Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Daniel Vetter | 618563e | 2012-04-01 13:38:50 +0200 | [diff] [blame] | 27 | #include <linux/dmi.h> |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 34 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 39 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 40 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 42 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 43 | #include <drm/drm_dp_helper.h> |
| 44 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 45 | #include <drm/drm_plane_helper.h> |
| 46 | #include <drm/drm_rect.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 47 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 48 | #include <linux/reservation.h> |
| 49 | #include <linux/dma-buf.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 50 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 51 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 52 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 53 | DRM_FORMAT_C8, |
| 54 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 55 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 56 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 60 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 61 | DRM_FORMAT_C8, |
| 62 | DRM_FORMAT_RGB565, |
| 63 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 64 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 65 | DRM_FORMAT_XRGB2101010, |
| 66 | DRM_FORMAT_XBGR2101010, |
| 67 | }; |
| 68 | |
| 69 | static const uint32_t skl_primary_formats[] = { |
| 70 | DRM_FORMAT_C8, |
| 71 | DRM_FORMAT_RGB565, |
| 72 | DRM_FORMAT_XRGB8888, |
| 73 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 74 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 75 | DRM_FORMAT_ABGR8888, |
| 76 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 77 | DRM_FORMAT_XBGR2101010, |
Kumar, Mahesh | ea916ea | 2015-09-03 16:17:09 +0530 | [diff] [blame] | 78 | DRM_FORMAT_YUYV, |
| 79 | DRM_FORMAT_YVYU, |
| 80 | DRM_FORMAT_UYVY, |
| 81 | DRM_FORMAT_VYUY, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 84 | /* Cursor formats */ |
| 85 | static const uint32_t intel_cursor_formats[] = { |
| 86 | DRM_FORMAT_ARGB8888, |
| 87 | }; |
| 88 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 89 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 90 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 91 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 92 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 93 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 94 | static int intel_framebuffer_init(struct drm_device *dev, |
| 95 | struct intel_framebuffer *ifb, |
| 96 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 97 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 98 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 99 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 100 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 101 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 102 | struct intel_link_m_n *m_n, |
| 103 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 104 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 105 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 106 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 107 | static void vlv_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); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 109 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 110 | const struct intel_crtc_state *pipe_config); |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 111 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 112 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 113 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 114 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 115 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
| 116 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); |
| 117 | static void ironlake_pfit_enable(struct intel_crtc *crtc); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 118 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 119 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 120 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 121 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 122 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 123 | } intel_range_t; |
| 124 | |
| 125 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 126 | int dot_limit; |
| 127 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 128 | } intel_p2_t; |
| 129 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 130 | typedef struct intel_limit intel_limit_t; |
| 131 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 132 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 133 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 134 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 135 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 136 | /* returns HPLL frequency in kHz */ |
| 137 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
| 138 | { |
| 139 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 140 | |
| 141 | /* Obtain SKU information */ |
| 142 | mutex_lock(&dev_priv->sb_lock); |
| 143 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 144 | CCK_FUSE_HPLL_FREQ_MASK; |
| 145 | mutex_unlock(&dev_priv->sb_lock); |
| 146 | |
| 147 | return vco_freq[hpll_freq] * 1000; |
| 148 | } |
| 149 | |
| 150 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 151 | const char *name, u32 reg) |
| 152 | { |
| 153 | u32 val; |
| 154 | int divider; |
| 155 | |
| 156 | if (dev_priv->hpll_freq == 0) |
| 157 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 158 | |
| 159 | mutex_lock(&dev_priv->sb_lock); |
| 160 | val = vlv_cck_read(dev_priv, reg); |
| 161 | mutex_unlock(&dev_priv->sb_lock); |
| 162 | |
| 163 | divider = val & CCK_FREQUENCY_VALUES; |
| 164 | |
| 165 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 166 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 167 | "%s change in progress\n", name); |
| 168 | |
| 169 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
| 170 | } |
| 171 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 172 | static int |
| 173 | intel_pch_rawclk(struct drm_i915_private *dev_priv) |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 174 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 175 | return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000; |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 178 | static int |
| 179 | intel_vlv_hrawclk(struct drm_i915_private *dev_priv) |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 180 | { |
Ville Syrjälä | 35d38d1 | 2016-03-02 17:22:16 +0200 | [diff] [blame] | 181 | return vlv_get_cck_clock_hpll(dev_priv, "hrawclk", |
| 182 | CCK_DISPLAY_REF_CLOCK_CONTROL); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | static int |
| 186 | intel_g4x_hrawclk(struct drm_i915_private *dev_priv) |
| 187 | { |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 188 | uint32_t clkcfg; |
| 189 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 190 | /* hrawclock is 1/4 the FSB frequency */ |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 191 | clkcfg = I915_READ(CLKCFG); |
| 192 | switch (clkcfg & CLKCFG_FSB_MASK) { |
| 193 | case CLKCFG_FSB_400: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 194 | return 100000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 195 | case CLKCFG_FSB_533: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 196 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 197 | case CLKCFG_FSB_667: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 198 | return 166667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 199 | case CLKCFG_FSB_800: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 200 | return 200000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 201 | case CLKCFG_FSB_1067: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 202 | return 266667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 203 | case CLKCFG_FSB_1333: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 204 | return 333333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 205 | /* these two are just a guess; one of them might be right */ |
| 206 | case CLKCFG_FSB_1600: |
| 207 | case CLKCFG_FSB_1600_ALT: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 208 | return 400000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 209 | default: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 210 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 211 | } |
| 212 | } |
| 213 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 214 | static void intel_update_rawclk(struct drm_i915_private *dev_priv) |
| 215 | { |
| 216 | if (HAS_PCH_SPLIT(dev_priv)) |
| 217 | dev_priv->rawclk_freq = intel_pch_rawclk(dev_priv); |
| 218 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 219 | dev_priv->rawclk_freq = intel_vlv_hrawclk(dev_priv); |
| 220 | else if (IS_G4X(dev_priv) || IS_PINEVIEW(dev_priv)) |
| 221 | dev_priv->rawclk_freq = intel_g4x_hrawclk(dev_priv); |
| 222 | else |
| 223 | return; /* no rawclk on other platforms, or no need to know it */ |
| 224 | |
| 225 | DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv->rawclk_freq); |
| 226 | } |
| 227 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 228 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 229 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 230 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 231 | return; |
| 232 | |
| 233 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 234 | CCK_CZ_CLOCK_CONTROL); |
| 235 | |
| 236 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 237 | } |
| 238 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 239 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 240 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 241 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 242 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 243 | if (HAS_DDI(dev_priv)) |
| 244 | return pipe_config->port_clock; /* SPLL */ |
| 245 | else if (IS_GEN5(dev_priv)) |
| 246 | return ((I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2) * 10000; |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 247 | else |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 248 | return 270000; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 251 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 253 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 254 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 255 | .m = { .min = 96, .max = 140 }, |
| 256 | .m1 = { .min = 18, .max = 26 }, |
| 257 | .m2 = { .min = 6, .max = 16 }, |
| 258 | .p = { .min = 4, .max = 128 }, |
| 259 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 260 | .p2 = { .dot_limit = 165000, |
| 261 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 264 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 265 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 266 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 267 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 268 | .m = { .min = 96, .max = 140 }, |
| 269 | .m1 = { .min = 18, .max = 26 }, |
| 270 | .m2 = { .min = 6, .max = 16 }, |
| 271 | .p = { .min = 4, .max = 128 }, |
| 272 | .p1 = { .min = 2, .max = 33 }, |
| 273 | .p2 = { .dot_limit = 165000, |
| 274 | .p2_slow = 4, .p2_fast = 4 }, |
| 275 | }; |
| 276 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 277 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 278 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 279 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 280 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 281 | .m = { .min = 96, .max = 140 }, |
| 282 | .m1 = { .min = 18, .max = 26 }, |
| 283 | .m2 = { .min = 6, .max = 16 }, |
| 284 | .p = { .min = 4, .max = 128 }, |
| 285 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 286 | .p2 = { .dot_limit = 165000, |
| 287 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 288 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 289 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 290 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 291 | .dot = { .min = 20000, .max = 400000 }, |
| 292 | .vco = { .min = 1400000, .max = 2800000 }, |
| 293 | .n = { .min = 1, .max = 6 }, |
| 294 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 295 | .m1 = { .min = 8, .max = 18 }, |
| 296 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 297 | .p = { .min = 5, .max = 80 }, |
| 298 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 299 | .p2 = { .dot_limit = 200000, |
| 300 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
| 303 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 304 | .dot = { .min = 20000, .max = 400000 }, |
| 305 | .vco = { .min = 1400000, .max = 2800000 }, |
| 306 | .n = { .min = 1, .max = 6 }, |
| 307 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 308 | .m1 = { .min = 8, .max = 18 }, |
| 309 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 310 | .p = { .min = 7, .max = 98 }, |
| 311 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 312 | .p2 = { .dot_limit = 112000, |
| 313 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 316 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 317 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 318 | .dot = { .min = 25000, .max = 270000 }, |
| 319 | .vco = { .min = 1750000, .max = 3500000}, |
| 320 | .n = { .min = 1, .max = 4 }, |
| 321 | .m = { .min = 104, .max = 138 }, |
| 322 | .m1 = { .min = 17, .max = 23 }, |
| 323 | .m2 = { .min = 5, .max = 11 }, |
| 324 | .p = { .min = 10, .max = 30 }, |
| 325 | .p1 = { .min = 1, .max = 3}, |
| 326 | .p2 = { .dot_limit = 270000, |
| 327 | .p2_slow = 10, |
| 328 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 329 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 330 | }; |
| 331 | |
| 332 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 333 | .dot = { .min = 22000, .max = 400000 }, |
| 334 | .vco = { .min = 1750000, .max = 3500000}, |
| 335 | .n = { .min = 1, .max = 4 }, |
| 336 | .m = { .min = 104, .max = 138 }, |
| 337 | .m1 = { .min = 16, .max = 23 }, |
| 338 | .m2 = { .min = 5, .max = 11 }, |
| 339 | .p = { .min = 5, .max = 80 }, |
| 340 | .p1 = { .min = 1, .max = 8}, |
| 341 | .p2 = { .dot_limit = 165000, |
| 342 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 346 | .dot = { .min = 20000, .max = 115000 }, |
| 347 | .vco = { .min = 1750000, .max = 3500000 }, |
| 348 | .n = { .min = 1, .max = 3 }, |
| 349 | .m = { .min = 104, .max = 138 }, |
| 350 | .m1 = { .min = 17, .max = 23 }, |
| 351 | .m2 = { .min = 5, .max = 11 }, |
| 352 | .p = { .min = 28, .max = 112 }, |
| 353 | .p1 = { .min = 2, .max = 8 }, |
| 354 | .p2 = { .dot_limit = 0, |
| 355 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 356 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 360 | .dot = { .min = 80000, .max = 224000 }, |
| 361 | .vco = { .min = 1750000, .max = 3500000 }, |
| 362 | .n = { .min = 1, .max = 3 }, |
| 363 | .m = { .min = 104, .max = 138 }, |
| 364 | .m1 = { .min = 17, .max = 23 }, |
| 365 | .m2 = { .min = 5, .max = 11 }, |
| 366 | .p = { .min = 14, .max = 42 }, |
| 367 | .p1 = { .min = 2, .max = 6 }, |
| 368 | .p2 = { .dot_limit = 0, |
| 369 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 370 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 371 | }; |
| 372 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 373 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 374 | .dot = { .min = 20000, .max = 400000}, |
| 375 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 376 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 377 | .n = { .min = 3, .max = 6 }, |
| 378 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 379 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 380 | .m1 = { .min = 0, .max = 0 }, |
| 381 | .m2 = { .min = 0, .max = 254 }, |
| 382 | .p = { .min = 5, .max = 80 }, |
| 383 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 384 | .p2 = { .dot_limit = 200000, |
| 385 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 386 | }; |
| 387 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 388 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 389 | .dot = { .min = 20000, .max = 400000 }, |
| 390 | .vco = { .min = 1700000, .max = 3500000 }, |
| 391 | .n = { .min = 3, .max = 6 }, |
| 392 | .m = { .min = 2, .max = 256 }, |
| 393 | .m1 = { .min = 0, .max = 0 }, |
| 394 | .m2 = { .min = 0, .max = 254 }, |
| 395 | .p = { .min = 7, .max = 112 }, |
| 396 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 397 | .p2 = { .dot_limit = 112000, |
| 398 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 401 | /* Ironlake / Sandybridge |
| 402 | * |
| 403 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 404 | * the range value for them is (actual_value - 2). |
| 405 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 406 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 407 | .dot = { .min = 25000, .max = 350000 }, |
| 408 | .vco = { .min = 1760000, .max = 3510000 }, |
| 409 | .n = { .min = 1, .max = 5 }, |
| 410 | .m = { .min = 79, .max = 127 }, |
| 411 | .m1 = { .min = 12, .max = 22 }, |
| 412 | .m2 = { .min = 5, .max = 9 }, |
| 413 | .p = { .min = 5, .max = 80 }, |
| 414 | .p1 = { .min = 1, .max = 8 }, |
| 415 | .p2 = { .dot_limit = 225000, |
| 416 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 417 | }; |
| 418 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 419 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 420 | .dot = { .min = 25000, .max = 350000 }, |
| 421 | .vco = { .min = 1760000, .max = 3510000 }, |
| 422 | .n = { .min = 1, .max = 3 }, |
| 423 | .m = { .min = 79, .max = 118 }, |
| 424 | .m1 = { .min = 12, .max = 22 }, |
| 425 | .m2 = { .min = 5, .max = 9 }, |
| 426 | .p = { .min = 28, .max = 112 }, |
| 427 | .p1 = { .min = 2, .max = 8 }, |
| 428 | .p2 = { .dot_limit = 225000, |
| 429 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 433 | .dot = { .min = 25000, .max = 350000 }, |
| 434 | .vco = { .min = 1760000, .max = 3510000 }, |
| 435 | .n = { .min = 1, .max = 3 }, |
| 436 | .m = { .min = 79, .max = 127 }, |
| 437 | .m1 = { .min = 12, .max = 22 }, |
| 438 | .m2 = { .min = 5, .max = 9 }, |
| 439 | .p = { .min = 14, .max = 56 }, |
| 440 | .p1 = { .min = 2, .max = 8 }, |
| 441 | .p2 = { .dot_limit = 225000, |
| 442 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 443 | }; |
| 444 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 445 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 446 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 447 | .dot = { .min = 25000, .max = 350000 }, |
| 448 | .vco = { .min = 1760000, .max = 3510000 }, |
| 449 | .n = { .min = 1, .max = 2 }, |
| 450 | .m = { .min = 79, .max = 126 }, |
| 451 | .m1 = { .min = 12, .max = 22 }, |
| 452 | .m2 = { .min = 5, .max = 9 }, |
| 453 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 454 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 455 | .p2 = { .dot_limit = 225000, |
| 456 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 457 | }; |
| 458 | |
| 459 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 460 | .dot = { .min = 25000, .max = 350000 }, |
| 461 | .vco = { .min = 1760000, .max = 3510000 }, |
| 462 | .n = { .min = 1, .max = 3 }, |
| 463 | .m = { .min = 79, .max = 126 }, |
| 464 | .m1 = { .min = 12, .max = 22 }, |
| 465 | .m2 = { .min = 5, .max = 9 }, |
| 466 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 467 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 468 | .p2 = { .dot_limit = 225000, |
| 469 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 470 | }; |
| 471 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 472 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 473 | /* |
| 474 | * These are the data rate limits (measured in fast clocks) |
| 475 | * since those are the strictest limits we have. The fast |
| 476 | * clock and actual rate limits are more relaxed, so checking |
| 477 | * them would make no difference. |
| 478 | */ |
| 479 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 480 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 481 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 482 | .m1 = { .min = 2, .max = 3 }, |
| 483 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 484 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 485 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 488 | static const intel_limit_t intel_limits_chv = { |
| 489 | /* |
| 490 | * These are the data rate limits (measured in fast clocks) |
| 491 | * since those are the strictest limits we have. The fast |
| 492 | * clock and actual rate limits are more relaxed, so checking |
| 493 | * them would make no difference. |
| 494 | */ |
| 495 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 496 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 497 | .n = { .min = 1, .max = 1 }, |
| 498 | .m1 = { .min = 2, .max = 2 }, |
| 499 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 500 | .p1 = { .min = 2, .max = 4 }, |
| 501 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 502 | }; |
| 503 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 504 | static const intel_limit_t intel_limits_bxt = { |
| 505 | /* FIXME: find real dot limits */ |
| 506 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 507 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 508 | .n = { .min = 1, .max = 1 }, |
| 509 | .m1 = { .min = 2, .max = 2 }, |
| 510 | /* FIXME: find real m2 limits */ |
| 511 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 512 | .p1 = { .min = 2, .max = 4 }, |
| 513 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 514 | }; |
| 515 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 516 | static bool |
| 517 | needs_modeset(struct drm_crtc_state *state) |
| 518 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 519 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 520 | } |
| 521 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 522 | /** |
| 523 | * Returns whether any output on the specified pipe is of the specified type |
| 524 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 525 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 526 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 527 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 528 | struct intel_encoder *encoder; |
| 529 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 530 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 531 | if (encoder->type == type) |
| 532 | return true; |
| 533 | |
| 534 | return false; |
| 535 | } |
| 536 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 537 | /** |
| 538 | * Returns whether any output on the specified pipe will have the specified |
| 539 | * type after a staged modeset is complete, i.e., the same as |
| 540 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 541 | * encoder->crtc. |
| 542 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 543 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 544 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 545 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 546 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 547 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 548 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 549 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 550 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 551 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 552 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 553 | if (connector_state->crtc != crtc_state->base.crtc) |
| 554 | continue; |
| 555 | |
| 556 | num_connectors++; |
| 557 | |
| 558 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 559 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 560 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 564 | |
| 565 | return false; |
| 566 | } |
| 567 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 568 | /* |
| 569 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 570 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 571 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 572 | * The helpers' return value is the rate of the clock that is fed to the |
| 573 | * display engine's pipe which can be the above fast dot clock rate or a |
| 574 | * divided-down version of it. |
| 575 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 576 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 577 | static int pnv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 578 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 579 | clock->m = clock->m2 + 2; |
| 580 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 581 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 582 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 583 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 584 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 585 | |
| 586 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 587 | } |
| 588 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 589 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 590 | { |
| 591 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 592 | } |
| 593 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 594 | static int i9xx_calc_dpll_params(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 595 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 596 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 598 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 599 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 600 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 601 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 602 | |
| 603 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 606 | static int vlv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 607 | { |
| 608 | clock->m = clock->m1 * clock->m2; |
| 609 | clock->p = clock->p1 * clock->p2; |
| 610 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 611 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 612 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 613 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 614 | |
| 615 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 616 | } |
| 617 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 618 | int chv_calc_dpll_params(int refclk, intel_clock_t *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 619 | { |
| 620 | clock->m = clock->m1 * clock->m2; |
| 621 | clock->p = clock->p1 * clock->p2; |
| 622 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 623 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 624 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 625 | clock->n << 22); |
| 626 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 627 | |
| 628 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 629 | } |
| 630 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 631 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 632 | /** |
| 633 | * Returns whether the given set of divisors are valid for a given refclk with |
| 634 | * the given connectors. |
| 635 | */ |
| 636 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 637 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 638 | const intel_limit_t *limit, |
| 639 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 640 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 641 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 642 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 643 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 644 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 645 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 646 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 647 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 648 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 649 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 650 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev) && |
| 651 | !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 652 | if (clock->m1 <= clock->m2) |
| 653 | INTELPllInvalid("m1 <= m2\n"); |
| 654 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 655 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && !IS_BROXTON(dev)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 656 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 657 | INTELPllInvalid("p out of range\n"); |
| 658 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 659 | INTELPllInvalid("m out of range\n"); |
| 660 | } |
| 661 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 662 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 663 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 664 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 665 | * connector, etc., rather than just a single range. |
| 666 | */ |
| 667 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 668 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 669 | |
| 670 | return true; |
| 671 | } |
| 672 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 673 | static int |
| 674 | i9xx_select_p2_div(const intel_limit_t *limit, |
| 675 | const struct intel_crtc_state *crtc_state, |
| 676 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 677 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 678 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 679 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 680 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 681 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 682 | * For LVDS just rely on its current settings for dual-channel. |
| 683 | * We haven't figured out how to reliably set up different |
| 684 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 685 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 686 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 687 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 688 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 689 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 690 | } else { |
| 691 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 692 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 693 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 694 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 695 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 696 | } |
| 697 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 698 | /* |
| 699 | * Returns a set of divisors for the desired target clock with the given |
| 700 | * refclk, or FALSE. The returned values represent the clock equation: |
| 701 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 702 | * |
| 703 | * Target and reference clocks are specified in kHz. |
| 704 | * |
| 705 | * If match_clock is provided, then best_clock P divider must match the P |
| 706 | * divider from @match_clock used for LVDS downclocking. |
| 707 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 708 | static bool |
| 709 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 710 | struct intel_crtc_state *crtc_state, |
| 711 | int target, int refclk, intel_clock_t *match_clock, |
| 712 | intel_clock_t *best_clock) |
| 713 | { |
| 714 | struct drm_device *dev = crtc_state->base.crtc->dev; |
| 715 | intel_clock_t clock; |
| 716 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 717 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 718 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 719 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 720 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 721 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 722 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 723 | clock.m1++) { |
| 724 | for (clock.m2 = limit->m2.min; |
| 725 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 726 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 727 | break; |
| 728 | for (clock.n = limit->n.min; |
| 729 | clock.n <= limit->n.max; clock.n++) { |
| 730 | for (clock.p1 = limit->p1.min; |
| 731 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 732 | int this_err; |
| 733 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 734 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 735 | if (!intel_PLL_is_valid(dev, limit, |
| 736 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 737 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 738 | if (match_clock && |
| 739 | clock.p != match_clock->p) |
| 740 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 741 | |
| 742 | this_err = abs(clock.dot - target); |
| 743 | if (this_err < err) { |
| 744 | *best_clock = clock; |
| 745 | err = this_err; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return (err != target); |
| 753 | } |
| 754 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 755 | /* |
| 756 | * Returns a set of divisors for the desired target clock with the given |
| 757 | * refclk, or FALSE. The returned values represent the clock equation: |
| 758 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 759 | * |
| 760 | * Target and reference clocks are specified in kHz. |
| 761 | * |
| 762 | * If match_clock is provided, then best_clock P divider must match the P |
| 763 | * divider from @match_clock used for LVDS downclocking. |
| 764 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 765 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 766 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 767 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 768 | int target, int refclk, intel_clock_t *match_clock, |
| 769 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 770 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 771 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 772 | intel_clock_t clock; |
| 773 | int err = target; |
| 774 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 775 | memset(best_clock, 0, sizeof(*best_clock)); |
| 776 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 777 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 778 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 779 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 780 | clock.m1++) { |
| 781 | for (clock.m2 = limit->m2.min; |
| 782 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 783 | for (clock.n = limit->n.min; |
| 784 | clock.n <= limit->n.max; clock.n++) { |
| 785 | for (clock.p1 = limit->p1.min; |
| 786 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 787 | int this_err; |
| 788 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 789 | pnv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 790 | if (!intel_PLL_is_valid(dev, limit, |
| 791 | &clock)) |
| 792 | continue; |
| 793 | if (match_clock && |
| 794 | clock.p != match_clock->p) |
| 795 | continue; |
| 796 | |
| 797 | this_err = abs(clock.dot - target); |
| 798 | if (this_err < err) { |
| 799 | *best_clock = clock; |
| 800 | err = this_err; |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | return (err != target); |
| 808 | } |
| 809 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 810 | /* |
| 811 | * Returns a set of divisors for the desired target clock with the given |
| 812 | * refclk, or FALSE. The returned values represent the clock equation: |
| 813 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 814 | * |
| 815 | * Target and reference clocks are specified in kHz. |
| 816 | * |
| 817 | * If match_clock is provided, then best_clock P divider must match the P |
| 818 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 819 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 820 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 821 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 822 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 823 | int target, int refclk, intel_clock_t *match_clock, |
| 824 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 825 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 826 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 827 | intel_clock_t clock; |
| 828 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 829 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 830 | /* approximately equals target * 0.00585 */ |
| 831 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 832 | |
| 833 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 834 | |
| 835 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 836 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 837 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 838 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 839 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 840 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 841 | for (clock.m1 = limit->m1.max; |
| 842 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 843 | for (clock.m2 = limit->m2.max; |
| 844 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 845 | for (clock.p1 = limit->p1.max; |
| 846 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 847 | int this_err; |
| 848 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 849 | i9xx_calc_dpll_params(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 850 | if (!intel_PLL_is_valid(dev, limit, |
| 851 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 852 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 853 | |
| 854 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 855 | if (this_err < err_most) { |
| 856 | *best_clock = clock; |
| 857 | err_most = this_err; |
| 858 | max_n = clock.n; |
| 859 | found = true; |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 865 | return found; |
| 866 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 867 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 868 | /* |
| 869 | * Check if the calculated PLL configuration is more optimal compared to the |
| 870 | * best configuration and error found so far. Return the calculated error. |
| 871 | */ |
| 872 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 873 | const intel_clock_t *calculated_clock, |
| 874 | const intel_clock_t *best_clock, |
| 875 | unsigned int best_error_ppm, |
| 876 | unsigned int *error_ppm) |
| 877 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 878 | /* |
| 879 | * For CHV ignore the error and consider only the P value. |
| 880 | * Prefer a bigger P value based on HW requirements. |
| 881 | */ |
| 882 | if (IS_CHERRYVIEW(dev)) { |
| 883 | *error_ppm = 0; |
| 884 | |
| 885 | return calculated_clock->p > best_clock->p; |
| 886 | } |
| 887 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 888 | if (WARN_ON_ONCE(!target_freq)) |
| 889 | return false; |
| 890 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 891 | *error_ppm = div_u64(1000000ULL * |
| 892 | abs(target_freq - calculated_clock->dot), |
| 893 | target_freq); |
| 894 | /* |
| 895 | * Prefer a better P value over a better (smaller) error if the error |
| 896 | * is small. Ensure this preference for future configurations too by |
| 897 | * setting the error to 0. |
| 898 | */ |
| 899 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 900 | *error_ppm = 0; |
| 901 | |
| 902 | return true; |
| 903 | } |
| 904 | |
| 905 | return *error_ppm + 10 < best_error_ppm; |
| 906 | } |
| 907 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 908 | /* |
| 909 | * Returns a set of divisors for the desired target clock with the given |
| 910 | * refclk, or FALSE. The returned values represent the clock equation: |
| 911 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 912 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 913 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 914 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 915 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 916 | int target, int refclk, intel_clock_t *match_clock, |
| 917 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 918 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 919 | 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] | 920 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 921 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 922 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 923 | /* min update 19.2 MHz */ |
| 924 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 925 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 926 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 927 | target *= 5; /* fast clock */ |
| 928 | |
| 929 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 930 | |
| 931 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 932 | 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] | 933 | 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] | 934 | 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] | 935 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 936 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 937 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 938 | 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] | 939 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 940 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 941 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 942 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 943 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 944 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 945 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 946 | if (!intel_PLL_is_valid(dev, limit, |
| 947 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 948 | continue; |
| 949 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 950 | if (!vlv_PLL_is_optimal(dev, target, |
| 951 | &clock, |
| 952 | best_clock, |
| 953 | bestppm, &ppm)) |
| 954 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 955 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 956 | *best_clock = clock; |
| 957 | bestppm = ppm; |
| 958 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | } |
| 962 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 963 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 964 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 965 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 966 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 967 | /* |
| 968 | * Returns a set of divisors for the desired target clock with the given |
| 969 | * refclk, or FALSE. The returned values represent the clock equation: |
| 970 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 971 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 972 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 973 | chv_find_best_dpll(const intel_limit_t *limit, |
| 974 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 975 | int target, int refclk, intel_clock_t *match_clock, |
| 976 | intel_clock_t *best_clock) |
| 977 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 978 | 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] | 979 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 980 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 981 | intel_clock_t clock; |
| 982 | uint64_t m2; |
| 983 | int found = false; |
| 984 | |
| 985 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 986 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 987 | |
| 988 | /* |
| 989 | * Based on hardware doc, the n always set to 1, and m1 always |
| 990 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 991 | * revisit this because n may not 1 anymore. |
| 992 | */ |
| 993 | clock.n = 1, clock.m1 = 2; |
| 994 | target *= 5; /* fast clock */ |
| 995 | |
| 996 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 997 | for (clock.p2 = limit->p2.p2_fast; |
| 998 | clock.p2 >= limit->p2.p2_slow; |
| 999 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1000 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1001 | |
| 1002 | clock.p = clock.p1 * clock.p2; |
| 1003 | |
| 1004 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 1005 | clock.n) << 22, refclk * clock.m1); |
| 1006 | |
| 1007 | if (m2 > INT_MAX/clock.m1) |
| 1008 | continue; |
| 1009 | |
| 1010 | clock.m2 = m2; |
| 1011 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 1012 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1013 | |
| 1014 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 1015 | continue; |
| 1016 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 1017 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 1018 | best_error_ppm, &error_ppm)) |
| 1019 | continue; |
| 1020 | |
| 1021 | *best_clock = clock; |
| 1022 | best_error_ppm = error_ppm; |
| 1023 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | return found; |
| 1028 | } |
| 1029 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1030 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
| 1031 | intel_clock_t *best_clock) |
| 1032 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1033 | int refclk = 100000; |
| 1034 | const intel_limit_t *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1035 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1036 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1037 | target_clock, refclk, NULL, best_clock); |
| 1038 | } |
| 1039 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1040 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 1041 | { |
| 1042 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1043 | |
| 1044 | /* Be paranoid as we can arrive here with only partial |
| 1045 | * state retrieved from the hardware during setup. |
| 1046 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1047 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1048 | * as Haswell has gained clock readout/fastboot support. |
| 1049 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 1050 | * We can ditch the crtc->primary->fb check as soon as we can |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1051 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1052 | * |
| 1053 | * FIXME: The intel_crtc->active here should be switched to |
| 1054 | * crtc->state->active once we have proper CRTC states wired up |
| 1055 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1056 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1057 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1058 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1059 | } |
| 1060 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1061 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1062 | enum pipe pipe) |
| 1063 | { |
| 1064 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 1065 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1066 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1067 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1068 | } |
| 1069 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1070 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 1071 | { |
| 1072 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1073 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1074 | u32 line1, line2; |
| 1075 | u32 line_mask; |
| 1076 | |
| 1077 | if (IS_GEN2(dev)) |
| 1078 | line_mask = DSL_LINEMASK_GEN2; |
| 1079 | else |
| 1080 | line_mask = DSL_LINEMASK_GEN3; |
| 1081 | |
| 1082 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1083 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1084 | line2 = I915_READ(reg) & line_mask; |
| 1085 | |
| 1086 | return line1 == line2; |
| 1087 | } |
| 1088 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1089 | /* |
| 1090 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1091 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1092 | * |
| 1093 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1094 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1095 | * see an interrupt when the pipe is disabled. |
| 1096 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1097 | * On Gen4 and above: |
| 1098 | * wait for the pipe register state bit to turn off |
| 1099 | * |
| 1100 | * Otherwise: |
| 1101 | * wait for the display line value to settle (it usually |
| 1102 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1103 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1104 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1105 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1106 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1107 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1108 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1109 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1110 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1111 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1112 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1113 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1114 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1115 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1116 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1117 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1118 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1119 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1120 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1121 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1122 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1123 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1124 | } |
| 1125 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1126 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1127 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1128 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1129 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1130 | u32 val; |
| 1131 | bool cur_state; |
| 1132 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1133 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1134 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1135 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1136 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1137 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1138 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1139 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1140 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1141 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1142 | { |
| 1143 | u32 val; |
| 1144 | bool cur_state; |
| 1145 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1146 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1147 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1148 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1149 | |
| 1150 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1151 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1152 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1153 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1154 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1155 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1156 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1157 | enum pipe pipe, bool state) |
| 1158 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1159 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1160 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1161 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1162 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1163 | if (HAS_DDI(dev_priv->dev)) { |
| 1164 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1165 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1166 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1167 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1168 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1169 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1170 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1171 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1172 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1173 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1174 | } |
| 1175 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1176 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1177 | |
| 1178 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1179 | enum pipe pipe, bool state) |
| 1180 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1181 | u32 val; |
| 1182 | bool cur_state; |
| 1183 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1184 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1185 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1186 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1187 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1188 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1189 | } |
| 1190 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1191 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1192 | |
| 1193 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1194 | enum pipe pipe) |
| 1195 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1196 | u32 val; |
| 1197 | |
| 1198 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1199 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1200 | return; |
| 1201 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1202 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1203 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1204 | return; |
| 1205 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1206 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1207 | 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] | 1208 | } |
| 1209 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1210 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1211 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1212 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1213 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1214 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1215 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1216 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1217 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1218 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1219 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1220 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1223 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1224 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1225 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1226 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1227 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1228 | u32 val; |
| 1229 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1230 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1231 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1232 | if (WARN_ON(HAS_DDI(dev))) |
| 1233 | return; |
| 1234 | |
| 1235 | if (HAS_PCH_SPLIT(dev)) { |
| 1236 | u32 port_sel; |
| 1237 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1238 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1239 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1240 | |
| 1241 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1242 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1243 | panel_pipe = PIPE_B; |
| 1244 | /* XXX: else fix for eDP */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1245 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1246 | /* presumably write lock depends on pipe, not port select */ |
| 1247 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1248 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1249 | } else { |
| 1250 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1251 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1252 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | val = I915_READ(pp_reg); |
| 1256 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1257 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1258 | locked = false; |
| 1259 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1260 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1261 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1262 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1263 | } |
| 1264 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1265 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1266 | enum pipe pipe, bool state) |
| 1267 | { |
| 1268 | struct drm_device *dev = dev_priv->dev; |
| 1269 | bool cur_state; |
| 1270 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1271 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 1272 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1273 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1274 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1275 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1276 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1277 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1278 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1279 | } |
| 1280 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1281 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1282 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1283 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1284 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1285 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1286 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1287 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1288 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1289 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1290 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1291 | /* if we need the pipe quirk it must be always on */ |
| 1292 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1293 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1294 | state = true; |
| 1295 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1296 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1297 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1298 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1299 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1300 | |
| 1301 | intel_display_power_put(dev_priv, power_domain); |
| 1302 | } else { |
| 1303 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1304 | } |
| 1305 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1306 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1307 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1308 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1311 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1312 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1313 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1314 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1315 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1316 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1317 | val = I915_READ(DSPCNTR(plane)); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1318 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1319 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1320 | "plane %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1321 | plane_name(plane), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1324 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1325 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1326 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1327 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1328 | enum pipe pipe) |
| 1329 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1330 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1331 | int i; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1332 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1333 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1334 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1335 | u32 val = I915_READ(DSPCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1336 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1337 | "plane %c assertion failure, should be disabled but not\n", |
| 1338 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1339 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1340 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1341 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1342 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1343 | for_each_pipe(dev_priv, i) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1344 | u32 val = I915_READ(DSPCNTR(i)); |
| 1345 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1346 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1347 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1348 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1349 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1353 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1354 | enum pipe pipe) |
| 1355 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1356 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1357 | int sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1358 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1359 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1360 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1361 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1362 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1363 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1364 | sprite, pipe_name(pipe)); |
| 1365 | } |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 1366 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1367 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1368 | u32 val = I915_READ(SPCNTR(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1369 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1370 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1371 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1372 | } |
| 1373 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1374 | u32 val = I915_READ(SPRCTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1375 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1376 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1377 | plane_name(pipe), pipe_name(pipe)); |
| 1378 | } else if (INTEL_INFO(dev)->gen >= 5) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1379 | u32 val = I915_READ(DVSCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1380 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1381 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1382 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1386 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1387 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1388 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1389 | drm_crtc_vblank_put(crtc); |
| 1390 | } |
| 1391 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1392 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1393 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1394 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1395 | u32 val; |
| 1396 | bool enabled; |
| 1397 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1398 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1399 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1400 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1401 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1402 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1405 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1406 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1407 | { |
| 1408 | if ((val & DP_PORT_EN) == 0) |
| 1409 | return false; |
| 1410 | |
| 1411 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1412 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1413 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1414 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1415 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1416 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1417 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1418 | } else { |
| 1419 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1420 | return false; |
| 1421 | } |
| 1422 | return true; |
| 1423 | } |
| 1424 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1425 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1426 | enum pipe pipe, u32 val) |
| 1427 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1428 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1429 | return false; |
| 1430 | |
| 1431 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1432 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1433 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1434 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1435 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1436 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1437 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1438 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1439 | return false; |
| 1440 | } |
| 1441 | return true; |
| 1442 | } |
| 1443 | |
| 1444 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1445 | enum pipe pipe, u32 val) |
| 1446 | { |
| 1447 | if ((val & LVDS_PORT_EN) == 0) |
| 1448 | return false; |
| 1449 | |
| 1450 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1451 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1452 | return false; |
| 1453 | } else { |
| 1454 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1455 | return false; |
| 1456 | } |
| 1457 | return true; |
| 1458 | } |
| 1459 | |
| 1460 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1461 | enum pipe pipe, u32 val) |
| 1462 | { |
| 1463 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1464 | return false; |
| 1465 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1466 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1467 | return false; |
| 1468 | } else { |
| 1469 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1470 | return false; |
| 1471 | } |
| 1472 | return true; |
| 1473 | } |
| 1474 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1475 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1476 | enum pipe pipe, i915_reg_t reg, |
| 1477 | u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1478 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1479 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1480 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1481 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1482 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1483 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1484 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1485 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1486 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1490 | enum pipe pipe, i915_reg_t reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1491 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1492 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1493 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1494 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1495 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1496 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1497 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1498 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1499 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1503 | enum pipe pipe) |
| 1504 | { |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1505 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1506 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1507 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1508 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1509 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1510 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1511 | val = I915_READ(PCH_ADPA); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1512 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1513 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1514 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1515 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1516 | val = I915_READ(PCH_LVDS); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1517 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1518 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1519 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1520 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1521 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1522 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1523 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1524 | } |
| 1525 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1526 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1527 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1528 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1529 | struct drm_device *dev = crtc->base.dev; |
| 1530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1531 | enum pipe pipe = crtc->pipe; |
| 1532 | i915_reg_t reg = DPLL(pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1533 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1534 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1535 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1536 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1537 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1538 | if (IS_MOBILE(dev_priv->dev)) |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1539 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1540 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1541 | I915_WRITE(reg, dpll); |
| 1542 | POSTING_READ(reg); |
| 1543 | udelay(150); |
| 1544 | |
| 1545 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1546 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1547 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1548 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1549 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1550 | |
| 1551 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1552 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1553 | POSTING_READ(reg); |
| 1554 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1555 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1556 | POSTING_READ(reg); |
| 1557 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1558 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1559 | POSTING_READ(reg); |
| 1560 | udelay(150); /* wait for warmup */ |
| 1561 | } |
| 1562 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1563 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1564 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1565 | { |
| 1566 | struct drm_device *dev = crtc->base.dev; |
| 1567 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1568 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1569 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1570 | u32 tmp; |
| 1571 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame^] | 1572 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1573 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1574 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1575 | |
| 1576 | /* Enable back the 10bit clock to display controller */ |
| 1577 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1578 | tmp |= DPIO_DCLKP_EN; |
| 1579 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1580 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1581 | mutex_unlock(&dev_priv->sb_lock); |
| 1582 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1583 | /* |
| 1584 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1585 | */ |
| 1586 | udelay(1); |
| 1587 | |
| 1588 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1589 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1590 | |
| 1591 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1592 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1593 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1594 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1595 | if (pipe != PIPE_A) { |
| 1596 | /* |
| 1597 | * WaPixelRepeatModeFixForC0:chv |
| 1598 | * |
| 1599 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1600 | * the value from DPLLBMD to either pipe B or C. |
| 1601 | */ |
| 1602 | I915_WRITE(CBR4_VLV, pipe == PIPE_B ? CBR_DPLLBMD_PIPE_B : CBR_DPLLBMD_PIPE_C); |
| 1603 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1604 | I915_WRITE(CBR4_VLV, 0); |
| 1605 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1606 | |
| 1607 | /* |
| 1608 | * DPLLB VGA mode also seems to cause problems. |
| 1609 | * We should always have it disabled. |
| 1610 | */ |
| 1611 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1612 | } else { |
| 1613 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1614 | POSTING_READ(DPLL_MD(pipe)); |
| 1615 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1616 | } |
| 1617 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1618 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1619 | { |
| 1620 | struct intel_crtc *crtc; |
| 1621 | int count = 0; |
| 1622 | |
| 1623 | for_each_intel_crtc(dev, crtc) |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1624 | count += crtc->base.state->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1625 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1626 | |
| 1627 | return count; |
| 1628 | } |
| 1629 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1630 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1631 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1632 | struct drm_device *dev = crtc->base.dev; |
| 1633 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1634 | i915_reg_t reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1635 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1636 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1637 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1638 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1639 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1640 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1641 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1642 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1643 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1644 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1645 | /* |
| 1646 | * It appears to be important that we don't enable this |
| 1647 | * for the current pipe before otherwise configuring the |
| 1648 | * PLL. No idea how this should be handled if multiple |
| 1649 | * DVO outputs are enabled simultaneosly. |
| 1650 | */ |
| 1651 | dpll |= DPLL_DVO_2X_MODE; |
| 1652 | I915_WRITE(DPLL(!crtc->pipe), |
| 1653 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1654 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1655 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1656 | /* |
| 1657 | * Apparently we need to have VGA mode enabled prior to changing |
| 1658 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1659 | * dividers, even though the register value does change. |
| 1660 | */ |
| 1661 | I915_WRITE(reg, 0); |
| 1662 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1663 | I915_WRITE(reg, dpll); |
| 1664 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1665 | /* Wait for the clocks to stabilize. */ |
| 1666 | POSTING_READ(reg); |
| 1667 | udelay(150); |
| 1668 | |
| 1669 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1670 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1671 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1672 | } else { |
| 1673 | /* The pixel multiplier can only be updated once the |
| 1674 | * DPLL is enabled and the clocks are stable. |
| 1675 | * |
| 1676 | * So write it again. |
| 1677 | */ |
| 1678 | I915_WRITE(reg, dpll); |
| 1679 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1680 | |
| 1681 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1682 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1683 | POSTING_READ(reg); |
| 1684 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1685 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1686 | POSTING_READ(reg); |
| 1687 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1688 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1689 | POSTING_READ(reg); |
| 1690 | udelay(150); /* wait for warmup */ |
| 1691 | } |
| 1692 | |
| 1693 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1694 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1695 | * @dev_priv: i915 private structure |
| 1696 | * @pipe: pipe PLL to disable |
| 1697 | * |
| 1698 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1699 | * |
| 1700 | * Note! This is for pre-ILK only. |
| 1701 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1702 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1703 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1704 | struct drm_device *dev = crtc->base.dev; |
| 1705 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1706 | enum pipe pipe = crtc->pipe; |
| 1707 | |
| 1708 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1709 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1710 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1711 | !intel_num_dvo_pipes(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1712 | I915_WRITE(DPLL(PIPE_B), |
| 1713 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1714 | I915_WRITE(DPLL(PIPE_A), |
| 1715 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1716 | } |
| 1717 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1718 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1719 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1720 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1721 | return; |
| 1722 | |
| 1723 | /* Make sure the pipe isn't still relying on us */ |
| 1724 | assert_pipe_disabled(dev_priv, pipe); |
| 1725 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1726 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1727 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1728 | } |
| 1729 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1730 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1731 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1732 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1733 | |
| 1734 | /* Make sure the pipe isn't still relying on us */ |
| 1735 | assert_pipe_disabled(dev_priv, pipe); |
| 1736 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1737 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1738 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1739 | if (pipe != PIPE_A) |
| 1740 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1741 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1742 | I915_WRITE(DPLL(pipe), val); |
| 1743 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1747 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1748 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1749 | u32 val; |
| 1750 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1751 | /* Make sure the pipe isn't still relying on us */ |
| 1752 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1753 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1754 | val = DPLL_SSC_REF_CLK_CHV | |
| 1755 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1756 | if (pipe != PIPE_A) |
| 1757 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1758 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1759 | I915_WRITE(DPLL(pipe), val); |
| 1760 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1761 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1762 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1763 | |
| 1764 | /* Disable 10bit clock to display controller */ |
| 1765 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1766 | val &= ~DPIO_DCLKP_EN; |
| 1767 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1768 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1769 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1772 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1773 | struct intel_digital_port *dport, |
| 1774 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1775 | { |
| 1776 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1777 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1778 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1779 | switch (dport->port) { |
| 1780 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1781 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1782 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1783 | break; |
| 1784 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1785 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1786 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1787 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1788 | break; |
| 1789 | case PORT_D: |
| 1790 | port_mask = DPLL_PORTD_READY_MASK; |
| 1791 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1792 | break; |
| 1793 | default: |
| 1794 | BUG(); |
| 1795 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1796 | |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1797 | if (wait_for((I915_READ(dpll_reg) & port_mask) == expected_mask, 1000)) |
| 1798 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
| 1799 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1800 | } |
| 1801 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1802 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1803 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1804 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1805 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1806 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1807 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1808 | i915_reg_t reg; |
| 1809 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1810 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1811 | /* Make sure PCH DPLL is enabled */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 1812 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1813 | |
| 1814 | /* FDI must be feeding us bits for PCH ports */ |
| 1815 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1816 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1817 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1818 | if (HAS_PCH_CPT(dev)) { |
| 1819 | /* Workaround: Set the timing override bit before enabling the |
| 1820 | * pch transcoder. */ |
| 1821 | reg = TRANS_CHICKEN2(pipe); |
| 1822 | val = I915_READ(reg); |
| 1823 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1824 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1825 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1826 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1827 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1828 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1829 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1830 | |
| 1831 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1832 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1833 | * Make the BPC in transcoder be consistent with |
| 1834 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1835 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1836 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1837 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1838 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_HDMI)) |
| 1839 | val |= PIPECONF_8BPC; |
| 1840 | else |
| 1841 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1842 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1843 | |
| 1844 | val &= ~TRANS_INTERLACE_MASK; |
| 1845 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1846 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1847 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1848 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1849 | else |
| 1850 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1851 | else |
| 1852 | val |= TRANS_PROGRESSIVE; |
| 1853 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1854 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1855 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1856 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1857 | } |
| 1858 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1859 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1860 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1861 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1862 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1863 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1864 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1865 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1866 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1867 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1868 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1869 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1870 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1871 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1872 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1873 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1874 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1875 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1876 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1877 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1878 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1879 | else |
| 1880 | val |= TRANS_PROGRESSIVE; |
| 1881 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1882 | I915_WRITE(LPT_TRANSCONF, val); |
| 1883 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1884 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1885 | } |
| 1886 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1887 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1888 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1889 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1890 | struct drm_device *dev = dev_priv->dev; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1891 | i915_reg_t reg; |
| 1892 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1893 | |
| 1894 | /* FDI relies on the transcoder */ |
| 1895 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1896 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1897 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1898 | /* Ports must be off as well */ |
| 1899 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1900 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1901 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1902 | val = I915_READ(reg); |
| 1903 | val &= ~TRANS_ENABLE; |
| 1904 | I915_WRITE(reg, val); |
| 1905 | /* wait for PCH transcoder off, transcoder state */ |
| 1906 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1907 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1908 | |
Ville Syrjälä | c465613 | 2015-10-29 21:25:56 +0200 | [diff] [blame] | 1909 | if (HAS_PCH_CPT(dev)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1910 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1911 | reg = TRANS_CHICKEN2(pipe); |
| 1912 | val = I915_READ(reg); |
| 1913 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1914 | I915_WRITE(reg, val); |
| 1915 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1916 | } |
| 1917 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1918 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1919 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1920 | u32 val; |
| 1921 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1922 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1923 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1924 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1925 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1926 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1927 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1928 | |
| 1929 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1930 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1931 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1932 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1933 | } |
| 1934 | |
| 1935 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1936 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1937 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1938 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1939 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1940 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1941 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1942 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1943 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1944 | struct drm_device *dev = crtc->base.dev; |
| 1945 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1946 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 1a70a728 | 2015-10-29 21:25:50 +0200 | [diff] [blame] | 1947 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1948 | enum pipe pch_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1949 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1950 | u32 val; |
| 1951 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1952 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1953 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1954 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1955 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1956 | assert_sprites_disabled(dev_priv, pipe); |
| 1957 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 1958 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1959 | pch_transcoder = TRANSCODER_A; |
| 1960 | else |
| 1961 | pch_transcoder = pipe; |
| 1962 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1963 | /* |
| 1964 | * A pipe without a PLL won't actually be able to drive bits from |
| 1965 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1966 | * need the check. |
| 1967 | */ |
Imre Deak | 5036040 | 2015-01-16 00:55:16 -0800 | [diff] [blame] | 1968 | if (HAS_GMCH_DISPLAY(dev_priv->dev)) |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 1969 | if (crtc->config->has_dsi_encoder) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1970 | assert_dsi_pll_enabled(dev_priv); |
| 1971 | else |
| 1972 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1973 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1974 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1975 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1976 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1977 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1978 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1979 | } |
| 1980 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1981 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1982 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1983 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1984 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1985 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1986 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1987 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1988 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1989 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1990 | |
| 1991 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1992 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1993 | |
| 1994 | /* |
| 1995 | * Until the pipe starts DSL will read as 0, which would cause |
| 1996 | * an apparent vblank timestamp jump, which messes up also the |
| 1997 | * frame count when it's derived from the timestamps. So let's |
| 1998 | * wait for the pipe to start properly before we call |
| 1999 | * drm_crtc_vblank_on() |
| 2000 | */ |
| 2001 | if (dev->max_vblank_count == 0 && |
| 2002 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) |
| 2003 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2007 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2008 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2009 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2010 | * Disable the pipe of @crtc, making sure that various hardware |
| 2011 | * specific requirements are met, if applicable, e.g. plane |
| 2012 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2013 | * |
| 2014 | * Will wait until the pipe has shut down before returning. |
| 2015 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2016 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2017 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2018 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2019 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2020 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2021 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2022 | u32 val; |
| 2023 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2024 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 2025 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2026 | /* |
| 2027 | * Make sure planes won't keep trying to pump pixels to us, |
| 2028 | * or we might hang the display. |
| 2029 | */ |
| 2030 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2031 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2032 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2033 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2034 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2035 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2036 | if ((val & PIPECONF_ENABLE) == 0) |
| 2037 | return; |
| 2038 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2039 | /* |
| 2040 | * Double wide has implications for planes |
| 2041 | * so best keep it disabled when not needed. |
| 2042 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2043 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2044 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2045 | |
| 2046 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2047 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2048 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2049 | val &= ~PIPECONF_ENABLE; |
| 2050 | |
| 2051 | I915_WRITE(reg, val); |
| 2052 | if ((val & PIPECONF_ENABLE) == 0) |
| 2053 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2054 | } |
| 2055 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2056 | static bool need_vtd_wa(struct drm_device *dev) |
| 2057 | { |
| 2058 | #ifdef CONFIG_INTEL_IOMMU |
| 2059 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2060 | return true; |
| 2061 | #endif |
| 2062 | return false; |
| 2063 | } |
| 2064 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2065 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 2066 | { |
| 2067 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 2068 | } |
| 2069 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2070 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
| 2071 | uint64_t fb_modifier, unsigned int cpp) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2072 | { |
| 2073 | switch (fb_modifier) { |
| 2074 | case DRM_FORMAT_MOD_NONE: |
| 2075 | return cpp; |
| 2076 | case I915_FORMAT_MOD_X_TILED: |
| 2077 | if (IS_GEN2(dev_priv)) |
| 2078 | return 128; |
| 2079 | else |
| 2080 | return 512; |
| 2081 | case I915_FORMAT_MOD_Y_TILED: |
| 2082 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 2083 | return 128; |
| 2084 | else |
| 2085 | return 512; |
| 2086 | case I915_FORMAT_MOD_Yf_TILED: |
| 2087 | switch (cpp) { |
| 2088 | case 1: |
| 2089 | return 64; |
| 2090 | case 2: |
| 2091 | case 4: |
| 2092 | return 128; |
| 2093 | case 8: |
| 2094 | case 16: |
| 2095 | return 256; |
| 2096 | default: |
| 2097 | MISSING_CASE(cpp); |
| 2098 | return cpp; |
| 2099 | } |
| 2100 | break; |
| 2101 | default: |
| 2102 | MISSING_CASE(fb_modifier); |
| 2103 | return cpp; |
| 2104 | } |
| 2105 | } |
| 2106 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2107 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
| 2108 | uint64_t fb_modifier, unsigned int cpp) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2109 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2110 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
| 2111 | return 1; |
| 2112 | else |
| 2113 | return intel_tile_size(dev_priv) / |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2114 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2115 | } |
| 2116 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2117 | /* Return the tile dimensions in pixel units */ |
| 2118 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, |
| 2119 | unsigned int *tile_width, |
| 2120 | unsigned int *tile_height, |
| 2121 | uint64_t fb_modifier, |
| 2122 | unsigned int cpp) |
| 2123 | { |
| 2124 | unsigned int tile_width_bytes = |
| 2125 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
| 2126 | |
| 2127 | *tile_width = tile_width_bytes / cpp; |
| 2128 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; |
| 2129 | } |
| 2130 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2131 | unsigned int |
| 2132 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2133 | uint32_t pixel_format, uint64_t fb_modifier) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2134 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2135 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 2136 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); |
| 2137 | |
| 2138 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2141 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 2142 | { |
| 2143 | unsigned int size = 0; |
| 2144 | int i; |
| 2145 | |
| 2146 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 2147 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2148 | |
| 2149 | return size; |
| 2150 | } |
| 2151 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 2152 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2153 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 2154 | const struct drm_framebuffer *fb, |
| 2155 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2156 | { |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2157 | if (intel_rotation_90_or_270(rotation)) { |
| 2158 | *view = i915_ggtt_view_rotated; |
| 2159 | view->params.rotated = to_intel_framebuffer(fb)->rot_info; |
| 2160 | } else { |
| 2161 | *view = i915_ggtt_view_normal; |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | static void |
| 2166 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2167 | struct drm_framebuffer *fb) |
| 2168 | { |
| 2169 | struct intel_rotation_info *info = &to_intel_framebuffer(fb)->rot_info; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2170 | unsigned int tile_size, tile_width, tile_height, cpp; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2171 | |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2172 | tile_size = intel_tile_size(dev_priv); |
| 2173 | |
| 2174 | cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2175 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2176 | fb->modifier[0], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2177 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2178 | info->plane[0].width = DIV_ROUND_UP(fb->pitches[0], tile_width * cpp); |
| 2179 | info->plane[0].height = DIV_ROUND_UP(fb->height, tile_height); |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 2180 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2181 | if (info->pixel_format == DRM_FORMAT_NV12) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2182 | cpp = drm_format_plane_cpp(fb->pixel_format, 1); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2183 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2184 | fb->modifier[1], cpp); |
Ville Syrjälä | d9b3288 | 2016-01-12 21:08:34 +0200 | [diff] [blame] | 2185 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2186 | info->uv_offset = fb->offsets[1]; |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2187 | info->plane[1].width = DIV_ROUND_UP(fb->pitches[1], tile_width * cpp); |
| 2188 | info->plane[1].height = DIV_ROUND_UP(fb->height / 2, tile_height); |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 2189 | } |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2192 | 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] | 2193 | { |
| 2194 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2195 | return 256 * 1024; |
Ville Syrjälä | 985b8bb | 2015-06-11 16:31:15 +0300 | [diff] [blame] | 2196 | else if (IS_BROADWATER(dev_priv) || IS_CRESTLINE(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2197 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2198 | return 128 * 1024; |
| 2199 | else if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2200 | return 4 * 1024; |
| 2201 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2202 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2203 | } |
| 2204 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2205 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
| 2206 | uint64_t fb_modifier) |
| 2207 | { |
| 2208 | switch (fb_modifier) { |
| 2209 | case DRM_FORMAT_MOD_NONE: |
| 2210 | return intel_linear_alignment(dev_priv); |
| 2211 | case I915_FORMAT_MOD_X_TILED: |
| 2212 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2213 | return 256 * 1024; |
| 2214 | return 0; |
| 2215 | case I915_FORMAT_MOD_Y_TILED: |
| 2216 | case I915_FORMAT_MOD_Yf_TILED: |
| 2217 | return 1 * 1024 * 1024; |
| 2218 | default: |
| 2219 | MISSING_CASE(fb_modifier); |
| 2220 | return 0; |
| 2221 | } |
| 2222 | } |
| 2223 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2224 | int |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2225 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, |
| 2226 | unsigned int rotation) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2227 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2228 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2229 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2230 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2231 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2232 | u32 alignment; |
| 2233 | int ret; |
| 2234 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2235 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2236 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2237 | alignment = intel_surf_alignment(dev_priv, fb->modifier[0]); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2238 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2239 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2240 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2241 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2242 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2243 | * we should always have valid PTE following the scanout preventing |
| 2244 | * the VT-d warning. |
| 2245 | */ |
| 2246 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2247 | alignment = 256 * 1024; |
| 2248 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2249 | /* |
| 2250 | * Global gtt pte registers are special registers which actually forward |
| 2251 | * writes to a chunk of system memory. Which means that there is no risk |
| 2252 | * that the register values disappear as soon as we call |
| 2253 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2254 | * pin/unpin/fence and not more. |
| 2255 | */ |
| 2256 | intel_runtime_pm_get(dev_priv); |
| 2257 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 2258 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, |
| 2259 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2260 | if (ret) |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2261 | goto err_pm; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2262 | |
| 2263 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2264 | * fence, whereas 965+ only requires a fence if using |
| 2265 | * framebuffer compression. For simplicity, we always install |
| 2266 | * a fence as the cost is not that onerous. |
| 2267 | */ |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2268 | if (view.type == I915_GGTT_VIEW_NORMAL) { |
| 2269 | ret = i915_gem_object_get_fence(obj); |
| 2270 | if (ret == -EDEADLK) { |
| 2271 | /* |
| 2272 | * -EDEADLK means there are no free fences |
| 2273 | * no pending flips. |
| 2274 | * |
| 2275 | * This is propagated to atomic, but it uses |
| 2276 | * -EDEADLK to force a locking recovery, so |
| 2277 | * change the returned error to -EBUSY. |
| 2278 | */ |
| 2279 | ret = -EBUSY; |
| 2280 | goto err_unpin; |
| 2281 | } else if (ret) |
| 2282 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2283 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2284 | i915_gem_object_pin_fence(obj); |
| 2285 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2286 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2287 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2288 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2289 | |
| 2290 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2291 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Maarten Lankhorst | b26a6b3 | 2015-09-23 13:27:09 +0200 | [diff] [blame] | 2292 | err_pm: |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2293 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2294 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2295 | } |
| 2296 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2297 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2298 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2299 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2300 | struct i915_ggtt_view view; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2301 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2302 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2303 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2304 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2305 | |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2306 | if (view.type == I915_GGTT_VIEW_NORMAL) |
| 2307 | i915_gem_object_unpin_fence(obj); |
| 2308 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2309 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2310 | } |
| 2311 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2312 | /* |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2313 | * Adjust the tile offset by moving the difference into |
| 2314 | * the x/y offsets. |
| 2315 | * |
| 2316 | * Input tile dimensions and pitch must already be |
| 2317 | * rotated to match x and y, and in pixel units. |
| 2318 | */ |
| 2319 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2320 | unsigned int tile_width, |
| 2321 | unsigned int tile_height, |
| 2322 | unsigned int tile_size, |
| 2323 | unsigned int pitch_tiles, |
| 2324 | u32 old_offset, |
| 2325 | u32 new_offset) |
| 2326 | { |
| 2327 | unsigned int tiles; |
| 2328 | |
| 2329 | WARN_ON(old_offset & (tile_size - 1)); |
| 2330 | WARN_ON(new_offset & (tile_size - 1)); |
| 2331 | WARN_ON(new_offset > old_offset); |
| 2332 | |
| 2333 | tiles = (old_offset - new_offset) / tile_size; |
| 2334 | |
| 2335 | *y += tiles / pitch_tiles * tile_height; |
| 2336 | *x += tiles % pitch_tiles * tile_width; |
| 2337 | |
| 2338 | return new_offset; |
| 2339 | } |
| 2340 | |
| 2341 | /* |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2342 | * Computes the linear offset to the base tile and adjusts |
| 2343 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2344 | * |
| 2345 | * In the 90/270 rotated case, x and y are assumed |
| 2346 | * to be already rotated to match the rotated GTT view, and |
| 2347 | * pitch is the tile_height aligned framebuffer height. |
| 2348 | */ |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2349 | u32 intel_compute_tile_offset(int *x, int *y, |
| 2350 | const struct drm_framebuffer *fb, int plane, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2351 | unsigned int pitch, |
| 2352 | unsigned int rotation) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2353 | { |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2354 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 2355 | uint64_t fb_modifier = fb->modifier[plane]; |
| 2356 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2357 | u32 offset, offset_aligned, alignment; |
| 2358 | |
| 2359 | alignment = intel_surf_alignment(dev_priv, fb_modifier); |
| 2360 | if (alignment) |
| 2361 | alignment--; |
| 2362 | |
Ville Syrjälä | b5c6533 | 2016-01-12 21:08:31 +0200 | [diff] [blame] | 2363 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2364 | unsigned int tile_size, tile_width, tile_height; |
| 2365 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2366 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2367 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2368 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2369 | fb_modifier, cpp); |
| 2370 | |
| 2371 | if (intel_rotation_90_or_270(rotation)) { |
| 2372 | pitch_tiles = pitch / tile_height; |
| 2373 | swap(tile_width, tile_height); |
| 2374 | } else { |
| 2375 | pitch_tiles = pitch / (tile_width * cpp); |
| 2376 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2377 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2378 | tile_rows = *y / tile_height; |
| 2379 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2380 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2381 | tiles = *x / tile_width; |
| 2382 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2383 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2384 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2385 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2386 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2387 | intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2388 | tile_size, pitch_tiles, |
| 2389 | offset, offset_aligned); |
| 2390 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2391 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2392 | offset_aligned = offset & ~alignment; |
| 2393 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2394 | *y = (offset & alignment) / pitch; |
| 2395 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2396 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2397 | |
| 2398 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2401 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2402 | { |
| 2403 | switch (format) { |
| 2404 | case DISPPLANE_8BPP: |
| 2405 | return DRM_FORMAT_C8; |
| 2406 | case DISPPLANE_BGRX555: |
| 2407 | return DRM_FORMAT_XRGB1555; |
| 2408 | case DISPPLANE_BGRX565: |
| 2409 | return DRM_FORMAT_RGB565; |
| 2410 | default: |
| 2411 | case DISPPLANE_BGRX888: |
| 2412 | return DRM_FORMAT_XRGB8888; |
| 2413 | case DISPPLANE_RGBX888: |
| 2414 | return DRM_FORMAT_XBGR8888; |
| 2415 | case DISPPLANE_BGRX101010: |
| 2416 | return DRM_FORMAT_XRGB2101010; |
| 2417 | case DISPPLANE_RGBX101010: |
| 2418 | return DRM_FORMAT_XBGR2101010; |
| 2419 | } |
| 2420 | } |
| 2421 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2422 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2423 | { |
| 2424 | switch (format) { |
| 2425 | case PLANE_CTL_FORMAT_RGB_565: |
| 2426 | return DRM_FORMAT_RGB565; |
| 2427 | default: |
| 2428 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2429 | if (rgb_order) { |
| 2430 | if (alpha) |
| 2431 | return DRM_FORMAT_ABGR8888; |
| 2432 | else |
| 2433 | return DRM_FORMAT_XBGR8888; |
| 2434 | } else { |
| 2435 | if (alpha) |
| 2436 | return DRM_FORMAT_ARGB8888; |
| 2437 | else |
| 2438 | return DRM_FORMAT_XRGB8888; |
| 2439 | } |
| 2440 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2441 | if (rgb_order) |
| 2442 | return DRM_FORMAT_XBGR2101010; |
| 2443 | else |
| 2444 | return DRM_FORMAT_XRGB2101010; |
| 2445 | } |
| 2446 | } |
| 2447 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2448 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2449 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2450 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2451 | { |
| 2452 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2453 | struct drm_i915_private *dev_priv = to_i915(dev); |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2454 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2455 | struct drm_i915_gem_object *obj = NULL; |
| 2456 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2457 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2458 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2459 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2460 | PAGE_SIZE); |
| 2461 | |
| 2462 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2463 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2464 | if (plane_config->size == 0) |
| 2465 | return false; |
| 2466 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2467 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2468 | * important and we should probably use that space with FBC or other |
| 2469 | * features. */ |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2470 | if (size_aligned * 2 > ggtt->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2471 | return false; |
| 2472 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2473 | mutex_lock(&dev->struct_mutex); |
| 2474 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2475 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2476 | base_aligned, |
| 2477 | base_aligned, |
| 2478 | size_aligned); |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2479 | if (!obj) { |
| 2480 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2481 | return false; |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2482 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2483 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2484 | obj->tiling_mode = plane_config->tiling; |
| 2485 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2486 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2487 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2488 | mode_cmd.pixel_format = fb->pixel_format; |
| 2489 | mode_cmd.width = fb->width; |
| 2490 | mode_cmd.height = fb->height; |
| 2491 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2492 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2493 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2494 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2495 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2496 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2497 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2498 | goto out_unref_obj; |
| 2499 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2500 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2501 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2502 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2503 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2504 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2505 | |
| 2506 | out_unref_obj: |
| 2507 | drm_gem_object_unreference(&obj->base); |
| 2508 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2509 | return false; |
| 2510 | } |
| 2511 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2512 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2513 | static void |
| 2514 | update_state_fb(struct drm_plane *plane) |
| 2515 | { |
| 2516 | if (plane->fb == plane->state->fb) |
| 2517 | return; |
| 2518 | |
| 2519 | if (plane->state->fb) |
| 2520 | drm_framebuffer_unreference(plane->state->fb); |
| 2521 | plane->state->fb = plane->fb; |
| 2522 | if (plane->state->fb) |
| 2523 | drm_framebuffer_reference(plane->state->fb); |
| 2524 | } |
| 2525 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2526 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2527 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2528 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2529 | { |
| 2530 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2531 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2532 | struct drm_crtc *c; |
| 2533 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2534 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2535 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2536 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2537 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
| 2538 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2539 | struct intel_plane_state *intel_state = |
| 2540 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2541 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2542 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2543 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2544 | return; |
| 2545 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2546 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2547 | fb = &plane_config->fb->base; |
| 2548 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2549 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2550 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2551 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2552 | |
| 2553 | /* |
| 2554 | * Failed to alloc the obj, check to see if we should share |
| 2555 | * an fb with another CRTC instead |
| 2556 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2557 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2558 | i = to_intel_crtc(c); |
| 2559 | |
| 2560 | if (c == &intel_crtc->base) |
| 2561 | continue; |
| 2562 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2563 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2564 | continue; |
| 2565 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2566 | fb = c->primary->fb; |
| 2567 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2568 | continue; |
| 2569 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2570 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2571 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2572 | drm_framebuffer_reference(fb); |
| 2573 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2574 | } |
| 2575 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2576 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2577 | /* |
| 2578 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2579 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2580 | * which will lead to problems later if we don't fix it up. The |
| 2581 | * simplest solution is to just disable the primary plane now and |
| 2582 | * pretend the BIOS never had it enabled. |
| 2583 | */ |
| 2584 | to_intel_plane_state(plane_state)->visible = false; |
| 2585 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 2586 | intel_pre_disable_primary_noatomic(&intel_crtc->base); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2587 | intel_plane->disable_plane(primary, &intel_crtc->base); |
| 2588 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2589 | return; |
| 2590 | |
| 2591 | valid_fb: |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2592 | plane_state->src_x = 0; |
| 2593 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2594 | plane_state->src_w = fb->width << 16; |
| 2595 | plane_state->src_h = fb->height << 16; |
| 2596 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2597 | plane_state->crtc_x = 0; |
| 2598 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2599 | plane_state->crtc_w = fb->width; |
| 2600 | plane_state->crtc_h = fb->height; |
| 2601 | |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2602 | intel_state->src.x1 = plane_state->src_x; |
| 2603 | intel_state->src.y1 = plane_state->src_y; |
| 2604 | intel_state->src.x2 = plane_state->src_x + plane_state->src_w; |
| 2605 | intel_state->src.y2 = plane_state->src_y + plane_state->src_h; |
| 2606 | intel_state->dst.x1 = plane_state->crtc_x; |
| 2607 | intel_state->dst.y1 = plane_state->crtc_y; |
| 2608 | intel_state->dst.x2 = plane_state->crtc_x + plane_state->crtc_w; |
| 2609 | intel_state->dst.y2 = plane_state->crtc_y + plane_state->crtc_h; |
| 2610 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2611 | obj = intel_fb_obj(fb); |
| 2612 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2613 | dev_priv->preserve_bios_swizzle = true; |
| 2614 | |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2615 | drm_framebuffer_reference(fb); |
| 2616 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2617 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2618 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 2619 | obj->frontbuffer_bits |= to_intel_plane(primary)->frontbuffer_bit; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2620 | } |
| 2621 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2622 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
| 2623 | const struct intel_crtc_state *crtc_state, |
| 2624 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2625 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2626 | struct drm_device *dev = primary->dev; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2627 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2628 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2629 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2630 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2631 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2632 | u32 linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2633 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2634 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2635 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2636 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2637 | int x = plane_state->src.x1 >> 16; |
| 2638 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2639 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2640 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2641 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2642 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2643 | |
| 2644 | if (INTEL_INFO(dev)->gen < 4) { |
| 2645 | if (intel_crtc->pipe == PIPE_B) |
| 2646 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2647 | |
| 2648 | /* pipesrc and dspsize control the size that is scaled from, |
| 2649 | * which should always be the user's requested size. |
| 2650 | */ |
| 2651 | I915_WRITE(DSPSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2652 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2653 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2654 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2655 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2656 | I915_WRITE(PRIMSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2657 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 2658 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2659 | I915_WRITE(PRIMPOS(plane), 0); |
| 2660 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2661 | } |
| 2662 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2663 | switch (fb->pixel_format) { |
| 2664 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2665 | dspcntr |= DISPPLANE_8BPP; |
| 2666 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2667 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2668 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2669 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2670 | case DRM_FORMAT_RGB565: |
| 2671 | dspcntr |= DISPPLANE_BGRX565; |
| 2672 | break; |
| 2673 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2674 | dspcntr |= DISPPLANE_BGRX888; |
| 2675 | break; |
| 2676 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2677 | dspcntr |= DISPPLANE_RGBX888; |
| 2678 | break; |
| 2679 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2680 | dspcntr |= DISPPLANE_BGRX101010; |
| 2681 | break; |
| 2682 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2683 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2684 | break; |
| 2685 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2686 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2687 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2688 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2689 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2690 | obj->tiling_mode != I915_TILING_NONE) |
| 2691 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2692 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2693 | if (IS_G4X(dev)) |
| 2694 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2695 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2696 | linear_offset = y * fb->pitches[0] + x * cpp; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2697 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2698 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2699 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2700 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2701 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2702 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2703 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2704 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2705 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2706 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2707 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2708 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2709 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2710 | x += (crtc_state->pipe_src_w - 1); |
| 2711 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2712 | |
| 2713 | /* Finding the last pixel of the last line of the display |
| 2714 | data and adding to linear_offset*/ |
| 2715 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2716 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2717 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2718 | } |
| 2719 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2720 | intel_crtc->adjusted_x = x; |
| 2721 | intel_crtc->adjusted_y = y; |
| 2722 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2723 | I915_WRITE(reg, dspcntr); |
| 2724 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2725 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2726 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2727 | I915_WRITE(DSPSURF(plane), |
| 2728 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2729 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2730 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2731 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2732 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2733 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2736 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
| 2737 | struct drm_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2738 | { |
| 2739 | struct drm_device *dev = crtc->dev; |
| 2740 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2741 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2742 | int plane = intel_crtc->plane; |
| 2743 | |
| 2744 | I915_WRITE(DSPCNTR(plane), 0); |
| 2745 | if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2746 | I915_WRITE(DSPSURF(plane), 0); |
| 2747 | else |
| 2748 | I915_WRITE(DSPADDR(plane), 0); |
| 2749 | POSTING_READ(DSPCNTR(plane)); |
| 2750 | } |
| 2751 | |
| 2752 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
| 2753 | const struct intel_crtc_state *crtc_state, |
| 2754 | const struct intel_plane_state *plane_state) |
| 2755 | { |
| 2756 | struct drm_device *dev = primary->dev; |
| 2757 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2758 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2759 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2760 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2761 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 2762 | u32 linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2763 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2764 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2765 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2766 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2767 | int x = plane_state->src.x1 >> 16; |
| 2768 | int y = plane_state->src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2769 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2770 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2771 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2772 | |
| 2773 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2774 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2775 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2776 | switch (fb->pixel_format) { |
| 2777 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2778 | dspcntr |= DISPPLANE_8BPP; |
| 2779 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2780 | case DRM_FORMAT_RGB565: |
| 2781 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2782 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2783 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2784 | dspcntr |= DISPPLANE_BGRX888; |
| 2785 | break; |
| 2786 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2787 | dspcntr |= DISPPLANE_RGBX888; |
| 2788 | break; |
| 2789 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2790 | dspcntr |= DISPPLANE_BGRX101010; |
| 2791 | break; |
| 2792 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2793 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2794 | break; |
| 2795 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2796 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2800 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2801 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2802 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2803 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2804 | |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2805 | linear_offset = y * fb->pitches[0] + x * cpp; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2806 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2807 | intel_compute_tile_offset(&x, &y, fb, 0, |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2808 | fb->pitches[0], rotation); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2809 | linear_offset -= intel_crtc->dspaddr_offset; |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2810 | if (rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2811 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2812 | |
| 2813 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2814 | x += (crtc_state->pipe_src_w - 1); |
| 2815 | y += (crtc_state->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2816 | |
| 2817 | /* Finding the last pixel of the last line of the display |
| 2818 | data and adding to linear_offset*/ |
| 2819 | linear_offset += |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2820 | (crtc_state->pipe_src_h - 1) * fb->pitches[0] + |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 2821 | (crtc_state->pipe_src_w - 1) * cpp; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2822 | } |
| 2823 | } |
| 2824 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 2825 | intel_crtc->adjusted_x = x; |
| 2826 | intel_crtc->adjusted_y = y; |
| 2827 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2828 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2829 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2830 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2831 | I915_WRITE(DSPSURF(plane), |
| 2832 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2833 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2834 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2835 | } else { |
| 2836 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2837 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2838 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2839 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2840 | } |
| 2841 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2842 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
| 2843 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2844 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2845 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
| 2846 | return 64; |
| 2847 | } else { |
| 2848 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2849 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2850 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2851 | } |
| 2852 | } |
| 2853 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2854 | u32 intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2855 | struct drm_i915_gem_object *obj, |
| 2856 | unsigned int plane) |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2857 | { |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2858 | struct i915_ggtt_view view; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2859 | struct i915_vma *vma; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2860 | u64 offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2861 | |
Ville Syrjälä | e794129 | 2016-01-19 18:23:17 +0200 | [diff] [blame] | 2862 | intel_fill_fb_ggtt_view(&view, intel_plane->base.state->fb, |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2863 | intel_plane->base.state->rotation); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2864 | |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2865 | vma = i915_gem_obj_to_ggtt_view(obj, &view); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2866 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 2867 | view.type)) |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2868 | return -1; |
| 2869 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2870 | offset = vma->node.start; |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2871 | |
| 2872 | if (plane == 1) { |
Ville Syrjälä | 7723f47d | 2016-01-20 21:05:22 +0200 | [diff] [blame] | 2873 | offset += vma->ggtt_view.params.rotated.uv_start_page * |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 2874 | PAGE_SIZE; |
| 2875 | } |
| 2876 | |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 2877 | WARN_ON(upper_32_bits(offset)); |
| 2878 | |
| 2879 | return lower_32_bits(offset); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2880 | } |
| 2881 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2882 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 2883 | { |
| 2884 | struct drm_device *dev = intel_crtc->base.dev; |
| 2885 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2886 | |
| 2887 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 2888 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 2889 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2890 | } |
| 2891 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2892 | /* |
| 2893 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 2894 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 2895 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2896 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2897 | struct intel_crtc_scaler_state *scaler_state; |
| 2898 | int i; |
| 2899 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2900 | scaler_state = &intel_crtc->config->scaler_state; |
| 2901 | |
| 2902 | /* loop through and disable scalers that aren't in use */ |
| 2903 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 2904 | if (!scaler_state->scalers[i].in_use) |
| 2905 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 2906 | } |
| 2907 | } |
| 2908 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2909 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 2910 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2911 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 2912 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2913 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2914 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2915 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2916 | case DRM_FORMAT_XBGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2917 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2918 | case DRM_FORMAT_XRGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2919 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2920 | /* |
| 2921 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 2922 | * to be already pre-multiplied. We need to add a knob (or a different |
| 2923 | * DRM_FORMAT) for user-space to configure that. |
| 2924 | */ |
| 2925 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2926 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2927 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2928 | case DRM_FORMAT_ARGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2929 | return PLANE_CTL_FORMAT_XRGB_8888 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2930 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2931 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2932 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2933 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2934 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2935 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2936 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2937 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2938 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2939 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2940 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2941 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2942 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2943 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 2944 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2945 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2946 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2947 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 2951 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2952 | switch (fb_modifier) { |
| 2953 | case DRM_FORMAT_MOD_NONE: |
| 2954 | break; |
| 2955 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2956 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2957 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2958 | return PLANE_CTL_TILED_Y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2959 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2960 | return PLANE_CTL_TILED_YF; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2961 | default: |
| 2962 | MISSING_CASE(fb_modifier); |
| 2963 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 2964 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2965 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 2969 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2970 | switch (rotation) { |
| 2971 | case BIT(DRM_ROTATE_0): |
| 2972 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2973 | /* |
| 2974 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 2975 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 2976 | */ |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2977 | case BIT(DRM_ROTATE_90): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2978 | return PLANE_CTL_ROTATE_270; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2979 | case BIT(DRM_ROTATE_180): |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2980 | return PLANE_CTL_ROTATE_180; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2981 | case BIT(DRM_ROTATE_270): |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 2982 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2983 | default: |
| 2984 | MISSING_CASE(rotation); |
| 2985 | } |
| 2986 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 2987 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2990 | static void skylake_update_primary_plane(struct drm_plane *plane, |
| 2991 | const struct intel_crtc_state *crtc_state, |
| 2992 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2993 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2994 | struct drm_device *dev = plane->dev; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2995 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2996 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 2997 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 2998 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2999 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3000 | u32 plane_ctl, stride_div, stride; |
| 3001 | u32 tile_height, plane_offset, plane_size; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3002 | unsigned int rotation = plane_state->base.rotation; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3003 | int x_offset, y_offset; |
Mika Kuoppala | 44eb0cb | 2015-10-30 13:26:15 +0200 | [diff] [blame] | 3004 | u32 surf_addr; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3005 | int scaler_id = plane_state->scaler_id; |
| 3006 | int src_x = plane_state->src.x1 >> 16; |
| 3007 | int src_y = plane_state->src.y1 >> 16; |
| 3008 | int src_w = drm_rect_width(&plane_state->src) >> 16; |
| 3009 | int src_h = drm_rect_height(&plane_state->src) >> 16; |
| 3010 | int dst_x = plane_state->dst.x1; |
| 3011 | int dst_y = plane_state->dst.y1; |
| 3012 | int dst_w = drm_rect_width(&plane_state->dst); |
| 3013 | int dst_h = drm_rect_height(&plane_state->dst); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3014 | |
| 3015 | plane_ctl = PLANE_CTL_ENABLE | |
| 3016 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3017 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 3018 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3019 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
| 3020 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3021 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3022 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3023 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3024 | stride_div = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3025 | fb->pixel_format); |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 3026 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj, 0); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3027 | |
Paulo Zanoni | a42e5a2 | 2015-09-30 17:05:43 -0300 | [diff] [blame] | 3028 | WARN_ON(drm_rect_width(&plane_state->src) == 0); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3029 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3030 | if (intel_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3031 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
| 3032 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3033 | /* stride = Surface height in tiles */ |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 3034 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], cpp); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3035 | stride = DIV_ROUND_UP(fb->height, tile_height); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3036 | x_offset = stride * tile_height - src_y - src_h; |
| 3037 | y_offset = src_x; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3038 | plane_size = (src_w - 1) << 16 | (src_h - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3039 | } else { |
| 3040 | stride = fb->pitches[0] / stride_div; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3041 | x_offset = src_x; |
| 3042 | y_offset = src_y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3043 | plane_size = (src_h - 1) << 16 | (src_w - 1); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3044 | } |
| 3045 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3046 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3047 | intel_crtc->adjusted_x = x_offset; |
| 3048 | intel_crtc->adjusted_y = y_offset; |
| 3049 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3050 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3051 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3052 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3053 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3054 | |
| 3055 | if (scaler_id >= 0) { |
| 3056 | uint32_t ps_ctrl = 0; |
| 3057 | |
| 3058 | WARN_ON(!dst_w || !dst_h); |
| 3059 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(0) | |
| 3060 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3061 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3062 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3063 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3064 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
| 3065 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3066 | } else { |
| 3067 | I915_WRITE(PLANE_POS(pipe, 0), (dst_y << 16) | dst_x); |
| 3068 | } |
| 3069 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3070 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3071 | |
| 3072 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3073 | } |
| 3074 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3075 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
| 3076 | struct drm_crtc *crtc) |
| 3077 | { |
| 3078 | struct drm_device *dev = crtc->dev; |
| 3079 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3080 | int pipe = to_intel_crtc(crtc)->pipe; |
| 3081 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3082 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 3083 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 3084 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3085 | } |
| 3086 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3087 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3088 | static int |
| 3089 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3090 | int x, int y, enum mode_set_atomic state) |
| 3091 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3092 | /* Support for kgdboc is disabled, this needs a major rework. */ |
| 3093 | DRM_ERROR("legacy panic handler not supported any more.\n"); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3094 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3095 | return -ENODEV; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3096 | } |
| 3097 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3098 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3099 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3100 | struct drm_crtc *crtc; |
| 3101 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3102 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3103 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3104 | enum plane plane = intel_crtc->plane; |
| 3105 | |
| 3106 | intel_prepare_page_flip(dev, plane); |
| 3107 | intel_finish_page_flip_plane(dev, plane); |
| 3108 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3112 | { |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3113 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3114 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3115 | for_each_crtc(dev, crtc) { |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3116 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
| 3117 | struct intel_plane_state *plane_state; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3118 | |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3119 | drm_modeset_lock_crtc(crtc, &plane->base); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3120 | plane_state = to_intel_plane_state(plane->base.state); |
| 3121 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3122 | if (plane_state->visible) |
| 3123 | plane->update_plane(&plane->base, |
| 3124 | to_intel_crtc_state(crtc->state), |
| 3125 | plane_state); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3126 | |
| 3127 | drm_modeset_unlock_crtc(crtc); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3131 | void intel_prepare_reset(struct drm_device *dev) |
| 3132 | { |
| 3133 | /* no reset support for gen2 */ |
| 3134 | if (IS_GEN2(dev)) |
| 3135 | return; |
| 3136 | |
| 3137 | /* reset doesn't touch the display */ |
| 3138 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3139 | return; |
| 3140 | |
| 3141 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3142 | /* |
| 3143 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3144 | * g33 docs say we should at least disable all the planes. |
| 3145 | */ |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 3146 | intel_display_suspend(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | void intel_finish_reset(struct drm_device *dev) |
| 3150 | { |
| 3151 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3152 | |
| 3153 | /* |
| 3154 | * Flips in the rings will be nuked by the reset, |
| 3155 | * so complete all pending flips so that user space |
| 3156 | * will get its events and not get stuck. |
| 3157 | */ |
| 3158 | intel_complete_page_flips(dev); |
| 3159 | |
| 3160 | /* no reset support for gen2 */ |
| 3161 | if (IS_GEN2(dev)) |
| 3162 | return; |
| 3163 | |
| 3164 | /* reset doesn't touch the display */ |
| 3165 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3166 | /* |
| 3167 | * Flips in the rings have been nuked by the reset, |
| 3168 | * so update the base address of all primary |
| 3169 | * planes to the the last fb to make sure we're |
| 3170 | * showing the correct fb after a reset. |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3171 | * |
| 3172 | * FIXME: Atomic will make this obsolete since we won't schedule |
| 3173 | * CS-based flips (which might get lost in gpu resets) any more. |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3174 | */ |
| 3175 | intel_update_primary_planes(dev); |
| 3176 | return; |
| 3177 | } |
| 3178 | |
| 3179 | /* |
| 3180 | * The display has been reset as well, |
| 3181 | * so need a full re-initialization. |
| 3182 | */ |
| 3183 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3184 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3185 | |
| 3186 | intel_modeset_init_hw(dev); |
| 3187 | |
| 3188 | spin_lock_irq(&dev_priv->irq_lock); |
| 3189 | if (dev_priv->display.hpd_irq_setup) |
| 3190 | dev_priv->display.hpd_irq_setup(dev); |
| 3191 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3192 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 3193 | intel_display_resume(dev); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3194 | |
| 3195 | intel_hpd_init(dev_priv); |
| 3196 | |
| 3197 | drm_modeset_unlock_all(dev); |
| 3198 | } |
| 3199 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3200 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3201 | { |
| 3202 | struct drm_device *dev = crtc->dev; |
| 3203 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3204 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3205 | bool pending; |
| 3206 | |
| 3207 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3208 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3209 | return false; |
| 3210 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3211 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3212 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3213 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3214 | |
| 3215 | return pending; |
| 3216 | } |
| 3217 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3218 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
| 3219 | struct intel_crtc_state *old_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3220 | { |
| 3221 | struct drm_device *dev = crtc->base.dev; |
| 3222 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3223 | struct intel_crtc_state *pipe_config = |
| 3224 | to_intel_crtc_state(crtc->base.state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3225 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3226 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
| 3227 | crtc->base.mode = crtc->base.state->mode; |
| 3228 | |
| 3229 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", |
| 3230 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, |
| 3231 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3232 | |
| 3233 | /* |
| 3234 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3235 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3236 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3237 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3238 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3239 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3240 | */ |
| 3241 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3242 | I915_WRITE(PIPESRC(crtc->pipe), |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3243 | ((pipe_config->pipe_src_w - 1) << 16) | |
| 3244 | (pipe_config->pipe_src_h - 1)); |
| 3245 | |
| 3246 | /* on skylake this is done by detaching scalers */ |
| 3247 | if (INTEL_INFO(dev)->gen >= 9) { |
| 3248 | skl_detach_scalers(crtc); |
| 3249 | |
| 3250 | if (pipe_config->pch_pfit.enabled) |
| 3251 | skylake_pfit_enable(crtc); |
| 3252 | } else if (HAS_PCH_SPLIT(dev)) { |
| 3253 | if (pipe_config->pch_pfit.enabled) |
| 3254 | ironlake_pfit_enable(crtc); |
| 3255 | else if (old_crtc_state->pch_pfit.enabled) |
| 3256 | ironlake_pfit_disable(crtc, true); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3257 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3258 | } |
| 3259 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3260 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3261 | { |
| 3262 | struct drm_device *dev = crtc->dev; |
| 3263 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3264 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3265 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3266 | i915_reg_t reg; |
| 3267 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3268 | |
| 3269 | /* enable normal train */ |
| 3270 | reg = FDI_TX_CTL(pipe); |
| 3271 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3272 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3273 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3274 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3275 | } else { |
| 3276 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3277 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3278 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3279 | I915_WRITE(reg, temp); |
| 3280 | |
| 3281 | reg = FDI_RX_CTL(pipe); |
| 3282 | temp = I915_READ(reg); |
| 3283 | if (HAS_PCH_CPT(dev)) { |
| 3284 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3285 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3286 | } else { |
| 3287 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3288 | temp |= FDI_LINK_TRAIN_NONE; |
| 3289 | } |
| 3290 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3291 | |
| 3292 | /* wait one idle pattern time */ |
| 3293 | POSTING_READ(reg); |
| 3294 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3295 | |
| 3296 | /* IVB wants error correction enabled */ |
| 3297 | if (IS_IVYBRIDGE(dev)) |
| 3298 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3299 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3300 | } |
| 3301 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3302 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3303 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3304 | { |
| 3305 | struct drm_device *dev = crtc->dev; |
| 3306 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3307 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3308 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3309 | i915_reg_t reg; |
| 3310 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3311 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3312 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3313 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3314 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3315 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3316 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3317 | reg = FDI_RX_IMR(pipe); |
| 3318 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3319 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3320 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3321 | I915_WRITE(reg, temp); |
| 3322 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3323 | udelay(150); |
| 3324 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3325 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3326 | reg = FDI_TX_CTL(pipe); |
| 3327 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3328 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3329 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3330 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3331 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3332 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3333 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3334 | reg = FDI_RX_CTL(pipe); |
| 3335 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3336 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3337 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3338 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3339 | |
| 3340 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3341 | udelay(150); |
| 3342 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3343 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3344 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3345 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3346 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3347 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3348 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3349 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3350 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3351 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3352 | |
| 3353 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3354 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3355 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3356 | break; |
| 3357 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3358 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3359 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3360 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3361 | |
| 3362 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3363 | reg = FDI_TX_CTL(pipe); |
| 3364 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3365 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3366 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3367 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3368 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3369 | reg = FDI_RX_CTL(pipe); |
| 3370 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3371 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3372 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3373 | I915_WRITE(reg, temp); |
| 3374 | |
| 3375 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3376 | udelay(150); |
| 3377 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3378 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3379 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3380 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3381 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3382 | |
| 3383 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3384 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3385 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3386 | break; |
| 3387 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3388 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3389 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3390 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3391 | |
| 3392 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3393 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3394 | } |
| 3395 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3396 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3397 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3398 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3399 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3400 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3401 | }; |
| 3402 | |
| 3403 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3404 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3405 | { |
| 3406 | struct drm_device *dev = crtc->dev; |
| 3407 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3408 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3409 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3410 | i915_reg_t reg; |
| 3411 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3412 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3413 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3414 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3415 | reg = FDI_RX_IMR(pipe); |
| 3416 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3417 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3418 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3419 | I915_WRITE(reg, temp); |
| 3420 | |
| 3421 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3422 | udelay(150); |
| 3423 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3424 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3425 | reg = FDI_TX_CTL(pipe); |
| 3426 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3427 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3428 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3429 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3430 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3431 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3432 | /* SNB-B */ |
| 3433 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3434 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3435 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3436 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3437 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3438 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3439 | reg = FDI_RX_CTL(pipe); |
| 3440 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3441 | if (HAS_PCH_CPT(dev)) { |
| 3442 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3443 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3444 | } else { |
| 3445 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3446 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3447 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3448 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3449 | |
| 3450 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3451 | udelay(150); |
| 3452 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3453 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3454 | reg = FDI_TX_CTL(pipe); |
| 3455 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3456 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3457 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3458 | I915_WRITE(reg, temp); |
| 3459 | |
| 3460 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3461 | udelay(500); |
| 3462 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3463 | for (retry = 0; retry < 5; retry++) { |
| 3464 | reg = FDI_RX_IIR(pipe); |
| 3465 | temp = I915_READ(reg); |
| 3466 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3467 | if (temp & FDI_RX_BIT_LOCK) { |
| 3468 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3469 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3470 | break; |
| 3471 | } |
| 3472 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3473 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3474 | if (retry < 5) |
| 3475 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3476 | } |
| 3477 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3478 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3479 | |
| 3480 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3481 | reg = FDI_TX_CTL(pipe); |
| 3482 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3483 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3484 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3485 | if (IS_GEN6(dev)) { |
| 3486 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3487 | /* SNB-B */ |
| 3488 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3489 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3490 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3491 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3492 | reg = FDI_RX_CTL(pipe); |
| 3493 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3494 | if (HAS_PCH_CPT(dev)) { |
| 3495 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3496 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3497 | } else { |
| 3498 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3499 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3500 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3501 | I915_WRITE(reg, temp); |
| 3502 | |
| 3503 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3504 | udelay(150); |
| 3505 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3506 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3507 | reg = FDI_TX_CTL(pipe); |
| 3508 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3509 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3510 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3511 | I915_WRITE(reg, temp); |
| 3512 | |
| 3513 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3514 | udelay(500); |
| 3515 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3516 | for (retry = 0; retry < 5; retry++) { |
| 3517 | reg = FDI_RX_IIR(pipe); |
| 3518 | temp = I915_READ(reg); |
| 3519 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3520 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3521 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3522 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3523 | break; |
| 3524 | } |
| 3525 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3526 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3527 | if (retry < 5) |
| 3528 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3529 | } |
| 3530 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3531 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3532 | |
| 3533 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3534 | } |
| 3535 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3536 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3537 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3538 | { |
| 3539 | struct drm_device *dev = crtc->dev; |
| 3540 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3541 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3542 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3543 | i915_reg_t reg; |
| 3544 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3545 | |
| 3546 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3547 | for train result */ |
| 3548 | reg = FDI_RX_IMR(pipe); |
| 3549 | temp = I915_READ(reg); |
| 3550 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3551 | temp &= ~FDI_RX_BIT_LOCK; |
| 3552 | I915_WRITE(reg, temp); |
| 3553 | |
| 3554 | POSTING_READ(reg); |
| 3555 | udelay(150); |
| 3556 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3557 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3558 | I915_READ(FDI_RX_IIR(pipe))); |
| 3559 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3560 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3561 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3562 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3563 | reg = FDI_TX_CTL(pipe); |
| 3564 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3565 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3566 | temp &= ~FDI_TX_ENABLE; |
| 3567 | I915_WRITE(reg, temp); |
| 3568 | |
| 3569 | reg = FDI_RX_CTL(pipe); |
| 3570 | temp = I915_READ(reg); |
| 3571 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3572 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3573 | temp &= ~FDI_RX_ENABLE; |
| 3574 | I915_WRITE(reg, temp); |
| 3575 | |
| 3576 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3577 | reg = FDI_TX_CTL(pipe); |
| 3578 | temp = I915_READ(reg); |
| 3579 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3580 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3581 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3582 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3583 | temp |= snb_b_fdi_train_param[j/2]; |
| 3584 | temp |= FDI_COMPOSITE_SYNC; |
| 3585 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3586 | |
| 3587 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3588 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3589 | |
| 3590 | reg = FDI_RX_CTL(pipe); |
| 3591 | temp = I915_READ(reg); |
| 3592 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3593 | temp |= FDI_COMPOSITE_SYNC; |
| 3594 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3595 | |
| 3596 | POSTING_READ(reg); |
| 3597 | udelay(1); /* should be 0.5us */ |
| 3598 | |
| 3599 | for (i = 0; i < 4; i++) { |
| 3600 | reg = FDI_RX_IIR(pipe); |
| 3601 | temp = I915_READ(reg); |
| 3602 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3603 | |
| 3604 | if (temp & FDI_RX_BIT_LOCK || |
| 3605 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3606 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3607 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3608 | i); |
| 3609 | break; |
| 3610 | } |
| 3611 | udelay(1); /* should be 0.5us */ |
| 3612 | } |
| 3613 | if (i == 4) { |
| 3614 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3615 | continue; |
| 3616 | } |
| 3617 | |
| 3618 | /* Train 2 */ |
| 3619 | reg = FDI_TX_CTL(pipe); |
| 3620 | temp = I915_READ(reg); |
| 3621 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3622 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3623 | I915_WRITE(reg, temp); |
| 3624 | |
| 3625 | reg = FDI_RX_CTL(pipe); |
| 3626 | temp = I915_READ(reg); |
| 3627 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3628 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3629 | I915_WRITE(reg, temp); |
| 3630 | |
| 3631 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3632 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3633 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3634 | for (i = 0; i < 4; i++) { |
| 3635 | reg = FDI_RX_IIR(pipe); |
| 3636 | temp = I915_READ(reg); |
| 3637 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3638 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3639 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3640 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3641 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3642 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3643 | i); |
| 3644 | goto train_done; |
| 3645 | } |
| 3646 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3647 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3648 | if (i == 4) |
| 3649 | 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] | 3650 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3651 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3652 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3653 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3654 | } |
| 3655 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3656 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3657 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3658 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3659 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3660 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3661 | i915_reg_t reg; |
| 3662 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3663 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3664 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3665 | reg = FDI_RX_CTL(pipe); |
| 3666 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3667 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3668 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3669 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3670 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3671 | |
| 3672 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3673 | udelay(200); |
| 3674 | |
| 3675 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3676 | temp = I915_READ(reg); |
| 3677 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3678 | |
| 3679 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3680 | udelay(200); |
| 3681 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3682 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3683 | reg = FDI_TX_CTL(pipe); |
| 3684 | temp = I915_READ(reg); |
| 3685 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3686 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3687 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3688 | POSTING_READ(reg); |
| 3689 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3693 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3694 | { |
| 3695 | struct drm_device *dev = intel_crtc->base.dev; |
| 3696 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3697 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3698 | i915_reg_t reg; |
| 3699 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3700 | |
| 3701 | /* Switch from PCDclk to Rawclk */ |
| 3702 | reg = FDI_RX_CTL(pipe); |
| 3703 | temp = I915_READ(reg); |
| 3704 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3705 | |
| 3706 | /* Disable CPU FDI TX PLL */ |
| 3707 | reg = FDI_TX_CTL(pipe); |
| 3708 | temp = I915_READ(reg); |
| 3709 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3710 | |
| 3711 | POSTING_READ(reg); |
| 3712 | udelay(100); |
| 3713 | |
| 3714 | reg = FDI_RX_CTL(pipe); |
| 3715 | temp = I915_READ(reg); |
| 3716 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3717 | |
| 3718 | /* Wait for the clocks to turn off. */ |
| 3719 | POSTING_READ(reg); |
| 3720 | udelay(100); |
| 3721 | } |
| 3722 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3723 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3724 | { |
| 3725 | struct drm_device *dev = crtc->dev; |
| 3726 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3727 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3728 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3729 | i915_reg_t reg; |
| 3730 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3731 | |
| 3732 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3733 | reg = FDI_TX_CTL(pipe); |
| 3734 | temp = I915_READ(reg); |
| 3735 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3736 | POSTING_READ(reg); |
| 3737 | |
| 3738 | reg = FDI_RX_CTL(pipe); |
| 3739 | temp = I915_READ(reg); |
| 3740 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3741 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3742 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3743 | |
| 3744 | POSTING_READ(reg); |
| 3745 | udelay(100); |
| 3746 | |
| 3747 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3748 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3749 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3750 | |
| 3751 | /* still set train pattern 1 */ |
| 3752 | reg = FDI_TX_CTL(pipe); |
| 3753 | temp = I915_READ(reg); |
| 3754 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3755 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3756 | I915_WRITE(reg, temp); |
| 3757 | |
| 3758 | reg = FDI_RX_CTL(pipe); |
| 3759 | temp = I915_READ(reg); |
| 3760 | if (HAS_PCH_CPT(dev)) { |
| 3761 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3762 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3763 | } else { |
| 3764 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3765 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3766 | } |
| 3767 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3768 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3769 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3770 | I915_WRITE(reg, temp); |
| 3771 | |
| 3772 | POSTING_READ(reg); |
| 3773 | udelay(100); |
| 3774 | } |
| 3775 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3776 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3777 | { |
| 3778 | struct intel_crtc *crtc; |
| 3779 | |
| 3780 | /* Note that we don't need to be called with mode_config.lock here |
| 3781 | * as our list of CRTC objects is static for the lifetime of the |
| 3782 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3783 | * happily treat the predicates as racy, atomic checks as userspace |
| 3784 | * cannot claim and pin a new fb without at least acquring the |
| 3785 | * struct_mutex and so serialising with us. |
| 3786 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3787 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3788 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3789 | continue; |
| 3790 | |
| 3791 | if (crtc->unpin_work) |
| 3792 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3793 | |
| 3794 | return true; |
| 3795 | } |
| 3796 | |
| 3797 | return false; |
| 3798 | } |
| 3799 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3800 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3801 | { |
| 3802 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3803 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3804 | |
| 3805 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3806 | smp_rmb(); |
| 3807 | intel_crtc->unpin_work = NULL; |
| 3808 | |
| 3809 | if (work->event) |
| 3810 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3811 | intel_crtc->pipe, |
| 3812 | work->event); |
| 3813 | |
| 3814 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3815 | |
| 3816 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3817 | queue_work(dev_priv->wq, &work->work); |
| 3818 | |
| 3819 | trace_i915_flip_complete(intel_crtc->plane, |
| 3820 | work->pending_flip_obj); |
| 3821 | } |
| 3822 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3823 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3824 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3825 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3826 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3827 | long ret; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3828 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3829 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3830 | |
| 3831 | ret = wait_event_interruptible_timeout( |
| 3832 | dev_priv->pending_flip_queue, |
| 3833 | !intel_crtc_has_pending_flip(crtc), |
| 3834 | 60*HZ); |
| 3835 | |
| 3836 | if (ret < 0) |
| 3837 | return ret; |
| 3838 | |
| 3839 | if (ret == 0) { |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3840 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3841 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3842 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3843 | if (intel_crtc->unpin_work) { |
| 3844 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3845 | page_flip_completed(intel_crtc); |
| 3846 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3847 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3848 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3849 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 3850 | return 0; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3851 | } |
| 3852 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3853 | static void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
| 3854 | { |
| 3855 | u32 temp; |
| 3856 | |
| 3857 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3858 | |
| 3859 | mutex_lock(&dev_priv->sb_lock); |
| 3860 | |
| 3861 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3862 | temp |= SBI_SSCCTL_DISABLE; |
| 3863 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 3864 | |
| 3865 | mutex_unlock(&dev_priv->sb_lock); |
| 3866 | } |
| 3867 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3868 | /* Program iCLKIP clock to the desired frequency */ |
| 3869 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3870 | { |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3871 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3872 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3873 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3874 | u32 temp; |
| 3875 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3876 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3877 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3878 | /* The iCLK virtual clock root frequency is in MHz, |
| 3879 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3880 | * divisors, it is necessary to divide one by another, so we |
| 3881 | * convert the virtual clock precision to KHz here for higher |
| 3882 | * precision. |
| 3883 | */ |
| 3884 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3885 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3886 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3887 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3888 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3889 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3890 | clock << auxdiv); |
| 3891 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 3892 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3893 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 3894 | /* |
| 3895 | * Near 20MHz is a corner case which is |
| 3896 | * out of range for the 7-bit divisor |
| 3897 | */ |
| 3898 | if (divsel <= 0x7f) |
| 3899 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | /* This should not happen with any sane values */ |
| 3903 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3904 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3905 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3906 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3907 | |
| 3908 | 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] | 3909 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3910 | auxdiv, |
| 3911 | divsel, |
| 3912 | phasedir, |
| 3913 | phaseinc); |
| 3914 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3915 | mutex_lock(&dev_priv->sb_lock); |
| 3916 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3917 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3918 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3919 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3920 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3921 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3922 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3923 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3924 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3925 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3926 | |
| 3927 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3928 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3929 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3930 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3931 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3932 | |
| 3933 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3934 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3935 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3936 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3937 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 3938 | mutex_unlock(&dev_priv->sb_lock); |
| 3939 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3940 | /* Wait for initialization time */ |
| 3941 | udelay(24); |
| 3942 | |
| 3943 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 3944 | } |
| 3945 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 3946 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 3947 | { |
| 3948 | u32 divsel, phaseinc, auxdiv; |
| 3949 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3950 | u32 iclk_pi_range = 64; |
| 3951 | u32 desired_divisor; |
| 3952 | u32 temp; |
| 3953 | |
| 3954 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 3955 | return 0; |
| 3956 | |
| 3957 | mutex_lock(&dev_priv->sb_lock); |
| 3958 | |
| 3959 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 3960 | if (temp & SBI_SSCCTL_DISABLE) { |
| 3961 | mutex_unlock(&dev_priv->sb_lock); |
| 3962 | return 0; |
| 3963 | } |
| 3964 | |
| 3965 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 3966 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 3967 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 3968 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 3969 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 3970 | |
| 3971 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 3972 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 3973 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 3974 | |
| 3975 | mutex_unlock(&dev_priv->sb_lock); |
| 3976 | |
| 3977 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 3978 | |
| 3979 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 3980 | desired_divisor << auxdiv); |
| 3981 | } |
| 3982 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3983 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3984 | enum pipe pch_transcoder) |
| 3985 | { |
| 3986 | struct drm_device *dev = crtc->base.dev; |
| 3987 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3988 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3989 | |
| 3990 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3991 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3992 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3993 | I915_READ(HBLANK(cpu_transcoder))); |
| 3994 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3995 | I915_READ(HSYNC(cpu_transcoder))); |
| 3996 | |
| 3997 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3998 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3999 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4000 | I915_READ(VBLANK(cpu_transcoder))); |
| 4001 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4002 | I915_READ(VSYNC(cpu_transcoder))); |
| 4003 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4004 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4005 | } |
| 4006 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4007 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4008 | { |
| 4009 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4010 | uint32_t temp; |
| 4011 | |
| 4012 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4013 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4014 | return; |
| 4015 | |
| 4016 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4017 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4018 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4019 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4020 | if (enable) |
| 4021 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4022 | |
| 4023 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4024 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4025 | POSTING_READ(SOUTH_CHICKEN1); |
| 4026 | } |
| 4027 | |
| 4028 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4029 | { |
| 4030 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4031 | |
| 4032 | switch (intel_crtc->pipe) { |
| 4033 | case PIPE_A: |
| 4034 | break; |
| 4035 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4036 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4037 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4038 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4039 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4040 | |
| 4041 | break; |
| 4042 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4043 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4044 | |
| 4045 | break; |
| 4046 | default: |
| 4047 | BUG(); |
| 4048 | } |
| 4049 | } |
| 4050 | |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4051 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 4052 | static enum port |
| 4053 | intel_trans_dp_port_sel(struct drm_crtc *crtc) |
| 4054 | { |
| 4055 | struct drm_device *dev = crtc->dev; |
| 4056 | struct intel_encoder *encoder; |
| 4057 | |
| 4058 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4059 | if (encoder->type == INTEL_OUTPUT_DISPLAYPORT || |
| 4060 | encoder->type == INTEL_OUTPUT_EDP) |
| 4061 | return enc_to_dig_port(&encoder->base)->port; |
| 4062 | } |
| 4063 | |
| 4064 | return -1; |
| 4065 | } |
| 4066 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4067 | /* |
| 4068 | * Enable PCH resources required for PCH ports: |
| 4069 | * - PCH PLLs |
| 4070 | * - FDI training & RX/TX |
| 4071 | * - update transcoder timings |
| 4072 | * - DP transcoding bits |
| 4073 | * - transcoder |
| 4074 | */ |
| 4075 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4076 | { |
| 4077 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4078 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4079 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4080 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4081 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4082 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4083 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4084 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4085 | if (IS_IVYBRIDGE(dev)) |
| 4086 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4087 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4088 | /* Write the TU size bits before fdi link training, so that error |
| 4089 | * detection works. */ |
| 4090 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4091 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4092 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4093 | /* |
| 4094 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 4095 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 4096 | */ |
| 4097 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4098 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4099 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4100 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4101 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4102 | /* We need to program the right clock selection before writing the pixel |
| 4103 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4104 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4105 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4106 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4107 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4108 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4109 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4110 | if (intel_crtc->config->shared_dpll == |
| 4111 | 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] | 4112 | temp |= sel; |
| 4113 | else |
| 4114 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4115 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4116 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4117 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4118 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4119 | * transcoder, and we actually should do this to not upset any PCH |
| 4120 | * transcoder that already use the clock when we share it. |
| 4121 | * |
| 4122 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4123 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4124 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4125 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4126 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4127 | /* set transcoder timing, panel must allow it */ |
| 4128 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4129 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4130 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4131 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4132 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4133 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4134 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4135 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4136 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4137 | const struct drm_display_mode *adjusted_mode = |
| 4138 | &intel_crtc->config->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4139 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4140 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4141 | temp = I915_READ(reg); |
| 4142 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4143 | TRANS_DP_SYNC_MASK | |
| 4144 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4145 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4146 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4147 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4148 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4149 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4150 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4151 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4152 | |
| 4153 | switch (intel_trans_dp_port_sel(crtc)) { |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4154 | case PORT_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4155 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4156 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4157 | case PORT_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4158 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4159 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4160 | case PORT_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4161 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4162 | break; |
| 4163 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4164 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4167 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4168 | } |
| 4169 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4170 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4171 | } |
| 4172 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4173 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4174 | { |
| 4175 | struct drm_device *dev = crtc->dev; |
| 4176 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4177 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4178 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4179 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4180 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4181 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4182 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4183 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4184 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4185 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4186 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4187 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4188 | } |
| 4189 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4190 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4191 | { |
| 4192 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4193 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4194 | u32 temp; |
| 4195 | |
| 4196 | temp = I915_READ(dslreg); |
| 4197 | udelay(500); |
| 4198 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4199 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4200 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4201 | } |
| 4202 | } |
| 4203 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4204 | static int |
| 4205 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
| 4206 | unsigned scaler_user, int *scaler_id, unsigned int rotation, |
| 4207 | int src_w, int src_h, int dst_w, int dst_h) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4208 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4209 | struct intel_crtc_scaler_state *scaler_state = |
| 4210 | &crtc_state->scaler_state; |
| 4211 | struct intel_crtc *intel_crtc = |
| 4212 | to_intel_crtc(crtc_state->base.crtc); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4213 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4214 | |
| 4215 | need_scaling = intel_rotation_90_or_270(rotation) ? |
| 4216 | (src_h != dst_w || src_w != dst_h): |
| 4217 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4218 | |
| 4219 | /* |
| 4220 | * if plane is being disabled or scaler is no more required or force detach |
| 4221 | * - free scaler binded to this plane/crtc |
| 4222 | * - in order to do this, update crtc->scaler_usage |
| 4223 | * |
| 4224 | * Here scaler state in crtc_state is set free so that |
| 4225 | * scaler can be assigned to other user. Actual register |
| 4226 | * update to free the scaler is done in plane/panel-fit programming. |
| 4227 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4228 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4229 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4230 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4231 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4232 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4233 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4234 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4235 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4236 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4237 | scaler_state->scaler_users); |
| 4238 | *scaler_id = -1; |
| 4239 | } |
| 4240 | return 0; |
| 4241 | } |
| 4242 | |
| 4243 | /* range checks */ |
| 4244 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4245 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4246 | |
| 4247 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4248 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4249 | 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] | 4250 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4251 | 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] | 4252 | return -EINVAL; |
| 4253 | } |
| 4254 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4255 | /* mark this plane as a scaler user in crtc_state */ |
| 4256 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4257 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4258 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4259 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4260 | scaler_state->scaler_users); |
| 4261 | |
| 4262 | return 0; |
| 4263 | } |
| 4264 | |
| 4265 | /** |
| 4266 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4267 | * |
| 4268 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4269 | * |
| 4270 | * Return |
| 4271 | * 0 - scaler_usage updated successfully |
| 4272 | * error - requested scaling cannot be supported or other error condition |
| 4273 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4274 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4275 | { |
| 4276 | struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4277 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4278 | |
| 4279 | DRM_DEBUG_KMS("Updating scaler for [CRTC:%i] scaler_user index %u.%u\n", |
| 4280 | intel_crtc->base.base.id, intel_crtc->pipe, SKL_CRTC_INDEX); |
| 4281 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4282 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Ville Syrjälä | fa5a797 | 2015-10-15 17:01:58 +0300 | [diff] [blame] | 4283 | &state->scaler_state.scaler_id, BIT(DRM_ROTATE_0), |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4284 | state->pipe_src_w, state->pipe_src_h, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 4285 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | /** |
| 4289 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
| 4290 | * |
| 4291 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4292 | * @plane_state: atomic plane state to update |
| 4293 | * |
| 4294 | * Return |
| 4295 | * 0 - scaler_usage updated successfully |
| 4296 | * error - requested scaling cannot be supported or other error condition |
| 4297 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4298 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4299 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4300 | { |
| 4301 | |
| 4302 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4303 | struct intel_plane *intel_plane = |
| 4304 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4305 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4306 | int ret; |
| 4307 | |
| 4308 | bool force_detach = !fb || !plane_state->visible; |
| 4309 | |
| 4310 | DRM_DEBUG_KMS("Updating scaler for [PLANE:%d] scaler_user index %u.%u\n", |
| 4311 | intel_plane->base.base.id, intel_crtc->pipe, |
| 4312 | drm_plane_index(&intel_plane->base)); |
| 4313 | |
| 4314 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4315 | drm_plane_index(&intel_plane->base), |
| 4316 | &plane_state->scaler_id, |
| 4317 | plane_state->base.rotation, |
| 4318 | drm_rect_width(&plane_state->src) >> 16, |
| 4319 | drm_rect_height(&plane_state->src) >> 16, |
| 4320 | drm_rect_width(&plane_state->dst), |
| 4321 | drm_rect_height(&plane_state->dst)); |
| 4322 | |
| 4323 | if (ret || plane_state->scaler_id < 0) |
| 4324 | return ret; |
| 4325 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4326 | /* check colorkey */ |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4327 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4328 | DRM_DEBUG_KMS("[PLANE:%d] scaling with color key not allowed", |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4329 | intel_plane->base.base.id); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4330 | return -EINVAL; |
| 4331 | } |
| 4332 | |
| 4333 | /* Check src format */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4334 | switch (fb->pixel_format) { |
| 4335 | case DRM_FORMAT_RGB565: |
| 4336 | case DRM_FORMAT_XBGR8888: |
| 4337 | case DRM_FORMAT_XRGB8888: |
| 4338 | case DRM_FORMAT_ABGR8888: |
| 4339 | case DRM_FORMAT_ARGB8888: |
| 4340 | case DRM_FORMAT_XRGB2101010: |
| 4341 | case DRM_FORMAT_XBGR2101010: |
| 4342 | case DRM_FORMAT_YUYV: |
| 4343 | case DRM_FORMAT_YVYU: |
| 4344 | case DRM_FORMAT_UYVY: |
| 4345 | case DRM_FORMAT_VYUY: |
| 4346 | break; |
| 4347 | default: |
| 4348 | DRM_DEBUG_KMS("[PLANE:%d] FB:%d unsupported scaling format 0x%x\n", |
| 4349 | intel_plane->base.base.id, fb->base.id, fb->pixel_format); |
| 4350 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4351 | } |
| 4352 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4353 | return 0; |
| 4354 | } |
| 4355 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4356 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4357 | { |
| 4358 | int i; |
| 4359 | |
| 4360 | for (i = 0; i < crtc->num_scalers; i++) |
| 4361 | skl_detach_scaler(crtc, i); |
| 4362 | } |
| 4363 | |
| 4364 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4365 | { |
| 4366 | struct drm_device *dev = crtc->base.dev; |
| 4367 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4368 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4369 | struct intel_crtc_scaler_state *scaler_state = |
| 4370 | &crtc->config->scaler_state; |
| 4371 | |
| 4372 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4373 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4374 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4375 | int id; |
| 4376 | |
| 4377 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4378 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4379 | return; |
| 4380 | } |
| 4381 | |
| 4382 | id = scaler_state->scaler_id; |
| 4383 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4384 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4385 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4386 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4387 | |
| 4388 | DRM_DEBUG_KMS("for crtc_state = %p scaler_id = %d\n", crtc->config, id); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4392 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4393 | { |
| 4394 | struct drm_device *dev = crtc->base.dev; |
| 4395 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4396 | int pipe = crtc->pipe; |
| 4397 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4398 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4399 | /* Force use of hard-coded filter coefficients |
| 4400 | * as some pre-programmed values are broken, |
| 4401 | * e.g. x201. |
| 4402 | */ |
| 4403 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4404 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4405 | PF_PIPE_SEL_IVB(pipe)); |
| 4406 | else |
| 4407 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4408 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4409 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4410 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4411 | } |
| 4412 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4413 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4414 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4415 | struct drm_device *dev = crtc->base.dev; |
| 4416 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4417 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4418 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4419 | return; |
| 4420 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 4421 | /* |
| 4422 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 4423 | * This function is called from post_plane_update, which is run after |
| 4424 | * a vblank wait. |
| 4425 | */ |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4426 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4427 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4428 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4429 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4430 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4431 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4432 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4433 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4434 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4435 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4436 | */ |
| 4437 | } else { |
| 4438 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4439 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4440 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4441 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4442 | * the HW state readout code will complain that the expected |
| 4443 | * IPS_CTL value is not the one we read. */ |
| 4444 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4445 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4446 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4447 | } |
| 4448 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4449 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4450 | { |
| 4451 | struct drm_device *dev = crtc->base.dev; |
| 4452 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4453 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4454 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4455 | return; |
| 4456 | |
| 4457 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4458 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4459 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4460 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4461 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4462 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4463 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4464 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4465 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4466 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4467 | POSTING_READ(IPS_CTL); |
| 4468 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4469 | |
| 4470 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4471 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4472 | } |
| 4473 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4474 | 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] | 4475 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4476 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4477 | struct drm_device *dev = intel_crtc->base.dev; |
| 4478 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4479 | |
| 4480 | mutex_lock(&dev->struct_mutex); |
| 4481 | dev_priv->mm.interruptible = false; |
| 4482 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4483 | dev_priv->mm.interruptible = true; |
| 4484 | mutex_unlock(&dev->struct_mutex); |
| 4485 | } |
| 4486 | |
| 4487 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4488 | * has to recompute where to put it anyway. |
| 4489 | */ |
| 4490 | } |
| 4491 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4492 | /** |
| 4493 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4494 | * @crtc: the CRTC whose primary plane was just enabled |
| 4495 | * |
| 4496 | * Performs potentially sleeping operations that must be done after the primary |
| 4497 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4498 | * called due to an explicit primary plane update, or due to an implicit |
| 4499 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4500 | * completely hide the primary plane. |
| 4501 | */ |
| 4502 | static void |
| 4503 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4504 | { |
| 4505 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4506 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4507 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4508 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4509 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4510 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4511 | * FIXME IPS should be fine as long as one plane is |
| 4512 | * enabled, but in practice it seems to have problems |
| 4513 | * when going from primary only to sprite only and vice |
| 4514 | * versa. |
| 4515 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4516 | hsw_enable_ips(intel_crtc); |
| 4517 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4518 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4519 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4520 | * So don't enable underrun reporting before at least some planes |
| 4521 | * are enabled. |
| 4522 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4523 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4524 | */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4525 | if (IS_GEN2(dev)) |
| 4526 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4527 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 4528 | /* Underruns don't always raise interrupts, so check manually. */ |
| 4529 | intel_check_cpu_fifo_underruns(dev_priv); |
| 4530 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4531 | } |
| 4532 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4533 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4534 | static void |
| 4535 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4536 | { |
| 4537 | struct drm_device *dev = crtc->dev; |
| 4538 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4539 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4540 | int pipe = intel_crtc->pipe; |
| 4541 | |
| 4542 | /* |
| 4543 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4544 | * So diasble underrun reporting before all the planes get disabled. |
| 4545 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4546 | * but leave the pipe running. |
| 4547 | */ |
| 4548 | if (IS_GEN2(dev)) |
| 4549 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4550 | |
| 4551 | /* |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4552 | * FIXME IPS should be fine as long as one plane is |
| 4553 | * enabled, but in practice it seems to have problems |
| 4554 | * when going from primary only to sprite only and vice |
| 4555 | * versa. |
| 4556 | */ |
| 4557 | hsw_disable_ips(intel_crtc); |
| 4558 | } |
| 4559 | |
| 4560 | /* FIXME get rid of this and use pre_plane_update */ |
| 4561 | static void |
| 4562 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 4563 | { |
| 4564 | struct drm_device *dev = crtc->dev; |
| 4565 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4566 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4567 | int pipe = intel_crtc->pipe; |
| 4568 | |
| 4569 | intel_pre_disable_primary(crtc); |
| 4570 | |
| 4571 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4572 | * Vblank time updates from the shadow to live plane control register |
| 4573 | * are blocked if the memory self-refresh mode is active at that |
| 4574 | * moment. So to make sure the plane gets truly disabled, disable |
| 4575 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4576 | * will be checked/applied by the HW only at the next frame start |
| 4577 | * event which is after the vblank start event, so we need to have a |
| 4578 | * wait-for-vblank between disabling the plane and the pipe. |
| 4579 | */ |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4580 | if (HAS_GMCH_DISPLAY(dev)) { |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4581 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 262cd2e | 2015-06-24 22:00:04 +0300 | [diff] [blame] | 4582 | dev_priv->wm.vlv.cxsr = false; |
| 4583 | intel_wait_for_vblank(dev, pipe); |
| 4584 | } |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4585 | } |
| 4586 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4587 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4588 | { |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4589 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 4590 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4591 | struct intel_crtc_state *pipe_config = |
| 4592 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4593 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4594 | struct drm_plane *primary = crtc->base.primary; |
| 4595 | struct drm_plane_state *old_pri_state = |
| 4596 | drm_atomic_get_existing_plane_state(old_state, primary); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4597 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4598 | intel_frontbuffer_flip(dev, pipe_config->fb_bits); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4599 | |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4600 | crtc->wm.cxsr_allowed = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4601 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 4602 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | f015c55 | 2015-06-24 22:00:02 +0300 | [diff] [blame] | 4603 | intel_update_watermarks(&crtc->base); |
| 4604 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4605 | if (old_pri_state) { |
| 4606 | struct intel_plane_state *primary_state = |
| 4607 | to_intel_plane_state(primary->state); |
| 4608 | struct intel_plane_state *old_primary_state = |
| 4609 | to_intel_plane_state(old_pri_state); |
| 4610 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 4611 | intel_fbc_post_update(crtc); |
| 4612 | |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 4613 | if (primary_state->visible && |
| 4614 | (needs_modeset(&pipe_config->base) || |
| 4615 | !old_primary_state->visible)) |
| 4616 | intel_post_enable_primary(&crtc->base); |
| 4617 | } |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4618 | } |
| 4619 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4620 | static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state) |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4621 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4622 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4623 | struct drm_device *dev = crtc->base.dev; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 4624 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4625 | struct intel_crtc_state *pipe_config = |
| 4626 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4627 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 4628 | struct drm_plane *primary = crtc->base.primary; |
| 4629 | struct drm_plane_state *old_pri_state = |
| 4630 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 4631 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4632 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4633 | if (old_pri_state) { |
| 4634 | struct intel_plane_state *primary_state = |
| 4635 | to_intel_plane_state(primary->state); |
| 4636 | struct intel_plane_state *old_primary_state = |
| 4637 | to_intel_plane_state(old_pri_state); |
| 4638 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 4639 | intel_fbc_pre_update(crtc); |
| 4640 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 4641 | if (old_primary_state->visible && |
| 4642 | (modeset || !primary_state->visible)) |
| 4643 | intel_pre_disable_primary(&crtc->base); |
| 4644 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4645 | |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 4646 | if (pipe_config->disable_cxsr) { |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4647 | crtc->wm.cxsr_allowed = false; |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4648 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4649 | /* |
| 4650 | * Vblank time updates from the shadow to live plane control register |
| 4651 | * are blocked if the memory self-refresh mode is active at that |
| 4652 | * moment. So to make sure the plane gets truly disabled, disable |
| 4653 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4654 | * will be checked/applied by the HW only at the next frame start |
| 4655 | * event which is after the vblank start event, so we need to have a |
| 4656 | * wait-for-vblank between disabling the plane and the pipe. |
| 4657 | */ |
| 4658 | if (old_crtc_state->base.active) { |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 4659 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4660 | dev_priv->wm.vlv.cxsr = false; |
| 4661 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4662 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 4663 | } |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4664 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 4665 | /* |
| 4666 | * IVB workaround: must disable low power watermarks for at least |
| 4667 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 4668 | * when scaling is disabled. |
| 4669 | * |
| 4670 | * WaCxSRDisabledForSpriteScaling:ivb |
| 4671 | */ |
| 4672 | if (pipe_config->disable_lp_wm) { |
| 4673 | ilk_disable_lp_wm(dev); |
| 4674 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4675 | } |
| 4676 | |
| 4677 | /* |
| 4678 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 4679 | * watermark programming here. |
| 4680 | */ |
| 4681 | if (needs_modeset(&pipe_config->base)) |
| 4682 | return; |
| 4683 | |
| 4684 | /* |
| 4685 | * For platforms that support atomic watermarks, program the |
| 4686 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 4687 | * will be the intermediate values that are safe for both pre- and |
| 4688 | * post- vblank; when vblank happens, the 'active' values will be set |
| 4689 | * to the final 'target' values and we'll do this again to get the |
| 4690 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 4691 | * will be the final target values which will get automatically latched |
| 4692 | * at vblank time; no further programming will be necessary. |
| 4693 | * |
| 4694 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 4695 | * we'll continue to update watermarks the old way, if flags tell |
| 4696 | * us to. |
| 4697 | */ |
| 4698 | if (dev_priv->display.initial_watermarks != NULL) |
| 4699 | dev_priv->display.initial_watermarks(pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 4700 | else if (pipe_config->update_wm_pre) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 4701 | intel_update_watermarks(&crtc->base); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 4702 | } |
| 4703 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4704 | static void intel_crtc_disable_planes(struct drm_crtc *crtc, unsigned plane_mask) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4705 | { |
| 4706 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4707 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4708 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4709 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4710 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4711 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 4712 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 4713 | drm_for_each_plane_mask(p, dev, plane_mask) |
| 4714 | to_intel_plane(p)->disable_plane(p, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4715 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4716 | /* |
| 4717 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4718 | * to compute the mask of flip planes precisely. For the time being |
| 4719 | * consider this a flip to a NULL plane. |
| 4720 | */ |
| 4721 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4722 | } |
| 4723 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4724 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4725 | { |
| 4726 | struct drm_device *dev = crtc->dev; |
| 4727 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4728 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4729 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4730 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4731 | struct intel_crtc_state *pipe_config = |
| 4732 | to_intel_crtc_state(crtc->state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4733 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4734 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4735 | return; |
| 4736 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4737 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4738 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4739 | |
| 4740 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4741 | intel_prepare_shared_dpll(intel_crtc); |
| 4742 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4743 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4744 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4745 | |
| 4746 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4747 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4748 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4749 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4750 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4751 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | ironlake_set_pipeconf(crtc); |
| 4755 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4756 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4757 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4758 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4759 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4760 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4761 | if (encoder->pre_enable) |
| 4762 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4763 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4764 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4765 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4766 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4767 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4768 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4769 | } else { |
| 4770 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4771 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4772 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4773 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4774 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4775 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4776 | /* |
| 4777 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4778 | * clocks enabled |
| 4779 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4780 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4781 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4782 | if (dev_priv->display.initial_watermarks != NULL) |
| 4783 | dev_priv->display.initial_watermarks(intel_crtc->config); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4784 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4785 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4786 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4787 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4788 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4789 | assert_vblank_disabled(crtc); |
| 4790 | drm_crtc_vblank_on(crtc); |
| 4791 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4792 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4793 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4794 | |
| 4795 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4796 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4797 | |
| 4798 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ |
| 4799 | if (intel_crtc->config->has_pch_encoder) |
| 4800 | intel_wait_for_vblank(dev, pipe); |
| 4801 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4802 | } |
| 4803 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4804 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4805 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4806 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4807 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4808 | } |
| 4809 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4810 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4811 | { |
| 4812 | struct drm_device *dev = crtc->dev; |
| 4813 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4814 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4815 | struct intel_encoder *encoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4816 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4817 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4818 | struct intel_crtc_state *pipe_config = |
| 4819 | to_intel_crtc_state(crtc->state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4820 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 4821 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4822 | return; |
| 4823 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 4824 | if (intel_crtc->config->has_pch_encoder) |
| 4825 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4826 | false); |
| 4827 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4828 | if (intel_crtc->config->shared_dpll) |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4829 | intel_enable_shared_dpll(intel_crtc); |
| 4830 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4831 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4832 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4833 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4834 | if (!intel_crtc->config->has_dsi_encoder) |
| 4835 | intel_set_pipe_timings(intel_crtc); |
| 4836 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 4837 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4838 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4839 | if (cpu_transcoder != TRANSCODER_EDP && |
| 4840 | !transcoder_is_dsi(cpu_transcoder)) { |
| 4841 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4842 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4843 | } |
| 4844 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4845 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4846 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4847 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4848 | } |
| 4849 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4850 | if (!intel_crtc->config->has_dsi_encoder) |
| 4851 | haswell_set_pipeconf(crtc); |
| 4852 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 4853 | haswell_set_pipemisc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4854 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4855 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4856 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4857 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4858 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4859 | if (intel_crtc->config->has_pch_encoder) |
| 4860 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4861 | else |
| 4862 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4863 | |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4864 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4865 | if (encoder->pre_enable) |
| 4866 | encoder->pre_enable(encoder); |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4867 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4868 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4869 | if (intel_crtc->config->has_pch_encoder) |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4870 | dev_priv->display.fdi_link_train(crtc); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4871 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4872 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4873 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4874 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4875 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4876 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 4877 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 4878 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4879 | |
| 4880 | /* |
| 4881 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4882 | * clocks enabled |
| 4883 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 4884 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4885 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4886 | intel_ddi_set_pipe_settings(crtc); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4887 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 4888 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4889 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 4890 | if (dev_priv->display.initial_watermarks != NULL) |
| 4891 | dev_priv->display.initial_watermarks(pipe_config); |
| 4892 | else |
| 4893 | intel_update_watermarks(crtc); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 4894 | |
| 4895 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 4896 | if (!intel_crtc->config->has_dsi_encoder) |
| 4897 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4898 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4899 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4900 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4901 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 4902 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4903 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4904 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4905 | assert_vblank_disabled(crtc); |
| 4906 | drm_crtc_vblank_on(crtc); |
| 4907 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4908 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4909 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4910 | intel_opregion_notify_encoder(encoder, true); |
| 4911 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4912 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4913 | if (intel_crtc->config->has_pch_encoder) { |
| 4914 | intel_wait_for_vblank(dev, pipe); |
| 4915 | intel_wait_for_vblank(dev, pipe); |
| 4916 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4917 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4918 | true); |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 4919 | } |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 4920 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4921 | /* If we change the relative order between pipe/planes enabling, we need |
| 4922 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 4923 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
| 4924 | if (IS_HASWELL(dev) && hsw_workaround_pipe != INVALID_PIPE) { |
| 4925 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4926 | intel_wait_for_vblank(dev, hsw_workaround_pipe); |
| 4927 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4928 | } |
| 4929 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4930 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4931 | { |
| 4932 | struct drm_device *dev = crtc->base.dev; |
| 4933 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4934 | int pipe = crtc->pipe; |
| 4935 | |
| 4936 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4937 | * it's in use. The hw state code will make sure we get this right. */ |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4938 | if (force || crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4939 | I915_WRITE(PF_CTL(pipe), 0); |
| 4940 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4941 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4942 | } |
| 4943 | } |
| 4944 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4945 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4946 | { |
| 4947 | struct drm_device *dev = crtc->dev; |
| 4948 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4949 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4950 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4951 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4952 | |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 4953 | if (intel_crtc->config->has_pch_encoder) |
| 4954 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4955 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4956 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4957 | encoder->disable(encoder); |
| 4958 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4959 | drm_crtc_vblank_off(crtc); |
| 4960 | assert_vblank_disabled(crtc); |
| 4961 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4962 | /* |
| 4963 | * Sometimes spurious CPU pipe underruns happen when the |
| 4964 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 4965 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 4966 | */ |
| 4967 | if (intel_crtc->config->has_pch_encoder) |
| 4968 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4969 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4970 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4971 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 4972 | ironlake_pfit_disable(intel_crtc, false); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4973 | |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4974 | if (intel_crtc->config->has_pch_encoder) { |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4975 | ironlake_fdi_disable(crtc); |
Ville Syrjälä | 3860b2e | 2015-11-20 22:09:18 +0200 | [diff] [blame] | 4976 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4977 | } |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 4978 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4979 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4980 | if (encoder->post_disable) |
| 4981 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4982 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4983 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4984 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4985 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4986 | if (HAS_PCH_CPT(dev)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4987 | i915_reg_t reg; |
| 4988 | u32 temp; |
| 4989 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4990 | /* disable TRANS_DP_CTL */ |
| 4991 | reg = TRANS_DP_CTL(pipe); |
| 4992 | temp = I915_READ(reg); |
| 4993 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4994 | TRANS_DP_PORT_SEL_MASK); |
| 4995 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4996 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4997 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4998 | /* disable DPLL_SEL */ |
| 4999 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5000 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5001 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5002 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5003 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5004 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5005 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5006 | |
| 5007 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5010 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 5011 | { |
| 5012 | struct drm_device *dev = crtc->dev; |
| 5013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5014 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5015 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5016 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5017 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5018 | if (intel_crtc->config->has_pch_encoder) |
| 5019 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5020 | false); |
| 5021 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5022 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5023 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5024 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 5025 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5026 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5027 | drm_crtc_vblank_off(crtc); |
| 5028 | assert_vblank_disabled(crtc); |
| 5029 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5030 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
| 5031 | if (!intel_crtc->config->has_dsi_encoder) |
| 5032 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5033 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5034 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5035 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5036 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5037 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5038 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5039 | |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 5040 | if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5041 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5042 | else |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5043 | ironlake_pfit_disable(intel_crtc, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5044 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 5045 | if (!intel_crtc->config->has_dsi_encoder) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5046 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5047 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 5048 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5049 | if (encoder->post_disable) |
| 5050 | encoder->post_disable(encoder); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5051 | |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5052 | if (intel_crtc->config->has_pch_encoder) { |
| 5053 | lpt_disable_pch_transcoder(dev_priv); |
Ville Syrjälä | 503a74e | 2015-12-04 22:22:14 +0200 | [diff] [blame] | 5054 | lpt_disable_iclkip(dev_priv); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5055 | intel_ddi_fdi_disable(crtc); |
| 5056 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5057 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5058 | true); |
Ville Syrjälä | 92966a3 | 2015-12-08 16:05:48 +0200 | [diff] [blame] | 5059 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5060 | } |
| 5061 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5062 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5063 | { |
| 5064 | struct drm_device *dev = crtc->base.dev; |
| 5065 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5066 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5067 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5068 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5069 | return; |
| 5070 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5071 | /* |
| 5072 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5073 | * according to register description and PRM. |
| 5074 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5075 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5076 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5077 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5078 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5079 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5080 | |
| 5081 | /* Border color in case we don't scale up to the full screen. Black by |
| 5082 | * default, change to something else for debugging. */ |
| 5083 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5086 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5087 | { |
| 5088 | switch (port) { |
| 5089 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5090 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5091 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5092 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5093 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5094 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5095 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5096 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5097 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5098 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5099 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5100 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5101 | return POWER_DOMAIN_PORT_OTHER; |
| 5102 | } |
| 5103 | } |
| 5104 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5105 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
| 5106 | { |
| 5107 | switch (port) { |
| 5108 | case PORT_A: |
| 5109 | return POWER_DOMAIN_AUX_A; |
| 5110 | case PORT_B: |
| 5111 | return POWER_DOMAIN_AUX_B; |
| 5112 | case PORT_C: |
| 5113 | return POWER_DOMAIN_AUX_C; |
| 5114 | case PORT_D: |
| 5115 | return POWER_DOMAIN_AUX_D; |
| 5116 | case PORT_E: |
| 5117 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5118 | return POWER_DOMAIN_AUX_D; |
| 5119 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5120 | MISSING_CASE(port); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5121 | return POWER_DOMAIN_AUX_A; |
| 5122 | } |
| 5123 | } |
| 5124 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5125 | enum intel_display_power_domain |
| 5126 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5127 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5128 | struct drm_device *dev = intel_encoder->base.dev; |
| 5129 | struct intel_digital_port *intel_dig_port; |
| 5130 | |
| 5131 | switch (intel_encoder->type) { |
| 5132 | case INTEL_OUTPUT_UNKNOWN: |
| 5133 | /* Only DDI platforms should ever use this output type */ |
| 5134 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5135 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5136 | case INTEL_OUTPUT_HDMI: |
| 5137 | case INTEL_OUTPUT_EDP: |
| 5138 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5139 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5140 | case INTEL_OUTPUT_DP_MST: |
| 5141 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5142 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5143 | case INTEL_OUTPUT_ANALOG: |
| 5144 | return POWER_DOMAIN_PORT_CRT; |
| 5145 | case INTEL_OUTPUT_DSI: |
| 5146 | return POWER_DOMAIN_PORT_DSI; |
| 5147 | default: |
| 5148 | return POWER_DOMAIN_PORT_OTHER; |
| 5149 | } |
| 5150 | } |
| 5151 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5152 | enum intel_display_power_domain |
| 5153 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) |
| 5154 | { |
| 5155 | struct drm_device *dev = intel_encoder->base.dev; |
| 5156 | struct intel_digital_port *intel_dig_port; |
| 5157 | |
| 5158 | switch (intel_encoder->type) { |
| 5159 | case INTEL_OUTPUT_UNKNOWN: |
Imre Deak | 651174a | 2015-11-18 15:57:24 +0200 | [diff] [blame] | 5160 | case INTEL_OUTPUT_HDMI: |
| 5161 | /* |
| 5162 | * Only DDI platforms should ever use these output types. |
| 5163 | * We can get here after the HDMI detect code has already set |
| 5164 | * the type of the shared encoder. Since we can't be sure |
| 5165 | * what's the status of the given connectors, play safe and |
| 5166 | * run the DP detection too. |
| 5167 | */ |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5168 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 5169 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5170 | case INTEL_OUTPUT_EDP: |
| 5171 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 5172 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5173 | case INTEL_OUTPUT_DP_MST: |
| 5174 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5175 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5176 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5177 | MISSING_CASE(intel_encoder->type); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5178 | return POWER_DOMAIN_AUX_A; |
| 5179 | } |
| 5180 | } |
| 5181 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5182 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
| 5183 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5184 | { |
| 5185 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5186 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5187 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5188 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5189 | unsigned long mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5190 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5191 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5192 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5193 | return 0; |
| 5194 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5195 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5196 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5197 | if (crtc_state->pch_pfit.enabled || |
| 5198 | crtc_state->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5199 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5200 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5201 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5202 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5203 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5204 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5205 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5206 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5207 | if (crtc_state->shared_dpll) |
| 5208 | mask |= BIT(POWER_DOMAIN_PLLS); |
| 5209 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5210 | return mask; |
| 5211 | } |
| 5212 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5213 | static unsigned long |
| 5214 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5215 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5216 | { |
| 5217 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5218 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5219 | enum intel_display_power_domain domain; |
| 5220 | unsigned long domains, new_domains, old_domains; |
| 5221 | |
| 5222 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5223 | intel_crtc->enabled_power_domains = new_domains = |
| 5224 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5225 | |
| 5226 | domains = new_domains & ~old_domains; |
| 5227 | |
| 5228 | for_each_power_domain(domain, domains) |
| 5229 | intel_display_power_get(dev_priv, domain); |
| 5230 | |
| 5231 | return old_domains & ~new_domains; |
| 5232 | } |
| 5233 | |
| 5234 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
| 5235 | unsigned long domains) |
| 5236 | { |
| 5237 | enum intel_display_power_domain domain; |
| 5238 | |
| 5239 | for_each_power_domain(domain, domains) |
| 5240 | intel_display_power_put(dev_priv, domain); |
| 5241 | } |
| 5242 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5243 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
| 5244 | { |
| 5245 | int max_cdclk_freq = dev_priv->max_cdclk_freq; |
| 5246 | |
| 5247 | if (INTEL_INFO(dev_priv)->gen >= 9 || |
| 5248 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
| 5249 | return max_cdclk_freq; |
| 5250 | else if (IS_CHERRYVIEW(dev_priv)) |
| 5251 | return max_cdclk_freq*95/100; |
| 5252 | else if (INTEL_INFO(dev_priv)->gen < 4) |
| 5253 | return 2*max_cdclk_freq*90/100; |
| 5254 | else |
| 5255 | return max_cdclk_freq*90/100; |
| 5256 | } |
| 5257 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5258 | static void intel_update_max_cdclk(struct drm_device *dev) |
| 5259 | { |
| 5260 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5261 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 5262 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5263 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
| 5264 | |
| 5265 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
| 5266 | dev_priv->max_cdclk_freq = 675000; |
| 5267 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
| 5268 | dev_priv->max_cdclk_freq = 540000; |
| 5269 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
| 5270 | dev_priv->max_cdclk_freq = 450000; |
| 5271 | else |
| 5272 | dev_priv->max_cdclk_freq = 337500; |
| 5273 | } else if (IS_BROADWELL(dev)) { |
| 5274 | /* |
| 5275 | * FIXME with extra cooling we can allow |
| 5276 | * 540 MHz for ULX and 675 Mhz for ULT. |
| 5277 | * How can we know if extra cooling is |
| 5278 | * available? PCI ID, VTB, something else? |
| 5279 | */ |
| 5280 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 5281 | dev_priv->max_cdclk_freq = 450000; |
| 5282 | else if (IS_BDW_ULX(dev)) |
| 5283 | dev_priv->max_cdclk_freq = 450000; |
| 5284 | else if (IS_BDW_ULT(dev)) |
| 5285 | dev_priv->max_cdclk_freq = 540000; |
| 5286 | else |
| 5287 | dev_priv->max_cdclk_freq = 675000; |
Mika Kahola | 0904dea | 2015-06-12 10:11:32 +0300 | [diff] [blame] | 5288 | } else if (IS_CHERRYVIEW(dev)) { |
| 5289 | dev_priv->max_cdclk_freq = 320000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5290 | } else if (IS_VALLEYVIEW(dev)) { |
| 5291 | dev_priv->max_cdclk_freq = 400000; |
| 5292 | } else { |
| 5293 | /* otherwise assume cdclk is fixed */ |
| 5294 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; |
| 5295 | } |
| 5296 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5297 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
| 5298 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5299 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
| 5300 | dev_priv->max_cdclk_freq); |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5301 | |
| 5302 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", |
| 5303 | dev_priv->max_dotclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5304 | } |
| 5305 | |
| 5306 | static void intel_update_cdclk(struct drm_device *dev) |
| 5307 | { |
| 5308 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5309 | |
| 5310 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
| 5311 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
| 5312 | dev_priv->cdclk_freq); |
| 5313 | |
| 5314 | /* |
| 5315 | * Program the gmbus_freq based on the cdclk frequency. |
| 5316 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5317 | * in fact 1MHz is the correct frequency. |
| 5318 | */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 5319 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5320 | /* |
| 5321 | * Program the gmbus_freq based on the cdclk frequency. |
| 5322 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5323 | * in fact 1MHz is the correct frequency. |
| 5324 | */ |
| 5325 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
| 5326 | } |
| 5327 | |
| 5328 | if (dev_priv->max_cdclk_freq == 0) |
| 5329 | intel_update_max_cdclk(dev); |
| 5330 | } |
| 5331 | |
Damien Lespiau | 70d0c57 | 2015-06-04 18:21:29 +0100 | [diff] [blame] | 5332 | static void broxton_set_cdclk(struct drm_device *dev, int frequency) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5333 | { |
| 5334 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5335 | uint32_t divider; |
| 5336 | uint32_t ratio; |
| 5337 | uint32_t current_freq; |
| 5338 | int ret; |
| 5339 | |
| 5340 | /* frequency = 19.2MHz * ratio / 2 / div{1,1.5,2,4} */ |
| 5341 | switch (frequency) { |
| 5342 | case 144000: |
| 5343 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
| 5344 | ratio = BXT_DE_PLL_RATIO(60); |
| 5345 | break; |
| 5346 | case 288000: |
| 5347 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
| 5348 | ratio = BXT_DE_PLL_RATIO(60); |
| 5349 | break; |
| 5350 | case 384000: |
| 5351 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
| 5352 | ratio = BXT_DE_PLL_RATIO(60); |
| 5353 | break; |
| 5354 | case 576000: |
| 5355 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5356 | ratio = BXT_DE_PLL_RATIO(60); |
| 5357 | break; |
| 5358 | case 624000: |
| 5359 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 5360 | ratio = BXT_DE_PLL_RATIO(65); |
| 5361 | break; |
| 5362 | case 19200: |
| 5363 | /* |
| 5364 | * Bypass frequency with DE PLL disabled. Init ratio, divider |
| 5365 | * to suppress GCC warning. |
| 5366 | */ |
| 5367 | ratio = 0; |
| 5368 | divider = 0; |
| 5369 | break; |
| 5370 | default: |
| 5371 | DRM_ERROR("unsupported CDCLK freq %d", frequency); |
| 5372 | |
| 5373 | return; |
| 5374 | } |
| 5375 | |
| 5376 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5377 | /* Inform power controller of upcoming frequency change */ |
| 5378 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5379 | 0x80000000); |
| 5380 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5381 | |
| 5382 | if (ret) { |
| 5383 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
| 5384 | ret, frequency); |
| 5385 | return; |
| 5386 | } |
| 5387 | |
| 5388 | current_freq = I915_READ(CDCLK_CTL) & CDCLK_FREQ_DECIMAL_MASK; |
| 5389 | /* convert from .1 fixpoint MHz with -1MHz offset to kHz */ |
| 5390 | current_freq = current_freq * 500 + 1000; |
| 5391 | |
| 5392 | /* |
| 5393 | * DE PLL has to be disabled when |
| 5394 | * - setting to 19.2MHz (bypass, PLL isn't used) |
| 5395 | * - before setting to 624MHz (PLL needs toggling) |
| 5396 | * - before setting to any frequency from 624MHz (PLL needs toggling) |
| 5397 | */ |
| 5398 | if (frequency == 19200 || frequency == 624000 || |
| 5399 | current_freq == 624000) { |
| 5400 | I915_WRITE(BXT_DE_PLL_ENABLE, ~BXT_DE_PLL_PLL_ENABLE); |
| 5401 | /* Timeout 200us */ |
| 5402 | if (wait_for(!(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK), |
| 5403 | 1)) |
| 5404 | DRM_ERROR("timout waiting for DE PLL unlock\n"); |
| 5405 | } |
| 5406 | |
| 5407 | if (frequency != 19200) { |
| 5408 | uint32_t val; |
| 5409 | |
| 5410 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5411 | val &= ~BXT_DE_PLL_RATIO_MASK; |
| 5412 | val |= ratio; |
| 5413 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5414 | |
| 5415 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5416 | /* Timeout 200us */ |
| 5417 | if (wait_for(I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_LOCK, 1)) |
| 5418 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
| 5419 | |
| 5420 | val = I915_READ(CDCLK_CTL); |
| 5421 | val &= ~BXT_CDCLK_CD2X_DIV_SEL_MASK; |
| 5422 | val |= divider; |
| 5423 | /* |
| 5424 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 5425 | * enable otherwise. |
| 5426 | */ |
| 5427 | val &= ~BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5428 | if (frequency >= 500000) |
| 5429 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 5430 | |
| 5431 | val &= ~CDCLK_FREQ_DECIMAL_MASK; |
| 5432 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5433 | val |= (frequency - 1000) / 500; |
| 5434 | I915_WRITE(CDCLK_CTL, val); |
| 5435 | } |
| 5436 | |
| 5437 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5438 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 5439 | DIV_ROUND_UP(frequency, 25000)); |
| 5440 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5441 | |
| 5442 | if (ret) { |
| 5443 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
| 5444 | ret, frequency); |
| 5445 | return; |
| 5446 | } |
| 5447 | |
Damien Lespiau | a47871b | 2015-06-04 18:21:34 +0100 | [diff] [blame] | 5448 | intel_update_cdclk(dev); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | void broxton_init_cdclk(struct drm_device *dev) |
| 5452 | { |
| 5453 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5454 | uint32_t val; |
| 5455 | |
| 5456 | /* |
| 5457 | * NDE_RSTWRN_OPT RST PCH Handshake En must always be 0b on BXT |
| 5458 | * or else the reset will hang because there is no PCH to respond. |
| 5459 | * Move the handshake programming to initialization sequence. |
| 5460 | * Previously was left up to BIOS. |
| 5461 | */ |
| 5462 | val = I915_READ(HSW_NDE_RSTWRN_OPT); |
| 5463 | val &= ~RESET_PCH_HANDSHAKE_ENABLE; |
| 5464 | I915_WRITE(HSW_NDE_RSTWRN_OPT, val); |
| 5465 | |
| 5466 | /* Enable PG1 for cdclk */ |
| 5467 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 5468 | |
| 5469 | /* check if cd clock is enabled */ |
| 5470 | if (I915_READ(BXT_DE_PLL_ENABLE) & BXT_DE_PLL_PLL_ENABLE) { |
| 5471 | DRM_DEBUG_KMS("Display already initialized\n"); |
| 5472 | return; |
| 5473 | } |
| 5474 | |
| 5475 | /* |
| 5476 | * FIXME: |
| 5477 | * - The initial CDCLK needs to be read from VBT. |
| 5478 | * Need to make this change after VBT has changes for BXT. |
| 5479 | * - check if setting the max (or any) cdclk freq is really necessary |
| 5480 | * here, it belongs to modeset time |
| 5481 | */ |
| 5482 | broxton_set_cdclk(dev, 624000); |
| 5483 | |
| 5484 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5485 | POSTING_READ(DBUF_CTL); |
| 5486 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5487 | udelay(10); |
| 5488 | |
| 5489 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5490 | DRM_ERROR("DBuf power enable timeout!\n"); |
| 5491 | } |
| 5492 | |
| 5493 | void broxton_uninit_cdclk(struct drm_device *dev) |
| 5494 | { |
| 5495 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5496 | |
| 5497 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
Ville Syrjälä | 22e02c0 | 2015-05-06 14:28:57 +0300 | [diff] [blame] | 5498 | POSTING_READ(DBUF_CTL); |
| 5499 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5500 | udelay(10); |
| 5501 | |
| 5502 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5503 | DRM_ERROR("DBuf power disable timeout!\n"); |
| 5504 | |
| 5505 | /* Set minimum (bypass) frequency, in effect turning off the DE PLL */ |
| 5506 | broxton_set_cdclk(dev, 19200); |
| 5507 | |
| 5508 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
| 5509 | } |
| 5510 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5511 | static const struct skl_cdclk_entry { |
| 5512 | unsigned int freq; |
| 5513 | unsigned int vco; |
| 5514 | } skl_cdclk_frequencies[] = { |
| 5515 | { .freq = 308570, .vco = 8640 }, |
| 5516 | { .freq = 337500, .vco = 8100 }, |
| 5517 | { .freq = 432000, .vco = 8640 }, |
| 5518 | { .freq = 450000, .vco = 8100 }, |
| 5519 | { .freq = 540000, .vco = 8100 }, |
| 5520 | { .freq = 617140, .vco = 8640 }, |
| 5521 | { .freq = 675000, .vco = 8100 }, |
| 5522 | }; |
| 5523 | |
| 5524 | static unsigned int skl_cdclk_decimal(unsigned int freq) |
| 5525 | { |
| 5526 | return (freq - 1000) / 500; |
| 5527 | } |
| 5528 | |
| 5529 | static unsigned int skl_cdclk_get_vco(unsigned int freq) |
| 5530 | { |
| 5531 | unsigned int i; |
| 5532 | |
| 5533 | for (i = 0; i < ARRAY_SIZE(skl_cdclk_frequencies); i++) { |
| 5534 | const struct skl_cdclk_entry *e = &skl_cdclk_frequencies[i]; |
| 5535 | |
| 5536 | if (e->freq == freq) |
| 5537 | return e->vco; |
| 5538 | } |
| 5539 | |
| 5540 | return 8100; |
| 5541 | } |
| 5542 | |
| 5543 | static void |
| 5544 | skl_dpll0_enable(struct drm_i915_private *dev_priv, unsigned int required_vco) |
| 5545 | { |
| 5546 | unsigned int min_freq; |
| 5547 | u32 val; |
| 5548 | |
| 5549 | /* select the minimum CDCLK before enabling DPLL 0 */ |
| 5550 | val = I915_READ(CDCLK_CTL); |
| 5551 | val &= ~CDCLK_FREQ_SEL_MASK | ~CDCLK_FREQ_DECIMAL_MASK; |
| 5552 | val |= CDCLK_FREQ_337_308; |
| 5553 | |
| 5554 | if (required_vco == 8640) |
| 5555 | min_freq = 308570; |
| 5556 | else |
| 5557 | min_freq = 337500; |
| 5558 | |
| 5559 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_freq); |
| 5560 | |
| 5561 | I915_WRITE(CDCLK_CTL, val); |
| 5562 | POSTING_READ(CDCLK_CTL); |
| 5563 | |
| 5564 | /* |
| 5565 | * We always enable DPLL0 with the lowest link rate possible, but still |
| 5566 | * taking into account the VCO required to operate the eDP panel at the |
| 5567 | * desired frequency. The usual DP link rates operate with a VCO of |
| 5568 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. |
| 5569 | * The modeset code is responsible for the selection of the exact link |
| 5570 | * rate later on, with the constraint of choosing a frequency that |
| 5571 | * works with required_vco. |
| 5572 | */ |
| 5573 | val = I915_READ(DPLL_CTRL1); |
| 5574 | |
| 5575 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 5576 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
| 5577 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); |
| 5578 | if (required_vco == 8640) |
| 5579 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
| 5580 | SKL_DPLL0); |
| 5581 | else |
| 5582 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
| 5583 | SKL_DPLL0); |
| 5584 | |
| 5585 | I915_WRITE(DPLL_CTRL1, val); |
| 5586 | POSTING_READ(DPLL_CTRL1); |
| 5587 | |
| 5588 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); |
| 5589 | |
| 5590 | if (wait_for(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK, 5)) |
| 5591 | DRM_ERROR("DPLL0 not locked\n"); |
| 5592 | } |
| 5593 | |
| 5594 | static bool skl_cdclk_pcu_ready(struct drm_i915_private *dev_priv) |
| 5595 | { |
| 5596 | int ret; |
| 5597 | u32 val; |
| 5598 | |
| 5599 | /* inform PCU we want to change CDCLK */ |
| 5600 | val = SKL_CDCLK_PREPARE_FOR_CHANGE; |
| 5601 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5602 | ret = sandybridge_pcode_read(dev_priv, SKL_PCODE_CDCLK_CONTROL, &val); |
| 5603 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5604 | |
| 5605 | return ret == 0 && (val & SKL_CDCLK_READY_FOR_CHANGE); |
| 5606 | } |
| 5607 | |
| 5608 | static bool skl_cdclk_wait_for_pcu_ready(struct drm_i915_private *dev_priv) |
| 5609 | { |
| 5610 | unsigned int i; |
| 5611 | |
| 5612 | for (i = 0; i < 15; i++) { |
| 5613 | if (skl_cdclk_pcu_ready(dev_priv)) |
| 5614 | return true; |
| 5615 | udelay(10); |
| 5616 | } |
| 5617 | |
| 5618 | return false; |
| 5619 | } |
| 5620 | |
| 5621 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, unsigned int freq) |
| 5622 | { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5623 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5624 | u32 freq_select, pcu_ack; |
| 5625 | |
| 5626 | DRM_DEBUG_DRIVER("Changing CDCLK to %dKHz\n", freq); |
| 5627 | |
| 5628 | if (!skl_cdclk_wait_for_pcu_ready(dev_priv)) { |
| 5629 | DRM_ERROR("failed to inform PCU about cdclk change\n"); |
| 5630 | return; |
| 5631 | } |
| 5632 | |
| 5633 | /* set CDCLK_CTL */ |
| 5634 | switch(freq) { |
| 5635 | case 450000: |
| 5636 | case 432000: |
| 5637 | freq_select = CDCLK_FREQ_450_432; |
| 5638 | pcu_ack = 1; |
| 5639 | break; |
| 5640 | case 540000: |
| 5641 | freq_select = CDCLK_FREQ_540; |
| 5642 | pcu_ack = 2; |
| 5643 | break; |
| 5644 | case 308570: |
| 5645 | case 337500: |
| 5646 | default: |
| 5647 | freq_select = CDCLK_FREQ_337_308; |
| 5648 | pcu_ack = 0; |
| 5649 | break; |
| 5650 | case 617140: |
| 5651 | case 675000: |
| 5652 | freq_select = CDCLK_FREQ_675_617; |
| 5653 | pcu_ack = 3; |
| 5654 | break; |
| 5655 | } |
| 5656 | |
| 5657 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(freq)); |
| 5658 | POSTING_READ(CDCLK_CTL); |
| 5659 | |
| 5660 | /* inform PCU of the change */ |
| 5661 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5662 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); |
| 5663 | mutex_unlock(&dev_priv->rps.hw_lock); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5664 | |
| 5665 | intel_update_cdclk(dev); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
| 5669 | { |
| 5670 | /* disable DBUF power */ |
| 5671 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) & ~DBUF_POWER_REQUEST); |
| 5672 | POSTING_READ(DBUF_CTL); |
| 5673 | |
| 5674 | udelay(10); |
| 5675 | |
| 5676 | if (I915_READ(DBUF_CTL) & DBUF_POWER_STATE) |
| 5677 | DRM_ERROR("DBuf power disable timeout\n"); |
| 5678 | |
Imre Deak | ab96c1ee | 2015-11-04 19:24:18 +0200 | [diff] [blame] | 5679 | /* disable DPLL0 */ |
| 5680 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); |
| 5681 | if (wait_for(!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_LOCK), 1)) |
| 5682 | DRM_ERROR("Couldn't disable DPLL0\n"); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5683 | } |
| 5684 | |
| 5685 | void skl_init_cdclk(struct drm_i915_private *dev_priv) |
| 5686 | { |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5687 | unsigned int required_vco; |
| 5688 | |
Gary Wang | 39d9b85 | 2015-08-28 16:40:34 +0800 | [diff] [blame] | 5689 | /* DPLL0 not enabled (happens on early BIOS versions) */ |
| 5690 | if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE)) { |
| 5691 | /* enable DPLL0 */ |
| 5692 | required_vco = skl_cdclk_get_vco(dev_priv->skl_boot_cdclk); |
| 5693 | skl_dpll0_enable(dev_priv, required_vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5694 | } |
| 5695 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 5696 | /* set CDCLK to the frequency the BIOS chose */ |
| 5697 | skl_set_cdclk(dev_priv, dev_priv->skl_boot_cdclk); |
| 5698 | |
| 5699 | /* enable DBUF power */ |
| 5700 | I915_WRITE(DBUF_CTL, I915_READ(DBUF_CTL) | DBUF_POWER_REQUEST); |
| 5701 | POSTING_READ(DBUF_CTL); |
| 5702 | |
| 5703 | udelay(10); |
| 5704 | |
| 5705 | if (!(I915_READ(DBUF_CTL) & DBUF_POWER_STATE)) |
| 5706 | DRM_ERROR("DBuf power enable timeout\n"); |
| 5707 | } |
| 5708 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5709 | int skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
| 5710 | { |
| 5711 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 5712 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 5713 | int freq = dev_priv->skl_boot_cdclk; |
| 5714 | |
Shobhit Kumar | f1b391a | 2015-11-05 18:05:32 +0530 | [diff] [blame] | 5715 | /* |
| 5716 | * check if the pre-os intialized the display |
| 5717 | * There is SWF18 scratchpad register defined which is set by the |
| 5718 | * pre-os which can be used by the OS drivers to check the status |
| 5719 | */ |
| 5720 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) |
| 5721 | goto sanitize; |
| 5722 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 5723 | /* Is PLL enabled and locked ? */ |
| 5724 | if (!((lcpll1 & LCPLL_PLL_ENABLE) && (lcpll1 & LCPLL_PLL_LOCK))) |
| 5725 | goto sanitize; |
| 5726 | |
| 5727 | /* DPLL okay; verify the cdclock |
| 5728 | * |
| 5729 | * Noticed in some instances that the freq selection is correct but |
| 5730 | * decimal part is programmed wrong from BIOS where pre-os does not |
| 5731 | * enable display. Verify the same as well. |
| 5732 | */ |
| 5733 | if (cdctl == ((cdctl & CDCLK_FREQ_SEL_MASK) | skl_cdclk_decimal(freq))) |
| 5734 | /* All well; nothing to sanitize */ |
| 5735 | return false; |
| 5736 | sanitize: |
| 5737 | /* |
| 5738 | * As of now initialize with max cdclk till |
| 5739 | * we get dynamic cdclk support |
| 5740 | * */ |
| 5741 | dev_priv->skl_boot_cdclk = dev_priv->max_cdclk_freq; |
| 5742 | skl_init_cdclk(dev_priv); |
| 5743 | |
| 5744 | /* we did have to sanitize */ |
| 5745 | return true; |
| 5746 | } |
| 5747 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5748 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5749 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5750 | { |
| 5751 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5752 | u32 val, cmd; |
| 5753 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5754 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5755 | != dev_priv->cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5756 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5757 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5758 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5759 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5760 | cmd = 1; |
| 5761 | else |
| 5762 | cmd = 0; |
| 5763 | |
| 5764 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5765 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5766 | val &= ~DSPFREQGUAR_MASK; |
| 5767 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5768 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5769 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5770 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5771 | 50)) { |
| 5772 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5773 | } |
| 5774 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5775 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5776 | mutex_lock(&dev_priv->sb_lock); |
| 5777 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5778 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5779 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5780 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5781 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5782 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5783 | /* adjust cdclk divider */ |
| 5784 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5785 | val &= ~CCK_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5786 | val |= divider; |
| 5787 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5788 | |
| 5789 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 5790 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5791 | 50)) |
| 5792 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5793 | } |
| 5794 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5795 | /* adjust self-refresh exit latency value */ |
| 5796 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5797 | val &= ~0x7f; |
| 5798 | |
| 5799 | /* |
| 5800 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5801 | * so that the core display fetch happens in time to avoid underruns. |
| 5802 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5803 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5804 | val |= 4500 / 250; /* 4.5 usec */ |
| 5805 | else |
| 5806 | val |= 3000 / 250; /* 3.0 usec */ |
| 5807 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 5808 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 5809 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5810 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5811 | intel_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5812 | } |
| 5813 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5814 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5815 | { |
| 5816 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5817 | u32 val, cmd; |
| 5818 | |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 5819 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) |
| 5820 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5821 | |
| 5822 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5823 | case 333333: |
| 5824 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5825 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5826 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5827 | break; |
| 5828 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5829 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5830 | return; |
| 5831 | } |
| 5832 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5833 | /* |
| 5834 | * Specs are full of misinformation, but testing on actual |
| 5835 | * hardware has shown that we just need to write the desired |
| 5836 | * CCK divider into the Punit register. |
| 5837 | */ |
| 5838 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5839 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5840 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5841 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5842 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5843 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5844 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5845 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5846 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5847 | 50)) { |
| 5848 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5849 | } |
| 5850 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5851 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 5852 | intel_update_cdclk(dev); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5853 | } |
| 5854 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5855 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5856 | int max_pixclk) |
| 5857 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5858 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5859 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5860 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5861 | /* |
| 5862 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5863 | * 200MHz |
| 5864 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5865 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5866 | * 400MHz (VLV only) |
| 5867 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5868 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5869 | * |
| 5870 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5871 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5872 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5873 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5874 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5875 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5876 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5877 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5878 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5879 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5880 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5881 | else |
| 5882 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5883 | } |
| 5884 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5885 | static int broxton_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5886 | int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5887 | { |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5888 | /* |
| 5889 | * FIXME: |
| 5890 | * - remove the guardband, it's not needed on BXT |
| 5891 | * - set 19.2MHz bypass frequency if there are no active pipes |
| 5892 | */ |
| 5893 | if (max_pixclk > 576000*9/10) |
| 5894 | return 624000; |
| 5895 | else if (max_pixclk > 384000*9/10) |
| 5896 | return 576000; |
| 5897 | else if (max_pixclk > 288000*9/10) |
| 5898 | return 384000; |
| 5899 | else if (max_pixclk > 144000*9/10) |
| 5900 | return 288000; |
| 5901 | else |
| 5902 | return 144000; |
| 5903 | } |
| 5904 | |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 5905 | /* Compute the max pixel clock for new configuration. */ |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 5906 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 5907 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5908 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5909 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 5910 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5911 | struct drm_crtc *crtc; |
| 5912 | struct drm_crtc_state *crtc_state; |
| 5913 | unsigned max_pixclk = 0, i; |
| 5914 | enum pipe pipe; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5915 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5916 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 5917 | sizeof(intel_state->min_pixclk)); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5918 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5919 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 5920 | int pixclk = 0; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5921 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5922 | if (crtc_state->enable) |
| 5923 | pixclk = crtc_state->adjusted_mode.crtc_clock; |
| 5924 | |
| 5925 | intel_state->min_pixclk[i] = pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5926 | } |
| 5927 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 5928 | for_each_pipe(dev_priv, pipe) |
| 5929 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); |
| 5930 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5931 | return max_pixclk; |
| 5932 | } |
| 5933 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5934 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5935 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5936 | struct drm_device *dev = state->dev; |
| 5937 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5938 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5939 | struct intel_atomic_state *intel_state = |
| 5940 | to_intel_atomic_state(state); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5941 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5942 | if (max_pixclk < 0) |
| 5943 | return max_pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5944 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5945 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5946 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5947 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5948 | if (!intel_state->active_crtcs) |
| 5949 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); |
| 5950 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5951 | return 0; |
| 5952 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5953 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5954 | static int broxton_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 5955 | { |
| 5956 | struct drm_device *dev = state->dev; |
| 5957 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5958 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5959 | struct intel_atomic_state *intel_state = |
| 5960 | to_intel_atomic_state(state); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5961 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5962 | if (max_pixclk < 0) |
| 5963 | return max_pixclk; |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5964 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5965 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5966 | broxton_calc_cdclk(dev_priv, max_pixclk); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 5967 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 5968 | if (!intel_state->active_crtcs) |
| 5969 | intel_state->dev_cdclk = broxton_calc_cdclk(dev_priv, 0); |
| 5970 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 5971 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5972 | } |
| 5973 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5974 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5975 | { |
| 5976 | unsigned int credits, default_credits; |
| 5977 | |
| 5978 | if (IS_CHERRYVIEW(dev_priv)) |
| 5979 | default_credits = PFI_CREDIT(12); |
| 5980 | else |
| 5981 | default_credits = PFI_CREDIT(8); |
| 5982 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 5983 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5984 | /* CHV suggested value is 31 or 63 */ |
| 5985 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | fcc0008 | 2015-05-26 20:22:40 +0300 | [diff] [blame] | 5986 | credits = PFI_CREDIT_63; |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5987 | else |
| 5988 | credits = PFI_CREDIT(15); |
| 5989 | } else { |
| 5990 | credits = default_credits; |
| 5991 | } |
| 5992 | |
| 5993 | /* |
| 5994 | * WA - write default credits before re-programming |
| 5995 | * FIXME: should we also set the resend bit here? |
| 5996 | */ |
| 5997 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5998 | default_credits); |
| 5999 | |
| 6000 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6001 | credits | PFI_CREDIT_RESEND); |
| 6002 | |
| 6003 | /* |
| 6004 | * FIXME is this guaranteed to clear |
| 6005 | * immediately or should we poll for it? |
| 6006 | */ |
| 6007 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 6008 | } |
| 6009 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6010 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6011 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 6012 | struct drm_device *dev = old_state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6013 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6014 | struct intel_atomic_state *old_intel_state = |
| 6015 | to_intel_atomic_state(old_state); |
| 6016 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6017 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6018 | /* |
| 6019 | * FIXME: We can end up here with all power domains off, yet |
| 6020 | * with a CDCLK frequency other than the minimum. To account |
| 6021 | * for this take the PIPE-A power domain, which covers the HW |
| 6022 | * blocks needed for the following programming. This can be |
| 6023 | * removed once it's guaranteed that we get here either with |
| 6024 | * the minimum CDCLK set, or the required power domains |
| 6025 | * enabled. |
| 6026 | */ |
| 6027 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6028 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6029 | if (IS_CHERRYVIEW(dev)) |
| 6030 | cherryview_set_cdclk(dev, req_cdclk); |
| 6031 | else |
| 6032 | valleyview_set_cdclk(dev, req_cdclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6033 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6034 | vlv_program_pfi_credits(dev_priv); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 6035 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6036 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6037 | } |
| 6038 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6039 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 6040 | { |
| 6041 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6042 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6043 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6044 | struct intel_encoder *encoder; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6045 | struct intel_crtc_state *pipe_config = |
| 6046 | to_intel_crtc_state(crtc->state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6047 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6048 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6049 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6050 | return; |
| 6051 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6052 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6053 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6054 | |
| 6055 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6056 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6057 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6058 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 6059 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6060 | |
| 6061 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6062 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6063 | } |
| 6064 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6065 | i9xx_set_pipeconf(intel_crtc); |
| 6066 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6067 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6068 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6069 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6070 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6071 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6072 | if (encoder->pre_pll_enable) |
| 6073 | encoder->pre_pll_enable(encoder); |
| 6074 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 6075 | if (!intel_crtc->config->has_dsi_encoder) { |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6076 | if (IS_CHERRYVIEW(dev)) { |
| 6077 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6078 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6079 | } else { |
| 6080 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6081 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | c0b4c66 | 2015-07-08 23:45:52 +0300 | [diff] [blame] | 6082 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6083 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6084 | |
| 6085 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6086 | if (encoder->pre_enable) |
| 6087 | encoder->pre_enable(encoder); |
| 6088 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6089 | i9xx_pfit_enable(intel_crtc); |
| 6090 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6091 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6092 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 6093 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6094 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6095 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6096 | assert_vblank_disabled(crtc); |
| 6097 | drm_crtc_vblank_on(crtc); |
| 6098 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6099 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6100 | encoder->enable(encoder); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6101 | } |
| 6102 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6103 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 6104 | { |
| 6105 | struct drm_device *dev = crtc->base.dev; |
| 6106 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6107 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6108 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 6109 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6110 | } |
| 6111 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6112 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6113 | { |
| 6114 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6115 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6116 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6117 | struct intel_encoder *encoder; |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6118 | struct intel_crtc_state *pipe_config = |
| 6119 | to_intel_crtc_state(crtc->state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6120 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6121 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6122 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6123 | return; |
| 6124 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6125 | i9xx_set_pll_dividers(intel_crtc); |
| 6126 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6127 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6128 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6129 | |
| 6130 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6131 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6132 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6133 | i9xx_set_pipeconf(intel_crtc); |
| 6134 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6135 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6136 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6137 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6138 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6139 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 6140 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6141 | if (encoder->pre_enable) |
| 6142 | encoder->pre_enable(encoder); |
| 6143 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6144 | i9xx_enable_pll(intel_crtc); |
| 6145 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6146 | i9xx_pfit_enable(intel_crtc); |
| 6147 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6148 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6149 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 6150 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6151 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6152 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6153 | assert_vblank_disabled(crtc); |
| 6154 | drm_crtc_vblank_on(crtc); |
| 6155 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6156 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6157 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6158 | } |
| 6159 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6160 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6161 | { |
| 6162 | struct drm_device *dev = crtc->base.dev; |
| 6163 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6164 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6165 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6166 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6167 | |
| 6168 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6169 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6170 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6171 | I915_READ(PFIT_CONTROL)); |
| 6172 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6173 | } |
| 6174 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6175 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 6176 | { |
| 6177 | struct drm_device *dev = crtc->dev; |
| 6178 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6180 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6181 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6182 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6183 | /* |
| 6184 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6185 | * wait for planes to fully turn off before disabling the pipe. |
| 6186 | */ |
Ander Conselvan de Oliveira | 90e83e5 | 2016-03-22 10:11:24 +0200 | [diff] [blame] | 6187 | if (IS_GEN2(dev)) |
| 6188 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6189 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6190 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6191 | encoder->disable(encoder); |
| 6192 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6193 | drm_crtc_vblank_off(crtc); |
| 6194 | assert_vblank_disabled(crtc); |
| 6195 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6196 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6197 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6198 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6199 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6200 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6201 | if (encoder->post_disable) |
| 6202 | encoder->post_disable(encoder); |
| 6203 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 6204 | if (!intel_crtc->config->has_dsi_encoder) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6205 | if (IS_CHERRYVIEW(dev)) |
| 6206 | chv_disable_pll(dev_priv, pipe); |
| 6207 | else if (IS_VALLEYVIEW(dev)) |
| 6208 | vlv_disable_pll(dev_priv, pipe); |
| 6209 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6210 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6211 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6212 | |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6213 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 6214 | if (encoder->post_pll_disable) |
| 6215 | encoder->post_pll_disable(encoder); |
| 6216 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6217 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6218 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6219 | } |
| 6220 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6221 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6222 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6223 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6224 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6225 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6226 | enum intel_display_power_domain domain; |
| 6227 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6228 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6229 | if (!intel_crtc->active) |
| 6230 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6231 | |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6232 | if (to_intel_plane_state(crtc->primary->state)->visible) { |
Maarten Lankhorst | fc32b1f | 2015-10-19 17:09:23 +0200 | [diff] [blame] | 6233 | WARN_ON(intel_crtc->unpin_work); |
| 6234 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 6235 | intel_pre_disable_primary_noatomic(crtc); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6236 | |
| 6237 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); |
| 6238 | to_intel_plane_state(crtc->primary->state)->visible = false; |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6239 | } |
| 6240 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6241 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6242 | |
| 6243 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was enabled, now disabled\n", |
| 6244 | crtc->base.id); |
| 6245 | |
| 6246 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6247 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6248 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6249 | crtc->enabled = false; |
| 6250 | crtc->state->connector_mask = 0; |
| 6251 | crtc->state->encoder_mask = 0; |
| 6252 | |
| 6253 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6254 | encoder->base.crtc = NULL; |
| 6255 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6256 | intel_fbc_disable(intel_crtc); |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6257 | intel_update_watermarks(crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6258 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6259 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6260 | domains = intel_crtc->enabled_power_domains; |
| 6261 | for_each_power_domain(domain, domains) |
| 6262 | intel_display_power_put(dev_priv, domain); |
| 6263 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6264 | |
| 6265 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
| 6266 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6267 | } |
| 6268 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6269 | /* |
| 6270 | * turn all crtc's off, but do not adjust state |
| 6271 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6272 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6273 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6274 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6275 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6276 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6277 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6278 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6279 | state = drm_atomic_helper_suspend(dev); |
| 6280 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6281 | if (ret) |
| 6282 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6283 | else |
| 6284 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6285 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6286 | } |
| 6287 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6288 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6289 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6290 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6291 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6292 | drm_encoder_cleanup(encoder); |
| 6293 | kfree(intel_encoder); |
| 6294 | } |
| 6295 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6296 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6297 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 6298 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6299 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6300 | struct drm_crtc *crtc = connector->base.state->crtc; |
| 6301 | |
| 6302 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6303 | connector->base.base.id, |
| 6304 | connector->base.name); |
| 6305 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6306 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6307 | struct intel_encoder *encoder = connector->encoder; |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6308 | struct drm_connector_state *conn_state = connector->base.state; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6309 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6310 | I915_STATE_WARN(!crtc, |
| 6311 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6312 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6313 | if (!crtc) |
| 6314 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6315 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6316 | I915_STATE_WARN(!crtc->state->active, |
| 6317 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6318 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6319 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6320 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6321 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6322 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6323 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6324 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6325 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6326 | "attached encoder crtc differs from connector crtc\n"); |
| 6327 | } else { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6328 | I915_STATE_WARN(crtc && crtc->state->active, |
| 6329 | "attached crtc is active, but connector isn't\n"); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6330 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
| 6331 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6332 | } |
| 6333 | } |
| 6334 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6335 | int intel_connector_init(struct intel_connector *connector) |
| 6336 | { |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6337 | drm_atomic_helper_connector_reset(&connector->base); |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6338 | |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 6339 | if (!connector->base.state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6340 | return -ENOMEM; |
| 6341 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 6342 | return 0; |
| 6343 | } |
| 6344 | |
| 6345 | struct intel_connector *intel_connector_alloc(void) |
| 6346 | { |
| 6347 | struct intel_connector *connector; |
| 6348 | |
| 6349 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 6350 | if (!connector) |
| 6351 | return NULL; |
| 6352 | |
| 6353 | if (intel_connector_init(connector) < 0) { |
| 6354 | kfree(connector); |
| 6355 | return NULL; |
| 6356 | } |
| 6357 | |
| 6358 | return connector; |
| 6359 | } |
| 6360 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6361 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 6362 | * one connector and no cloning and hence the encoder state determines the state |
| 6363 | * of the connector. */ |
| 6364 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 6365 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 6366 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 6367 | struct intel_encoder *encoder = connector->encoder; |
| 6368 | |
| 6369 | return encoder->get_hw_state(encoder, &pipe); |
| 6370 | } |
| 6371 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6372 | 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] | 6373 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6374 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 6375 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 6376 | |
| 6377 | return 0; |
| 6378 | } |
| 6379 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6380 | 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] | 6381 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6382 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6383 | struct drm_atomic_state *state = pipe_config->base.state; |
| 6384 | struct intel_crtc *other_crtc; |
| 6385 | struct intel_crtc_state *other_crtc_state; |
| 6386 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6387 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 6388 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 6389 | if (pipe_config->fdi_lanes > 4) { |
| 6390 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 6391 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6392 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6393 | } |
| 6394 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 6395 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6396 | if (pipe_config->fdi_lanes > 2) { |
| 6397 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 6398 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6399 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6400 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6401 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6402 | } |
| 6403 | } |
| 6404 | |
| 6405 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6406 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6407 | |
| 6408 | /* Ivybridge 3 pipe is really complicated */ |
| 6409 | switch (pipe) { |
| 6410 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6411 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6412 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6413 | if (pipe_config->fdi_lanes <= 2) |
| 6414 | return 0; |
| 6415 | |
| 6416 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 6417 | other_crtc_state = |
| 6418 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6419 | if (IS_ERR(other_crtc_state)) |
| 6420 | return PTR_ERR(other_crtc_state); |
| 6421 | |
| 6422 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6423 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 6424 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6425 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6426 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6427 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6428 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6429 | if (pipe_config->fdi_lanes > 2) { |
| 6430 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 6431 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6432 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 6433 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6434 | |
| 6435 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 6436 | other_crtc_state = |
| 6437 | intel_atomic_get_crtc_state(state, other_crtc); |
| 6438 | if (IS_ERR(other_crtc_state)) |
| 6439 | return PTR_ERR(other_crtc_state); |
| 6440 | |
| 6441 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6442 | 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] | 6443 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6444 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6445 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6446 | default: |
| 6447 | BUG(); |
| 6448 | } |
| 6449 | } |
| 6450 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6451 | #define RETRY 1 |
| 6452 | 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] | 6453 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6454 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6455 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6456 | 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] | 6457 | int lane, link_bw, fdi_dotclock, ret; |
| 6458 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6459 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6460 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6461 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 6462 | * each output octet as 10 bits. The actual frequency |
| 6463 | * is stored as a divider into a 100MHz clock, and the |
| 6464 | * mode pixel clock is stored in units of 1KHz. |
| 6465 | * Hence the bw of each lane in terms of the mode signal |
| 6466 | * is: |
| 6467 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 6468 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6469 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 6470 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6471 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6472 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6473 | pipe_config->pipe_bpp); |
| 6474 | |
| 6475 | pipe_config->fdi_lanes = lane; |
| 6476 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 6477 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6478 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 6479 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 6480 | ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6481 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6482 | pipe_config->pipe_bpp -= 2*3; |
| 6483 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 6484 | pipe_config->pipe_bpp); |
| 6485 | needs_recompute = true; |
| 6486 | pipe_config->bw_constrained = true; |
| 6487 | |
| 6488 | goto retry; |
| 6489 | } |
| 6490 | |
| 6491 | if (needs_recompute) |
| 6492 | return RETRY; |
| 6493 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 6494 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6495 | } |
| 6496 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6497 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
| 6498 | struct intel_crtc_state *pipe_config) |
| 6499 | { |
| 6500 | if (pipe_config->pipe_bpp > 24) |
| 6501 | return false; |
| 6502 | |
| 6503 | /* HSW can handle pixel rate up to cdclk? */ |
| 6504 | if (IS_HASWELL(dev_priv->dev)) |
| 6505 | return true; |
| 6506 | |
| 6507 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 6508 | * We compare against max which means we must take |
| 6509 | * the increased cdclk requirement into account when |
| 6510 | * calculating the new cdclk. |
| 6511 | * |
| 6512 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6513 | */ |
| 6514 | return ilk_pipe_pixel_rate(pipe_config) <= |
| 6515 | dev_priv->max_cdclk_freq * 95 / 100; |
| 6516 | } |
| 6517 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6518 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6519 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6520 | { |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6521 | struct drm_device *dev = crtc->base.dev; |
| 6522 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6523 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6524 | pipe_config->ips_enabled = i915.enable_ips && |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 6525 | hsw_crtc_supports_ips(crtc) && |
| 6526 | pipe_config_supports_ips(dev_priv, pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6527 | } |
| 6528 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6529 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 6530 | { |
| 6531 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 6532 | |
| 6533 | /* GDG double wide on either pipe, otherwise pipe A only */ |
| 6534 | return INTEL_INFO(dev_priv)->gen < 4 && |
| 6535 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 6536 | } |
| 6537 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6538 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6539 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6540 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6541 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 6542 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 6543 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6544 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6545 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6546 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6547 | int clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6548 | |
| 6549 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6550 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6551 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6552 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6553 | if (intel_crtc_supports_double_wide(crtc) && |
| 6554 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6555 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6556 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 6557 | } |
| 6558 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6559 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 6560 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 6561 | adjusted_mode->crtc_clock, clock_limit, |
| 6562 | yesno(pipe_config->double_wide)); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6563 | return -EINVAL; |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 6564 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6565 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 6566 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6567 | /* |
| 6568 | * Pipe horizontal size must be even in: |
| 6569 | * - DVO ganged mode |
| 6570 | * - LVDS dual channel mode |
| 6571 | * - Double wide pipe |
| 6572 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6573 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 6574 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 6575 | pipe_config->pipe_src_w &= ~1; |
| 6576 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 6577 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 6578 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6579 | */ |
| 6580 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 6581 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 6582 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 6583 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 6584 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6585 | hsw_compute_ips_config(crtc, pipe_config); |
| 6586 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6587 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 6588 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 6589 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 6590 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6593 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 6594 | { |
| 6595 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6596 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 6597 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6598 | uint32_t linkrate; |
| 6599 | |
Damien Lespiau | 414355a | 2015-06-04 18:21:31 +0100 | [diff] [blame] | 6600 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6601 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6602 | |
| 6603 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 6604 | return 540000; |
| 6605 | |
| 6606 | linkrate = (I915_READ(DPLL_CTRL1) & |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6607 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6608 | |
Damien Lespiau | 71cd842 | 2015-04-30 16:39:17 +0100 | [diff] [blame] | 6609 | if (linkrate == DPLL_CTRL1_LINK_RATE_2160 || |
| 6610 | linkrate == DPLL_CTRL1_LINK_RATE_1080) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6611 | /* vco 8640 */ |
| 6612 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6613 | case CDCLK_FREQ_450_432: |
| 6614 | return 432000; |
| 6615 | case CDCLK_FREQ_337_308: |
| 6616 | return 308570; |
| 6617 | case CDCLK_FREQ_675_617: |
| 6618 | return 617140; |
| 6619 | default: |
| 6620 | WARN(1, "Unknown cd freq selection\n"); |
| 6621 | } |
| 6622 | } else { |
| 6623 | /* vco 8100 */ |
| 6624 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 6625 | case CDCLK_FREQ_450_432: |
| 6626 | return 450000; |
| 6627 | case CDCLK_FREQ_337_308: |
| 6628 | return 337500; |
| 6629 | case CDCLK_FREQ_675_617: |
| 6630 | return 675000; |
| 6631 | default: |
| 6632 | WARN(1, "Unknown cd freq selection\n"); |
| 6633 | } |
| 6634 | } |
| 6635 | |
| 6636 | /* error case, do as if DPLL0 isn't enabled */ |
| 6637 | return 24000; |
| 6638 | } |
| 6639 | |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 6640 | static int broxton_get_display_clock_speed(struct drm_device *dev) |
| 6641 | { |
| 6642 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 6643 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 6644 | uint32_t pll_ratio = I915_READ(BXT_DE_PLL_CTL) & BXT_DE_PLL_RATIO_MASK; |
| 6645 | uint32_t pll_enab = I915_READ(BXT_DE_PLL_ENABLE); |
| 6646 | int cdclk; |
| 6647 | |
| 6648 | if (!(pll_enab & BXT_DE_PLL_PLL_ENABLE)) |
| 6649 | return 19200; |
| 6650 | |
| 6651 | cdclk = 19200 * pll_ratio / 2; |
| 6652 | |
| 6653 | switch (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) { |
| 6654 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
| 6655 | return cdclk; /* 576MHz or 624MHz */ |
| 6656 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
| 6657 | return cdclk * 2 / 3; /* 384MHz */ |
| 6658 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
| 6659 | return cdclk / 2; /* 288MHz */ |
| 6660 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
| 6661 | return cdclk / 4; /* 144MHz */ |
| 6662 | } |
| 6663 | |
| 6664 | /* error case, do as if DE PLL isn't enabled */ |
| 6665 | return 19200; |
| 6666 | } |
| 6667 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 6668 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 6669 | { |
| 6670 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6671 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6672 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6673 | |
| 6674 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6675 | return 800000; |
| 6676 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6677 | return 450000; |
| 6678 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6679 | return 450000; |
| 6680 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6681 | return 540000; |
| 6682 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6683 | return 337500; |
| 6684 | else |
| 6685 | return 675000; |
| 6686 | } |
| 6687 | |
| 6688 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6689 | { |
| 6690 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6691 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6692 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6693 | |
| 6694 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6695 | return 800000; |
| 6696 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6697 | return 450000; |
| 6698 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6699 | return 450000; |
| 6700 | else if (IS_HSW_ULT(dev)) |
| 6701 | return 337500; |
| 6702 | else |
| 6703 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6704 | } |
| 6705 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6706 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6707 | { |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6708 | return vlv_get_cck_clock_hpll(to_i915(dev), "cdclk", |
| 6709 | CCK_DISPLAY_CLOCK_CONTROL); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6712 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6713 | { |
| 6714 | return 450000; |
| 6715 | } |
| 6716 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6717 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6718 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6719 | return 400000; |
| 6720 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6721 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6722 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 6723 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6724 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6725 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6726 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6727 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6728 | { |
| 6729 | return 200000; |
| 6730 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6731 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6732 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6733 | { |
| 6734 | u16 gcfgc = 0; |
| 6735 | |
| 6736 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6737 | |
| 6738 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6739 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6740 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6741 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6742 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6743 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6744 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6745 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6746 | return 200000; |
| 6747 | default: |
| 6748 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6749 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6750 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6751 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6752 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6753 | } |
| 6754 | } |
| 6755 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6756 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6757 | { |
| 6758 | u16 gcfgc = 0; |
| 6759 | |
| 6760 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6761 | |
| 6762 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6763 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6764 | else { |
| 6765 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6766 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6767 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6768 | default: |
| 6769 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6770 | return 190000; |
| 6771 | } |
| 6772 | } |
| 6773 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6774 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6775 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6776 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6777 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6778 | } |
| 6779 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6780 | static int i85x_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6781 | { |
| 6782 | u16 hpllcc = 0; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6783 | |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 6784 | /* |
| 6785 | * 852GM/852GMV only supports 133 MHz and the HPLLCC |
| 6786 | * encoding is different :( |
| 6787 | * FIXME is this the right way to detect 852GM/852GMV? |
| 6788 | */ |
| 6789 | if (dev->pdev->revision == 0x1) |
| 6790 | return 133333; |
| 6791 | |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6792 | pci_bus_read_config_word(dev->pdev->bus, |
| 6793 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); |
| 6794 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6795 | /* Assume that the hardware is in the high speed state. This |
| 6796 | * should be the default. |
| 6797 | */ |
| 6798 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6799 | case GC_CLOCK_133_200: |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6800 | case GC_CLOCK_133_200_2: |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6801 | case GC_CLOCK_100_200: |
| 6802 | return 200000; |
| 6803 | case GC_CLOCK_166_250: |
| 6804 | return 250000; |
| 6805 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6806 | return 133333; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 6807 | case GC_CLOCK_133_266: |
| 6808 | case GC_CLOCK_133_266_2: |
| 6809 | case GC_CLOCK_166_266: |
| 6810 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6811 | } |
| 6812 | |
| 6813 | /* Shouldn't happen */ |
| 6814 | return 0; |
| 6815 | } |
| 6816 | |
| 6817 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6818 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6819 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6820 | } |
| 6821 | |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6822 | static unsigned int intel_hpll_vco(struct drm_device *dev) |
| 6823 | { |
| 6824 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6825 | static const unsigned int blb_vco[8] = { |
| 6826 | [0] = 3200000, |
| 6827 | [1] = 4000000, |
| 6828 | [2] = 5333333, |
| 6829 | [3] = 4800000, |
| 6830 | [4] = 6400000, |
| 6831 | }; |
| 6832 | static const unsigned int pnv_vco[8] = { |
| 6833 | [0] = 3200000, |
| 6834 | [1] = 4000000, |
| 6835 | [2] = 5333333, |
| 6836 | [3] = 4800000, |
| 6837 | [4] = 2666667, |
| 6838 | }; |
| 6839 | static const unsigned int cl_vco[8] = { |
| 6840 | [0] = 3200000, |
| 6841 | [1] = 4000000, |
| 6842 | [2] = 5333333, |
| 6843 | [3] = 6400000, |
| 6844 | [4] = 3333333, |
| 6845 | [5] = 3566667, |
| 6846 | [6] = 4266667, |
| 6847 | }; |
| 6848 | static const unsigned int elk_vco[8] = { |
| 6849 | [0] = 3200000, |
| 6850 | [1] = 4000000, |
| 6851 | [2] = 5333333, |
| 6852 | [3] = 4800000, |
| 6853 | }; |
| 6854 | static const unsigned int ctg_vco[8] = { |
| 6855 | [0] = 3200000, |
| 6856 | [1] = 4000000, |
| 6857 | [2] = 5333333, |
| 6858 | [3] = 6400000, |
| 6859 | [4] = 2666667, |
| 6860 | [5] = 4266667, |
| 6861 | }; |
| 6862 | const unsigned int *vco_table; |
| 6863 | unsigned int vco; |
| 6864 | uint8_t tmp = 0; |
| 6865 | |
| 6866 | /* FIXME other chipsets? */ |
| 6867 | if (IS_GM45(dev)) |
| 6868 | vco_table = ctg_vco; |
| 6869 | else if (IS_G4X(dev)) |
| 6870 | vco_table = elk_vco; |
| 6871 | else if (IS_CRESTLINE(dev)) |
| 6872 | vco_table = cl_vco; |
| 6873 | else if (IS_PINEVIEW(dev)) |
| 6874 | vco_table = pnv_vco; |
| 6875 | else if (IS_G33(dev)) |
| 6876 | vco_table = blb_vco; |
| 6877 | else |
| 6878 | return 0; |
| 6879 | |
| 6880 | tmp = I915_READ(IS_MOBILE(dev) ? HPLLVCO_MOBILE : HPLLVCO); |
| 6881 | |
| 6882 | vco = vco_table[tmp & 0x7]; |
| 6883 | if (vco == 0) |
| 6884 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); |
| 6885 | else |
| 6886 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); |
| 6887 | |
| 6888 | return vco; |
| 6889 | } |
| 6890 | |
| 6891 | static int gm45_get_display_clock_speed(struct drm_device *dev) |
| 6892 | { |
| 6893 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6894 | uint16_t tmp = 0; |
| 6895 | |
| 6896 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6897 | |
| 6898 | cdclk_sel = (tmp >> 12) & 0x1; |
| 6899 | |
| 6900 | switch (vco) { |
| 6901 | case 2666667: |
| 6902 | case 4000000: |
| 6903 | case 5333333: |
| 6904 | return cdclk_sel ? 333333 : 222222; |
| 6905 | case 3200000: |
| 6906 | return cdclk_sel ? 320000 : 228571; |
| 6907 | default: |
| 6908 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); |
| 6909 | return 222222; |
| 6910 | } |
| 6911 | } |
| 6912 | |
| 6913 | static int i965gm_get_display_clock_speed(struct drm_device *dev) |
| 6914 | { |
| 6915 | static const uint8_t div_3200[] = { 16, 10, 8 }; |
| 6916 | static const uint8_t div_4000[] = { 20, 12, 10 }; |
| 6917 | static const uint8_t div_5333[] = { 24, 16, 14 }; |
| 6918 | const uint8_t *div_table; |
| 6919 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6920 | uint16_t tmp = 0; |
| 6921 | |
| 6922 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6923 | |
| 6924 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; |
| 6925 | |
| 6926 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6927 | goto fail; |
| 6928 | |
| 6929 | switch (vco) { |
| 6930 | case 3200000: |
| 6931 | div_table = div_3200; |
| 6932 | break; |
| 6933 | case 4000000: |
| 6934 | div_table = div_4000; |
| 6935 | break; |
| 6936 | case 5333333: |
| 6937 | div_table = div_5333; |
| 6938 | break; |
| 6939 | default: |
| 6940 | goto fail; |
| 6941 | } |
| 6942 | |
| 6943 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6944 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6945 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6946 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
| 6947 | return 200000; |
| 6948 | } |
| 6949 | |
| 6950 | static int g33_get_display_clock_speed(struct drm_device *dev) |
| 6951 | { |
| 6952 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; |
| 6953 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; |
| 6954 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; |
| 6955 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; |
| 6956 | const uint8_t *div_table; |
| 6957 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev); |
| 6958 | uint16_t tmp = 0; |
| 6959 | |
| 6960 | pci_read_config_word(dev->pdev, GCFGC, &tmp); |
| 6961 | |
| 6962 | cdclk_sel = (tmp >> 4) & 0x7; |
| 6963 | |
| 6964 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 6965 | goto fail; |
| 6966 | |
| 6967 | switch (vco) { |
| 6968 | case 3200000: |
| 6969 | div_table = div_3200; |
| 6970 | break; |
| 6971 | case 4000000: |
| 6972 | div_table = div_4000; |
| 6973 | break; |
| 6974 | case 4800000: |
| 6975 | div_table = div_4800; |
| 6976 | break; |
| 6977 | case 5333333: |
| 6978 | div_table = div_5333; |
| 6979 | break; |
| 6980 | default: |
| 6981 | goto fail; |
| 6982 | } |
| 6983 | |
| 6984 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 6985 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 6986 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 6987 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
| 6988 | return 190476; |
| 6989 | } |
| 6990 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6991 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6992 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6993 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6994 | while (*num > DATA_LINK_M_N_MASK || |
| 6995 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6996 | *num >>= 1; |
| 6997 | *den >>= 1; |
| 6998 | } |
| 6999 | } |
| 7000 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7001 | static void compute_m_n(unsigned int m, unsigned int n, |
| 7002 | uint32_t *ret_m, uint32_t *ret_n) |
| 7003 | { |
| 7004 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 7005 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 7006 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 7007 | } |
| 7008 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7009 | void |
| 7010 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 7011 | int pixel_clock, int link_clock, |
| 7012 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7013 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7014 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7015 | |
| 7016 | compute_m_n(bits_per_pixel * pixel_clock, |
| 7017 | link_clock * nlanes * 8, |
| 7018 | &m_n->gmch_m, &m_n->gmch_n); |
| 7019 | |
| 7020 | compute_m_n(pixel_clock, link_clock, |
| 7021 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7022 | } |
| 7023 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7024 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 7025 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7026 | if (i915.panel_use_ssc >= 0) |
| 7027 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7028 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 7029 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7030 | } |
| 7031 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7032 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7033 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 7034 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7035 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7036 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7037 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 7038 | { |
| 7039 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7040 | } |
| 7041 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7042 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7043 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7044 | intel_clock_t *reduced_clock) |
| 7045 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7046 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7047 | u32 fp, fp2 = 0; |
| 7048 | |
| 7049 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7050 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7051 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7052 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7053 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7054 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7055 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7056 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7057 | } |
| 7058 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7059 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7060 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7061 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7062 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7063 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7064 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7065 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7066 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7067 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7068 | } |
| 7069 | } |
| 7070 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7071 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 7072 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7073 | { |
| 7074 | u32 reg_val; |
| 7075 | |
| 7076 | /* |
| 7077 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 7078 | * and set it to a reasonable value instead. |
| 7079 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7080 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7081 | reg_val &= 0xffffff00; |
| 7082 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7083 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7084 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7085 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7086 | reg_val &= 0x8cffffff; |
| 7087 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7088 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7089 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7090 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7091 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7092 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7093 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7094 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7095 | reg_val &= 0x00ffffff; |
| 7096 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7097 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7098 | } |
| 7099 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7100 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 7101 | struct intel_link_m_n *m_n) |
| 7102 | { |
| 7103 | struct drm_device *dev = crtc->base.dev; |
| 7104 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7105 | int pipe = crtc->pipe; |
| 7106 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7107 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7108 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7109 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7110 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7111 | } |
| 7112 | |
| 7113 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7114 | struct intel_link_m_n *m_n, |
| 7115 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7116 | { |
| 7117 | struct drm_device *dev = crtc->base.dev; |
| 7118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7119 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7120 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7121 | |
| 7122 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7123 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7124 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7125 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7126 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7127 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 7128 | * for gen < 8) and if DRRS is supported (to make sure the |
| 7129 | * registers are not unnecessarily accessed). |
| 7130 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 7131 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7132 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7133 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7134 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7135 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7136 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7137 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7138 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7139 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7140 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7141 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7142 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7143 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7144 | } |
| 7145 | } |
| 7146 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7147 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7148 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7149 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 7150 | |
| 7151 | if (m_n == M1_N1) { |
| 7152 | dp_m_n = &crtc->config->dp_m_n; |
| 7153 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 7154 | } else if (m_n == M2_N2) { |
| 7155 | |
| 7156 | /* |
| 7157 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7158 | * needs to be programmed into M1_N1. |
| 7159 | */ |
| 7160 | dp_m_n = &crtc->config->dp_m2_n2; |
| 7161 | } else { |
| 7162 | DRM_ERROR("Unsupported divider value\n"); |
| 7163 | return; |
| 7164 | } |
| 7165 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7166 | if (crtc->config->has_pch_encoder) |
| 7167 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7168 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7169 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7170 | } |
| 7171 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7172 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7173 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7174 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7175 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
| 7176 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 7177 | DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 7178 | if (crtc->pipe != PIPE_A) |
| 7179 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7180 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7181 | pipe_config->dpll_hw_state.dpll_md = |
| 7182 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 7183 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7184 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7185 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7186 | struct intel_crtc_state *pipe_config) |
| 7187 | { |
| 7188 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
| 7189 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 7190 | DPLL_VCO_ENABLE; |
| 7191 | if (crtc->pipe != PIPE_A) |
| 7192 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7193 | |
| 7194 | pipe_config->dpll_hw_state.dpll_md = |
| 7195 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7196 | } |
| 7197 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7198 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7199 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7200 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7201 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7202 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7203 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7204 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7205 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7206 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7207 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7208 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7209 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7210 | bestn = pipe_config->dpll.n; |
| 7211 | bestm1 = pipe_config->dpll.m1; |
| 7212 | bestm2 = pipe_config->dpll.m2; |
| 7213 | bestp1 = pipe_config->dpll.p1; |
| 7214 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7215 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7216 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7217 | |
| 7218 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7219 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7220 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7221 | |
| 7222 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7223 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7224 | |
| 7225 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7226 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7227 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7228 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7229 | |
| 7230 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7231 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7232 | |
| 7233 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7234 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7235 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7236 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7237 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7238 | |
| 7239 | /* |
| 7240 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7241 | * but we don't support that). |
| 7242 | * Note: don't use the DAC post divider as it seems unstable. |
| 7243 | */ |
| 7244 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7245 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7246 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7247 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7248 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7249 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7250 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7251 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7252 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 7253 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7254 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7255 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7256 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7257 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7258 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7259 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7260 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7261 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7262 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7263 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7264 | 0x0df40000); |
| 7265 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7266 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7267 | 0x0df70000); |
| 7268 | } else { /* HDMI or VGA */ |
| 7269 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7270 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7271 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7272 | 0x0df70000); |
| 7273 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7274 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7275 | 0x0df40000); |
| 7276 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7277 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7278 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7279 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7280 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 7281 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7282 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7283 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7284 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7285 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7286 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7287 | } |
| 7288 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7289 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7290 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7291 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7292 | struct drm_device *dev = crtc->base.dev; |
| 7293 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7294 | int pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 7295 | i915_reg_t dpll_reg = DPLL(crtc->pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7296 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7297 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7298 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7299 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7300 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7301 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7302 | bestn = pipe_config->dpll.n; |
| 7303 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 7304 | bestm1 = pipe_config->dpll.m1; |
| 7305 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 7306 | bestp1 = pipe_config->dpll.p1; |
| 7307 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7308 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7309 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7310 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7311 | |
| 7312 | /* |
| 7313 | * Enable Refclk and SSC |
| 7314 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7315 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7316 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 7317 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7318 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7319 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7320 | /* p1 and p2 divider */ |
| 7321 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 7322 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 7323 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 7324 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 7325 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 7326 | |
| 7327 | /* Feedback post-divider - m2 */ |
| 7328 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 7329 | |
| 7330 | /* Feedback refclk divider - n and m1 */ |
| 7331 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 7332 | DPIO_CHV_M1_DIV_BY_2 | |
| 7333 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 7334 | |
| 7335 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 7336 | 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] | 7337 | |
| 7338 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 7339 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 7340 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 7341 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 7342 | if (bestm2_frac) |
| 7343 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 7344 | 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] | 7345 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 7346 | /* Program digital lock detect threshold */ |
| 7347 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 7348 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 7349 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 7350 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 7351 | if (!bestm2_frac) |
| 7352 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 7353 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 7354 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7355 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7356 | if (vco == 5400000) { |
| 7357 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7358 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7359 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7360 | tribuf_calcntr = 0x9; |
| 7361 | } else if (vco <= 6200000) { |
| 7362 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7363 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 7364 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7365 | tribuf_calcntr = 0x9; |
| 7366 | } else if (vco <= 6480000) { |
| 7367 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7368 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7369 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7370 | tribuf_calcntr = 0x8; |
| 7371 | } else { |
| 7372 | /* Not supported. Apply the same limits as in the max case */ |
| 7373 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 7374 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 7375 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 7376 | tribuf_calcntr = 0; |
| 7377 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7378 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 7379 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 7380 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 7381 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 7382 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 7383 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 7384 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7385 | /* AFC Recal */ |
| 7386 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 7387 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 7388 | DPIO_AFC_RECAL); |
| 7389 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7390 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7391 | } |
| 7392 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7393 | /** |
| 7394 | * vlv_force_pll_on - forcibly enable just the PLL |
| 7395 | * @dev_priv: i915 private structure |
| 7396 | * @pipe: pipe PLL to enable |
| 7397 | * @dpll: PLL configuration |
| 7398 | * |
| 7399 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 7400 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 7401 | * be enabled. |
| 7402 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7403 | int vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 7404 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7405 | { |
| 7406 | struct intel_crtc *crtc = |
| 7407 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7408 | struct intel_crtc_state *pipe_config; |
| 7409 | |
| 7410 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7411 | if (!pipe_config) |
| 7412 | return -ENOMEM; |
| 7413 | |
| 7414 | pipe_config->base.crtc = &crtc->base; |
| 7415 | pipe_config->pixel_multiplier = 1; |
| 7416 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7417 | |
| 7418 | if (IS_CHERRYVIEW(dev)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7419 | chv_compute_dpll(crtc, pipe_config); |
| 7420 | chv_prepare_pll(crtc, pipe_config); |
| 7421 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7422 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7423 | vlv_compute_dpll(crtc, pipe_config); |
| 7424 | vlv_prepare_pll(crtc, pipe_config); |
| 7425 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7426 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 7427 | |
| 7428 | kfree(pipe_config); |
| 7429 | |
| 7430 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7431 | } |
| 7432 | |
| 7433 | /** |
| 7434 | * vlv_force_pll_off - forcibly disable just the PLL |
| 7435 | * @dev_priv: i915 private structure |
| 7436 | * @pipe: pipe PLL to disable |
| 7437 | * |
| 7438 | * Disable the PLL for @pipe. To be used in cases where we need |
| 7439 | * the PLL enabled even when @pipe is not going to be enabled. |
| 7440 | */ |
| 7441 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 7442 | { |
| 7443 | if (IS_CHERRYVIEW(dev)) |
| 7444 | chv_disable_pll(to_i915(dev), pipe); |
| 7445 | else |
| 7446 | vlv_disable_pll(to_i915(dev), pipe); |
| 7447 | } |
| 7448 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7449 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 7450 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7451 | intel_clock_t *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7452 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7453 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7454 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7455 | u32 dpll; |
| 7456 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7457 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7458 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7459 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7460 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7461 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 7462 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7463 | |
| 7464 | dpll = DPLL_VGA_MODE_DIS; |
| 7465 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7466 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7467 | dpll |= DPLLB_MODE_LVDS; |
| 7468 | else |
| 7469 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7470 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7471 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7472 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7473 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7474 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7475 | |
| 7476 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7477 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7478 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7479 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7480 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7481 | |
| 7482 | /* compute bitmask from p1 value */ |
| 7483 | if (IS_PINEVIEW(dev)) |
| 7484 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 7485 | else { |
| 7486 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7487 | if (IS_G4X(dev) && reduced_clock) |
| 7488 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 7489 | } |
| 7490 | switch (clock->p2) { |
| 7491 | case 5: |
| 7492 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7493 | break; |
| 7494 | case 7: |
| 7495 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7496 | break; |
| 7497 | case 10: |
| 7498 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7499 | break; |
| 7500 | case 14: |
| 7501 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7502 | break; |
| 7503 | } |
| 7504 | if (INTEL_INFO(dev)->gen >= 4) |
| 7505 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 7506 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7507 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7508 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7509 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7510 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7511 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7512 | else |
| 7513 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7514 | |
| 7515 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7516 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7517 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7518 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7519 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7520 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7521 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7522 | } |
| 7523 | } |
| 7524 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7525 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 7526 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7527 | intel_clock_t *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7528 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7529 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7531 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7532 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7533 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7534 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7535 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7536 | dpll = DPLL_VGA_MODE_DIS; |
| 7537 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7538 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7539 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7540 | } else { |
| 7541 | if (clock->p1 == 2) |
| 7542 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 7543 | else |
| 7544 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 7545 | if (clock->p2 == 4) |
| 7546 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 7547 | } |
| 7548 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7549 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7550 | dpll |= DPLL_DVO_2X_MODE; |
| 7551 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7552 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 7553 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7554 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 7555 | else |
| 7556 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7557 | |
| 7558 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7559 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7560 | } |
| 7561 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 7562 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7563 | { |
| 7564 | struct drm_device *dev = intel_crtc->base.dev; |
| 7565 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7566 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7567 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7568 | const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7569 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 7570 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7571 | |
| 7572 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 7573 | * the hw state checker will get angry at the mismatch. */ |
| 7574 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 7575 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7576 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7577 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7578 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7579 | crtc_vtotal -= 1; |
| 7580 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7581 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7582 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 7583 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 7584 | else |
| 7585 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 7586 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 7587 | if (vsyncshift < 0) |
| 7588 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7589 | } |
| 7590 | |
| 7591 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7592 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7593 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7594 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7595 | (adjusted_mode->crtc_hdisplay - 1) | |
| 7596 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7597 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7598 | (adjusted_mode->crtc_hblank_start - 1) | |
| 7599 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7600 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7601 | (adjusted_mode->crtc_hsync_start - 1) | |
| 7602 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 7603 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7604 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7605 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7606 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7607 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7608 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 7609 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7610 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7611 | (adjusted_mode->crtc_vsync_start - 1) | |
| 7612 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 7613 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 7614 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 7615 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 7616 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 7617 | * bits. */ |
| 7618 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 7619 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 7620 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 7621 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7622 | } |
| 7623 | |
| 7624 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) |
| 7625 | { |
| 7626 | struct drm_device *dev = intel_crtc->base.dev; |
| 7627 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7628 | enum pipe pipe = intel_crtc->pipe; |
| 7629 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7630 | /* pipesrc controls the size that is scaled from, which should |
| 7631 | * always be the user's requested size. |
| 7632 | */ |
| 7633 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7634 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 7635 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 7636 | } |
| 7637 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7638 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7639 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7640 | { |
| 7641 | struct drm_device *dev = crtc->base.dev; |
| 7642 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7643 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 7644 | uint32_t tmp; |
| 7645 | |
| 7646 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7647 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 7648 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7649 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7650 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 7651 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7652 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7653 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 7654 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7655 | |
| 7656 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7657 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 7658 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7659 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7660 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 7661 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7662 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7663 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 7664 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7665 | |
| 7666 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7667 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 7668 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 7669 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7670 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 7671 | } |
| 7672 | |
| 7673 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 7674 | struct intel_crtc_state *pipe_config) |
| 7675 | { |
| 7676 | struct drm_device *dev = crtc->base.dev; |
| 7677 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7678 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7679 | |
| 7680 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 7681 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 7682 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 7683 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7684 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 7685 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7686 | } |
| 7687 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 7688 | 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] | 7689 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7690 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7691 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 7692 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 7693 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 7694 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7695 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7696 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 7697 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 7698 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 7699 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7700 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7701 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7702 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7703 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 7704 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 7705 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 7706 | |
| 7707 | mode->hsync = drm_mode_hsync(mode); |
| 7708 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 7709 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 7710 | } |
| 7711 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7712 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 7713 | { |
| 7714 | struct drm_device *dev = intel_crtc->base.dev; |
| 7715 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7716 | uint32_t pipeconf; |
| 7717 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7718 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7719 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 7720 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 7721 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 7722 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 7723 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7724 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7725 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7726 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7727 | /* only g4x and later have fancy bpc/dither controls */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7728 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7729 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7730 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7731 | pipeconf |= PIPECONF_DITHER_EN | |
| 7732 | PIPECONF_DITHER_TYPE_SP; |
| 7733 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7734 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 7735 | case 18: |
| 7736 | pipeconf |= PIPECONF_6BPC; |
| 7737 | break; |
| 7738 | case 24: |
| 7739 | pipeconf |= PIPECONF_8BPC; |
| 7740 | break; |
| 7741 | case 30: |
| 7742 | pipeconf |= PIPECONF_10BPC; |
| 7743 | break; |
| 7744 | default: |
| 7745 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7746 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7747 | } |
| 7748 | } |
| 7749 | |
| 7750 | if (HAS_PIPE_CXSR(dev)) { |
| 7751 | if (intel_crtc->lowfreq_avail) { |
| 7752 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 7753 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 7754 | } else { |
| 7755 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7756 | } |
| 7757 | } |
| 7758 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7759 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7760 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7761 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 7762 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 7763 | else |
| 7764 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 7765 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7766 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 7767 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 7768 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 7769 | intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 7770 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 7771 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 7772 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 7773 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 7774 | } |
| 7775 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7776 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7777 | struct intel_crtc_state *crtc_state) |
| 7778 | { |
| 7779 | struct drm_device *dev = crtc->base.dev; |
| 7780 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7781 | const intel_limit_t *limit; |
| 7782 | int refclk = 48000; |
| 7783 | |
| 7784 | memset(&crtc_state->dpll_hw_state, 0, |
| 7785 | sizeof(crtc_state->dpll_hw_state)); |
| 7786 | |
| 7787 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7788 | if (intel_panel_use_ssc(dev_priv)) { |
| 7789 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7790 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7791 | } |
| 7792 | |
| 7793 | limit = &intel_limits_i8xx_lvds; |
| 7794 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) { |
| 7795 | limit = &intel_limits_i8xx_dvo; |
| 7796 | } else { |
| 7797 | limit = &intel_limits_i8xx_dac; |
| 7798 | } |
| 7799 | |
| 7800 | if (!crtc_state->clock_set && |
| 7801 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7802 | refclk, NULL, &crtc_state->dpll)) { |
| 7803 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7804 | return -EINVAL; |
| 7805 | } |
| 7806 | |
| 7807 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 7808 | |
| 7809 | return 0; |
| 7810 | } |
| 7811 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 7812 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 7813 | struct intel_crtc_state *crtc_state) |
| 7814 | { |
| 7815 | struct drm_device *dev = crtc->base.dev; |
| 7816 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7817 | const intel_limit_t *limit; |
| 7818 | int refclk = 96000; |
| 7819 | |
| 7820 | memset(&crtc_state->dpll_hw_state, 0, |
| 7821 | sizeof(crtc_state->dpll_hw_state)); |
| 7822 | |
| 7823 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7824 | if (intel_panel_use_ssc(dev_priv)) { |
| 7825 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7826 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7827 | } |
| 7828 | |
| 7829 | if (intel_is_dual_link_lvds(dev)) |
| 7830 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 7831 | else |
| 7832 | limit = &intel_limits_g4x_single_channel_lvds; |
| 7833 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 7834 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
| 7835 | limit = &intel_limits_g4x_hdmi; |
| 7836 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
| 7837 | limit = &intel_limits_g4x_sdvo; |
| 7838 | } else { |
| 7839 | /* The option is for other outputs */ |
| 7840 | limit = &intel_limits_i9xx_sdvo; |
| 7841 | } |
| 7842 | |
| 7843 | if (!crtc_state->clock_set && |
| 7844 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7845 | refclk, NULL, &crtc_state->dpll)) { |
| 7846 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7847 | return -EINVAL; |
| 7848 | } |
| 7849 | |
| 7850 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7851 | |
| 7852 | return 0; |
| 7853 | } |
| 7854 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7855 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7856 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7857 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7858 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7859 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 7860 | const intel_limit_t *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7861 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7862 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 7863 | memset(&crtc_state->dpll_hw_state, 0, |
| 7864 | sizeof(crtc_state->dpll_hw_state)); |
| 7865 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7866 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7867 | if (intel_panel_use_ssc(dev_priv)) { |
| 7868 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7869 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 7870 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7871 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7872 | limit = &intel_limits_pineview_lvds; |
| 7873 | } else { |
| 7874 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7875 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7876 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7877 | if (!crtc_state->clock_set && |
| 7878 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7879 | refclk, NULL, &crtc_state->dpll)) { |
| 7880 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7881 | return -EINVAL; |
| 7882 | } |
| 7883 | |
| 7884 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 7885 | |
| 7886 | return 0; |
| 7887 | } |
| 7888 | |
| 7889 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 7890 | struct intel_crtc_state *crtc_state) |
| 7891 | { |
| 7892 | struct drm_device *dev = crtc->base.dev; |
| 7893 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7894 | const intel_limit_t *limit; |
| 7895 | int refclk = 96000; |
| 7896 | |
| 7897 | memset(&crtc_state->dpll_hw_state, 0, |
| 7898 | sizeof(crtc_state->dpll_hw_state)); |
| 7899 | |
| 7900 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 7901 | if (intel_panel_use_ssc(dev_priv)) { |
| 7902 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 7903 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7904 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 7905 | |
| 7906 | limit = &intel_limits_i9xx_lvds; |
| 7907 | } else { |
| 7908 | limit = &intel_limits_i9xx_sdvo; |
| 7909 | } |
| 7910 | |
| 7911 | if (!crtc_state->clock_set && |
| 7912 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7913 | refclk, NULL, &crtc_state->dpll)) { |
| 7914 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7915 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7916 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7917 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 7918 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7919 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7920 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7921 | } |
| 7922 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 7923 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7924 | struct intel_crtc_state *crtc_state) |
| 7925 | { |
| 7926 | int refclk = 100000; |
| 7927 | const intel_limit_t *limit = &intel_limits_chv; |
| 7928 | |
| 7929 | memset(&crtc_state->dpll_hw_state, 0, |
| 7930 | sizeof(crtc_state->dpll_hw_state)); |
| 7931 | |
| 7932 | if (crtc_state->has_dsi_encoder) |
| 7933 | return 0; |
| 7934 | |
| 7935 | if (!crtc_state->clock_set && |
| 7936 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7937 | refclk, NULL, &crtc_state->dpll)) { |
| 7938 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7939 | return -EINVAL; |
| 7940 | } |
| 7941 | |
| 7942 | chv_compute_dpll(crtc, crtc_state); |
| 7943 | |
| 7944 | return 0; |
| 7945 | } |
| 7946 | |
| 7947 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 7948 | struct intel_crtc_state *crtc_state) |
| 7949 | { |
| 7950 | int refclk = 100000; |
| 7951 | const intel_limit_t *limit = &intel_limits_vlv; |
| 7952 | |
| 7953 | memset(&crtc_state->dpll_hw_state, 0, |
| 7954 | sizeof(crtc_state->dpll_hw_state)); |
| 7955 | |
| 7956 | if (crtc_state->has_dsi_encoder) |
| 7957 | return 0; |
| 7958 | |
| 7959 | if (!crtc_state->clock_set && |
| 7960 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 7961 | refclk, NULL, &crtc_state->dpll)) { |
| 7962 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7963 | return -EINVAL; |
| 7964 | } |
| 7965 | |
| 7966 | vlv_compute_dpll(crtc, crtc_state); |
| 7967 | |
| 7968 | return 0; |
| 7969 | } |
| 7970 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7971 | static void i9xx_get_pfit_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 | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7973 | { |
| 7974 | struct drm_device *dev = crtc->base.dev; |
| 7975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7976 | uint32_t tmp; |
| 7977 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7978 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 7979 | return; |
| 7980 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7981 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7982 | if (!(tmp & PFIT_ENABLE)) |
| 7983 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7984 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7985 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7986 | if (INTEL_INFO(dev)->gen < 4) { |
| 7987 | if (crtc->pipe != PIPE_B) |
| 7988 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7989 | } else { |
| 7990 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7991 | return; |
| 7992 | } |
| 7993 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7994 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7995 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 7996 | if (INTEL_INFO(dev)->gen < 5) |
| 7997 | pipe_config->gmch_pfit.lvds_border_bits = |
| 7998 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 7999 | } |
| 8000 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8001 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8002 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8003 | { |
| 8004 | struct drm_device *dev = crtc->base.dev; |
| 8005 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8006 | int pipe = pipe_config->cpu_transcoder; |
| 8007 | intel_clock_t clock; |
| 8008 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 8009 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8010 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 8011 | /* In case of MIPI DPLL will not even be used */ |
| 8012 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 8013 | return; |
| 8014 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8015 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 8016 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8017 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8018 | |
| 8019 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 8020 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 8021 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 8022 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 8023 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 8024 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8025 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8026 | } |
| 8027 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8028 | static void |
| 8029 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 8030 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8031 | { |
| 8032 | struct drm_device *dev = crtc->base.dev; |
| 8033 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8034 | u32 val, base, offset; |
| 8035 | int pipe = crtc->pipe, plane = crtc->plane; |
| 8036 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8037 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8038 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8039 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8040 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8041 | val = I915_READ(DSPCNTR(plane)); |
| 8042 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8043 | return; |
| 8044 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8045 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8046 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8047 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8048 | return; |
| 8049 | } |
| 8050 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8051 | fb = &intel_fb->base; |
| 8052 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8053 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8054 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8055 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8056 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8057 | } |
| 8058 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8059 | |
| 8060 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8061 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8062 | fb->pixel_format = fourcc; |
| 8063 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8064 | |
| 8065 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8066 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8067 | offset = I915_READ(DSPTILEOFF(plane)); |
| 8068 | else |
| 8069 | offset = I915_READ(DSPLINOFF(plane)); |
| 8070 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 8071 | } else { |
| 8072 | base = I915_READ(DSPADDR(plane)); |
| 8073 | } |
| 8074 | plane_config->base = base; |
| 8075 | |
| 8076 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8077 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8078 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8079 | |
| 8080 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8081 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8082 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8083 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8084 | fb->pixel_format, |
| 8085 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8086 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8087 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8088 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8089 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8090 | pipe_name(pipe), plane, fb->width, fb->height, |
| 8091 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8092 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8093 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8094 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8095 | } |
| 8096 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8097 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8098 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8099 | { |
| 8100 | struct drm_device *dev = crtc->base.dev; |
| 8101 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8102 | int pipe = pipe_config->cpu_transcoder; |
| 8103 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 8104 | intel_clock_t clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8105 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8106 | int refclk = 100000; |
| 8107 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8108 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8109 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8110 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8111 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8112 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8113 | 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] | 8114 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8115 | |
| 8116 | 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] | 8117 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8118 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8119 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8120 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8121 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8122 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8123 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8124 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8125 | } |
| 8126 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8127 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8128 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8129 | { |
| 8130 | struct drm_device *dev = crtc->base.dev; |
| 8131 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8132 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8133 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8134 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8135 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8136 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8137 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8138 | return false; |
| 8139 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8140 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8141 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8142 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8143 | ret = false; |
| 8144 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8145 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8146 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8147 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8148 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8149 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8150 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8151 | case PIPECONF_6BPC: |
| 8152 | pipe_config->pipe_bpp = 18; |
| 8153 | break; |
| 8154 | case PIPECONF_8BPC: |
| 8155 | pipe_config->pipe_bpp = 24; |
| 8156 | break; |
| 8157 | case PIPECONF_10BPC: |
| 8158 | pipe_config->pipe_bpp = 30; |
| 8159 | break; |
| 8160 | default: |
| 8161 | break; |
| 8162 | } |
| 8163 | } |
| 8164 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8165 | if ((IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) && |
| 8166 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8167 | pipe_config->limited_color_range = true; |
| 8168 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8169 | if (INTEL_INFO(dev)->gen < 4) |
| 8170 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8171 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8172 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8173 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8174 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8175 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8176 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8177 | if (INTEL_INFO(dev)->gen >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8178 | /* No way to read it out on pipes B and C */ |
| 8179 | if (IS_CHERRYVIEW(dev) && crtc->pipe != PIPE_A) |
| 8180 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8181 | else |
| 8182 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8183 | pipe_config->pixel_multiplier = |
| 8184 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8185 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8186 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8187 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 8188 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8189 | pipe_config->pixel_multiplier = |
| 8190 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8191 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8192 | } else { |
| 8193 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8194 | * port and will be fixed up in the encoder->get_config |
| 8195 | * function. */ |
| 8196 | pipe_config->pixel_multiplier = 1; |
| 8197 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8198 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8199 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8200 | /* |
| 8201 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8202 | * on 830. Filter it out here so that we don't |
| 8203 | * report errors due to that. |
| 8204 | */ |
| 8205 | if (IS_I830(dev)) |
| 8206 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8207 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8208 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8209 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8210 | } else { |
| 8211 | /* Mask out read-only status bits. */ |
| 8212 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8213 | DPLL_PORTC_READY_MASK | |
| 8214 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8215 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8216 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8217 | if (IS_CHERRYVIEW(dev)) |
| 8218 | chv_crtc_clock_get(crtc, pipe_config); |
| 8219 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8220 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8221 | else |
| 8222 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8223 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8224 | /* |
| 8225 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8226 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8227 | * default. |
| 8228 | */ |
| 8229 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8230 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8231 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8232 | ret = true; |
| 8233 | |
| 8234 | out: |
| 8235 | intel_display_power_put(dev_priv, power_domain); |
| 8236 | |
| 8237 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8238 | } |
| 8239 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8240 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8241 | { |
| 8242 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8243 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8244 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8245 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8246 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8247 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8248 | bool has_ck505 = false; |
| 8249 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8250 | |
| 8251 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8252 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8253 | switch (encoder->type) { |
| 8254 | case INTEL_OUTPUT_LVDS: |
| 8255 | has_panel = true; |
| 8256 | has_lvds = true; |
| 8257 | break; |
| 8258 | case INTEL_OUTPUT_EDP: |
| 8259 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8260 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8261 | has_cpu_edp = true; |
| 8262 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8263 | default: |
| 8264 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8265 | } |
| 8266 | } |
| 8267 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8268 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8269 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8270 | can_ssc = has_ck505; |
| 8271 | } else { |
| 8272 | has_ck505 = false; |
| 8273 | can_ssc = true; |
| 8274 | } |
| 8275 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8276 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 8277 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8278 | |
| 8279 | /* Ironlake: try to setup display ref clock before DPLL |
| 8280 | * enabling. This is only under driver's control after |
| 8281 | * PCH B stepping, previous chipset stepping should be |
| 8282 | * ignoring this setting. |
| 8283 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8284 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8285 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8286 | /* As we must carefully and slowly disable/enable each source in turn, |
| 8287 | * compute the final state we want first and check if we need to |
| 8288 | * make any changes at all. |
| 8289 | */ |
| 8290 | final = val; |
| 8291 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8292 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8293 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8294 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8295 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8296 | |
| 8297 | final &= ~DREF_SSC_SOURCE_MASK; |
| 8298 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 8299 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8300 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8301 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8302 | final |= DREF_SSC_SOURCE_ENABLE; |
| 8303 | |
| 8304 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8305 | final |= DREF_SSC1_ENABLE; |
| 8306 | |
| 8307 | if (has_cpu_edp) { |
| 8308 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 8309 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 8310 | else |
| 8311 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 8312 | } else |
| 8313 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8314 | } else { |
| 8315 | final |= DREF_SSC_SOURCE_DISABLE; |
| 8316 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 8317 | } |
| 8318 | |
| 8319 | if (final == val) |
| 8320 | return; |
| 8321 | |
| 8322 | /* Always enable nonspread source */ |
| 8323 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 8324 | |
| 8325 | if (has_ck505) |
| 8326 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 8327 | else |
| 8328 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 8329 | |
| 8330 | if (has_panel) { |
| 8331 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8332 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8333 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8334 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8335 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8336 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8337 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 8338 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8339 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8340 | |
| 8341 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8342 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8343 | POSTING_READ(PCH_DREF_CONTROL); |
| 8344 | udelay(200); |
| 8345 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8346 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8347 | |
| 8348 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8349 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8350 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8351 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8352 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 8353 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8354 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8355 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8356 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8357 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8358 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8359 | POSTING_READ(PCH_DREF_CONTROL); |
| 8360 | udelay(200); |
| 8361 | } else { |
| 8362 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 8363 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8364 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8365 | |
| 8366 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8367 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8368 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8369 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8370 | POSTING_READ(PCH_DREF_CONTROL); |
| 8371 | udelay(200); |
| 8372 | |
| 8373 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8374 | val &= ~DREF_SSC_SOURCE_MASK; |
| 8375 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8376 | |
| 8377 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8378 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8379 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8380 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8381 | POSTING_READ(PCH_DREF_CONTROL); |
| 8382 | udelay(200); |
| 8383 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8384 | |
| 8385 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8386 | } |
| 8387 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8388 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8389 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8390 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8391 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8392 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8393 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 8394 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8395 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8396 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 8397 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 8398 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8399 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8400 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 8401 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 8402 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8403 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8404 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 8405 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 8406 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8407 | } |
| 8408 | |
| 8409 | /* WaMPhyProgramming:hsw */ |
| 8410 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 8411 | { |
| 8412 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8413 | |
| 8414 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 8415 | tmp &= ~(0xFF << 24); |
| 8416 | tmp |= (0x12 << 24); |
| 8417 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 8418 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8419 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 8420 | tmp |= (1 << 11); |
| 8421 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 8422 | |
| 8423 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 8424 | tmp |= (1 << 11); |
| 8425 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 8426 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8427 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 8428 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8429 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 8430 | |
| 8431 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 8432 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 8433 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 8434 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8435 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 8436 | tmp &= ~(7 << 13); |
| 8437 | tmp |= (5 << 13); |
| 8438 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8439 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8440 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 8441 | tmp &= ~(7 << 13); |
| 8442 | tmp |= (5 << 13); |
| 8443 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8444 | |
| 8445 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 8446 | tmp &= ~0xFF; |
| 8447 | tmp |= 0x1C; |
| 8448 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 8449 | |
| 8450 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 8451 | tmp &= ~0xFF; |
| 8452 | tmp |= 0x1C; |
| 8453 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 8454 | |
| 8455 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 8456 | tmp &= ~(0xFF << 16); |
| 8457 | tmp |= (0x1C << 16); |
| 8458 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 8459 | |
| 8460 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 8461 | tmp &= ~(0xFF << 16); |
| 8462 | tmp |= (0x1C << 16); |
| 8463 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 8464 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8465 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 8466 | tmp |= (1 << 27); |
| 8467 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8468 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8469 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 8470 | tmp |= (1 << 27); |
| 8471 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8472 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8473 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 8474 | tmp &= ~(0xF << 28); |
| 8475 | tmp |= (4 << 28); |
| 8476 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8477 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 8478 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 8479 | tmp &= ~(0xF << 28); |
| 8480 | tmp |= (4 << 28); |
| 8481 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8482 | } |
| 8483 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8484 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 8485 | * Programming" based on the parameters passed: |
| 8486 | * - Sequence to enable CLKOUT_DP |
| 8487 | * - Sequence to enable CLKOUT_DP without spread |
| 8488 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 8489 | */ |
| 8490 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 8491 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8492 | { |
| 8493 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8494 | uint32_t reg, tmp; |
| 8495 | |
| 8496 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 8497 | with_spread = true; |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8498 | if (WARN(HAS_PCH_LPT_LP(dev) && with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8499 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8500 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8501 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8502 | |
| 8503 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8504 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 8505 | tmp |= SBI_SSCCTL_PATHALT; |
| 8506 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8507 | |
| 8508 | udelay(24); |
| 8509 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8510 | if (with_spread) { |
| 8511 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8512 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 8513 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 8514 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8515 | if (with_fdi) { |
| 8516 | lpt_reset_fdi_mphy(dev_priv); |
| 8517 | lpt_program_fdi_mphy(dev_priv); |
| 8518 | } |
| 8519 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8520 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8521 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 8522 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8523 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8524 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 8525 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8526 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8527 | } |
| 8528 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8529 | /* Sequence to disable CLKOUT_DP */ |
| 8530 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 8531 | { |
| 8532 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8533 | uint32_t reg, tmp; |
| 8534 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8535 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8536 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 8537 | reg = HAS_PCH_LPT_LP(dev) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8538 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 8539 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 8540 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 8541 | |
| 8542 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 8543 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 8544 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 8545 | tmp |= SBI_SSCCTL_PATHALT; |
| 8546 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8547 | udelay(32); |
| 8548 | } |
| 8549 | tmp |= SBI_SSCCTL_DISABLE; |
| 8550 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 8551 | } |
| 8552 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8553 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8554 | } |
| 8555 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8556 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 8557 | |
| 8558 | static const uint16_t sscdivintphase[] = { |
| 8559 | [BEND_IDX( 50)] = 0x3B23, |
| 8560 | [BEND_IDX( 45)] = 0x3B23, |
| 8561 | [BEND_IDX( 40)] = 0x3C23, |
| 8562 | [BEND_IDX( 35)] = 0x3C23, |
| 8563 | [BEND_IDX( 30)] = 0x3D23, |
| 8564 | [BEND_IDX( 25)] = 0x3D23, |
| 8565 | [BEND_IDX( 20)] = 0x3E23, |
| 8566 | [BEND_IDX( 15)] = 0x3E23, |
| 8567 | [BEND_IDX( 10)] = 0x3F23, |
| 8568 | [BEND_IDX( 5)] = 0x3F23, |
| 8569 | [BEND_IDX( 0)] = 0x0025, |
| 8570 | [BEND_IDX( -5)] = 0x0025, |
| 8571 | [BEND_IDX(-10)] = 0x0125, |
| 8572 | [BEND_IDX(-15)] = 0x0125, |
| 8573 | [BEND_IDX(-20)] = 0x0225, |
| 8574 | [BEND_IDX(-25)] = 0x0225, |
| 8575 | [BEND_IDX(-30)] = 0x0325, |
| 8576 | [BEND_IDX(-35)] = 0x0325, |
| 8577 | [BEND_IDX(-40)] = 0x0425, |
| 8578 | [BEND_IDX(-45)] = 0x0425, |
| 8579 | [BEND_IDX(-50)] = 0x0525, |
| 8580 | }; |
| 8581 | |
| 8582 | /* |
| 8583 | * Bend CLKOUT_DP |
| 8584 | * steps -50 to 50 inclusive, in steps of 5 |
| 8585 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 8586 | * change in clock period = -(steps / 10) * 5.787 ps |
| 8587 | */ |
| 8588 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 8589 | { |
| 8590 | uint32_t tmp; |
| 8591 | int idx = BEND_IDX(steps); |
| 8592 | |
| 8593 | if (WARN_ON(steps % 5 != 0)) |
| 8594 | return; |
| 8595 | |
| 8596 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 8597 | return; |
| 8598 | |
| 8599 | mutex_lock(&dev_priv->sb_lock); |
| 8600 | |
| 8601 | if (steps % 10 != 0) |
| 8602 | tmp = 0xAAAAAAAB; |
| 8603 | else |
| 8604 | tmp = 0x00000000; |
| 8605 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 8606 | |
| 8607 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 8608 | tmp &= 0xffff0000; |
| 8609 | tmp |= sscdivintphase[idx]; |
| 8610 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 8611 | |
| 8612 | mutex_unlock(&dev_priv->sb_lock); |
| 8613 | } |
| 8614 | |
| 8615 | #undef BEND_IDX |
| 8616 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8617 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 8618 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8619 | struct intel_encoder *encoder; |
| 8620 | bool has_vga = false; |
| 8621 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 8622 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8623 | switch (encoder->type) { |
| 8624 | case INTEL_OUTPUT_ANALOG: |
| 8625 | has_vga = true; |
| 8626 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8627 | default: |
| 8628 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8629 | } |
| 8630 | } |
| 8631 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8632 | if (has_vga) { |
| 8633 | lpt_bend_clkout_dp(to_i915(dev), 0); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8634 | lpt_enable_clkout_dp(dev, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8635 | } else { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 8636 | lpt_disable_clkout_dp(dev); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 8637 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 8638 | } |
| 8639 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 8640 | /* |
| 8641 | * Initialize reference clocks when the driver loads |
| 8642 | */ |
| 8643 | void intel_init_pch_refclk(struct drm_device *dev) |
| 8644 | { |
| 8645 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 8646 | ironlake_init_pch_refclk(dev); |
| 8647 | else if (HAS_PCH_LPT(dev)) |
| 8648 | lpt_init_pch_refclk(dev); |
| 8649 | } |
| 8650 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8651 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8652 | { |
| 8653 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8654 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8655 | int pipe = intel_crtc->pipe; |
| 8656 | uint32_t val; |
| 8657 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 8658 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8659 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8660 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8661 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8662 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8663 | break; |
| 8664 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8665 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8666 | break; |
| 8667 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8668 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8669 | break; |
| 8670 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 8671 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8672 | break; |
| 8673 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 8674 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8675 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8676 | } |
| 8677 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8678 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8679 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8680 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8681 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8682 | val |= PIPECONF_INTERLACED_ILK; |
| 8683 | else |
| 8684 | val |= PIPECONF_PROGRESSIVE; |
| 8685 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8686 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8687 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 8688 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 8689 | I915_WRITE(PIPECONF(pipe), val); |
| 8690 | POSTING_READ(PIPECONF(pipe)); |
| 8691 | } |
| 8692 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 8693 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8694 | { |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8695 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8696 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8697 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8698 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8699 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8700 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8701 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 8702 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8703 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8704 | val |= PIPECONF_INTERLACED_ILK; |
| 8705 | else |
| 8706 | val |= PIPECONF_PROGRESSIVE; |
| 8707 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8708 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 8709 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8710 | } |
| 8711 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8712 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
| 8713 | { |
| 8714 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 8715 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8716 | |
| 8717 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
| 8718 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8719 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8720 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8721 | case 18: |
| 8722 | val |= PIPEMISC_DITHER_6_BPC; |
| 8723 | break; |
| 8724 | case 24: |
| 8725 | val |= PIPEMISC_DITHER_8_BPC; |
| 8726 | break; |
| 8727 | case 30: |
| 8728 | val |= PIPEMISC_DITHER_10_BPC; |
| 8729 | break; |
| 8730 | case 36: |
| 8731 | val |= PIPEMISC_DITHER_12_BPC; |
| 8732 | break; |
| 8733 | default: |
| 8734 | /* Case prevented by pipe_config_set_bpp. */ |
| 8735 | BUG(); |
| 8736 | } |
| 8737 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8738 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8739 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 8740 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 8741 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 8742 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 8743 | } |
| 8744 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8745 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 8746 | { |
| 8747 | /* |
| 8748 | * Account for spread spectrum to avoid |
| 8749 | * oversubscribing the link. Max center spread |
| 8750 | * is 2.5%; use 5% for safety's sake. |
| 8751 | */ |
| 8752 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 8753 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 8754 | } |
| 8755 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8756 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 8757 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8758 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 8759 | } |
| 8760 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8761 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 8762 | struct intel_crtc_state *crtc_state, |
| 8763 | intel_clock_t *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8764 | { |
| 8765 | struct drm_crtc *crtc = &intel_crtc->base; |
| 8766 | struct drm_device *dev = crtc->dev; |
| 8767 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8768 | struct drm_atomic_state *state = crtc_state->base.state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8769 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8770 | struct drm_connector_state *connector_state; |
| 8771 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8772 | u32 dpll, fp, fp2; |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8773 | int factor, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 8774 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8775 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 8776 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 8777 | if (connector_state->crtc != crtc_state->base.crtc) |
| 8778 | continue; |
| 8779 | |
| 8780 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 8781 | |
| 8782 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8783 | case INTEL_OUTPUT_LVDS: |
| 8784 | is_lvds = true; |
| 8785 | break; |
| 8786 | case INTEL_OUTPUT_SDVO: |
| 8787 | case INTEL_OUTPUT_HDMI: |
| 8788 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8789 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8790 | default: |
| 8791 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8792 | } |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8793 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8794 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8795 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8796 | factor = 21; |
| 8797 | if (is_lvds) { |
| 8798 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8799 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 8800 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8801 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8802 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 8803 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8804 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8805 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 8806 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8807 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 8808 | fp |= FP_CB_TUNE; |
| 8809 | |
| 8810 | if (reduced_clock) { |
| 8811 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 8812 | |
| 8813 | if (reduced_clock->m < factor * reduced_clock->n) |
| 8814 | fp2 |= FP_CB_TUNE; |
| 8815 | } else { |
| 8816 | fp2 = fp; |
| 8817 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 8818 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 8819 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 8820 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8821 | if (is_lvds) |
| 8822 | dpll |= DPLLB_MODE_LVDS; |
| 8823 | else |
| 8824 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8825 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8826 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8827 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8828 | |
| 8829 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8830 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8831 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8832 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8833 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8834 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8835 | 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] | 8836 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8837 | 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] | 8838 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8839 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 8840 | case 5: |
| 8841 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8842 | break; |
| 8843 | case 7: |
| 8844 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8845 | break; |
| 8846 | case 10: |
| 8847 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8848 | break; |
| 8849 | case 14: |
| 8850 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8851 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8852 | } |
| 8853 | |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8854 | if (is_lvds && intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 8855 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8856 | else |
| 8857 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8858 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8859 | dpll |= DPLL_VCO_ENABLE; |
| 8860 | |
| 8861 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8862 | crtc_state->dpll_hw_state.fp0 = fp; |
| 8863 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 8864 | } |
| 8865 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8866 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 8867 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8868 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8869 | struct drm_device *dev = crtc->base.dev; |
| 8870 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8871 | intel_clock_t reduced_clock; |
Ander Conselvan de Oliveira | 7ed9f89 | 2016-03-21 18:00:07 +0200 | [diff] [blame] | 8872 | bool has_reduced_clock = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8873 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8874 | const intel_limit_t *limit; |
| 8875 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8876 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8877 | memset(&crtc_state->dpll_hw_state, 0, |
| 8878 | sizeof(crtc_state->dpll_hw_state)); |
| 8879 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8880 | crtc->lowfreq_avail = false; |
| 8881 | |
| 8882 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 8883 | if (!crtc_state->has_pch_encoder) |
| 8884 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8885 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8886 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
| 8887 | if (intel_panel_use_ssc(dev_priv)) { |
| 8888 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 8889 | dev_priv->vbt.lvds_ssc_freq); |
| 8890 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8891 | } |
| 8892 | |
| 8893 | if (intel_is_dual_link_lvds(dev)) { |
| 8894 | if (refclk == 100000) |
| 8895 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 8896 | else |
| 8897 | limit = &intel_limits_ironlake_dual_lvds; |
| 8898 | } else { |
| 8899 | if (refclk == 100000) |
| 8900 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 8901 | else |
| 8902 | limit = &intel_limits_ironlake_single_lvds; |
| 8903 | } |
| 8904 | } else { |
| 8905 | limit = &intel_limits_ironlake_dac; |
| 8906 | } |
| 8907 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8908 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 8909 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8910 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 8911 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8912 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8913 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8914 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 8915 | ironlake_compute_dpll(crtc, crtc_state, |
| 8916 | has_reduced_clock ? &reduced_clock : NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8917 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8918 | pll = intel_get_shared_dpll(crtc, crtc_state, NULL); |
| 8919 | if (pll == NULL) { |
| 8920 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 8921 | pipe_name(crtc->pipe)); |
| 8922 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8923 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8924 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 8925 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 8926 | has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8927 | crtc->lowfreq_avail = true; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8928 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8929 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8930 | } |
| 8931 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8932 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8933 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8934 | { |
| 8935 | struct drm_device *dev = crtc->base.dev; |
| 8936 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8937 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8938 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8939 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8940 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8941 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8942 | & ~TU_SIZE_MASK; |
| 8943 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8944 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8945 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8946 | } |
| 8947 | |
| 8948 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8949 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8950 | struct intel_link_m_n *m_n, |
| 8951 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8952 | { |
| 8953 | struct drm_device *dev = crtc->base.dev; |
| 8954 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8955 | enum pipe pipe = crtc->pipe; |
| 8956 | |
| 8957 | if (INTEL_INFO(dev)->gen >= 5) { |
| 8958 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8959 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8960 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8961 | & ~TU_SIZE_MASK; |
| 8962 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8963 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8964 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8965 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8966 | * gen < 8) and if DRRS is supported (to make sure the |
| 8967 | * registers are not unnecessarily read). |
| 8968 | */ |
| 8969 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8970 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8971 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8972 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8973 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8974 | & ~TU_SIZE_MASK; |
| 8975 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8976 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8977 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8978 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8979 | } else { |
| 8980 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8981 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8982 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8983 | & ~TU_SIZE_MASK; |
| 8984 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8985 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8986 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8987 | } |
| 8988 | } |
| 8989 | |
| 8990 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8991 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8992 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8993 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8994 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8995 | else |
| 8996 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8997 | &pipe_config->dp_m_n, |
| 8998 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8999 | } |
| 9000 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9001 | 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] | 9002 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9003 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9004 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9005 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9006 | } |
| 9007 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9008 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9009 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9010 | { |
| 9011 | struct drm_device *dev = crtc->base.dev; |
| 9012 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9013 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 9014 | uint32_t ps_ctrl = 0; |
| 9015 | int id = -1; |
| 9016 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9017 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9018 | /* find scaler attached to this pipe */ |
| 9019 | for (i = 0; i < crtc->num_scalers; i++) { |
| 9020 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 9021 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 9022 | id = i; |
| 9023 | pipe_config->pch_pfit.enabled = true; |
| 9024 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 9025 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 9026 | break; |
| 9027 | } |
| 9028 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9029 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9030 | scaler_state->scaler_id = id; |
| 9031 | if (id >= 0) { |
| 9032 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 9033 | } else { |
| 9034 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9035 | } |
| 9036 | } |
| 9037 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9038 | static void |
| 9039 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9040 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9041 | { |
| 9042 | struct drm_device *dev = crtc->base.dev; |
| 9043 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9044 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9045 | int pipe = crtc->pipe; |
| 9046 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9047 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9048 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9049 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9050 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9051 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9052 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9053 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9054 | return; |
| 9055 | } |
| 9056 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9057 | fb = &intel_fb->base; |
| 9058 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9059 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9060 | if (!(val & PLANE_CTL_ENABLE)) |
| 9061 | goto error; |
| 9062 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9063 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 9064 | fourcc = skl_format_to_fourcc(pixel_format, |
| 9065 | val & PLANE_CTL_ORDER_RGBX, |
| 9066 | val & PLANE_CTL_ALPHA_MASK); |
| 9067 | fb->pixel_format = fourcc; |
| 9068 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 9069 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9070 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9071 | switch (tiling) { |
| 9072 | case PLANE_CTL_TILED_LINEAR: |
| 9073 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 9074 | break; |
| 9075 | case PLANE_CTL_TILED_X: |
| 9076 | plane_config->tiling = I915_TILING_X; |
| 9077 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9078 | break; |
| 9079 | case PLANE_CTL_TILED_Y: |
| 9080 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 9081 | break; |
| 9082 | case PLANE_CTL_TILED_YF: |
| 9083 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 9084 | break; |
| 9085 | default: |
| 9086 | MISSING_CASE(tiling); |
| 9087 | goto error; |
| 9088 | } |
| 9089 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9090 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 9091 | plane_config->base = base; |
| 9092 | |
| 9093 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 9094 | |
| 9095 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 9096 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9097 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9098 | |
| 9099 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 9100 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9101 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9102 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9103 | |
| 9104 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9105 | fb->pixel_format, |
| 9106 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9107 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9108 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9109 | |
| 9110 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9111 | pipe_name(pipe), fb->width, fb->height, |
| 9112 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9113 | plane_config->size); |
| 9114 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9115 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9116 | return; |
| 9117 | |
| 9118 | error: |
| 9119 | kfree(fb); |
| 9120 | } |
| 9121 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9122 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9123 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9124 | { |
| 9125 | struct drm_device *dev = crtc->base.dev; |
| 9126 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9127 | uint32_t tmp; |
| 9128 | |
| 9129 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9130 | |
| 9131 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9132 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9133 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9134 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9135 | |
| 9136 | /* We currently do not free assignements of panel fitters on |
| 9137 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9138 | * differentiates them) so just WARN about this case for now. */ |
| 9139 | if (IS_GEN7(dev)) { |
| 9140 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9141 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9142 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9143 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9144 | } |
| 9145 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9146 | static void |
| 9147 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9148 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9149 | { |
| 9150 | struct drm_device *dev = crtc->base.dev; |
| 9151 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9152 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9153 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9154 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9155 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9156 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9157 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9158 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9159 | val = I915_READ(DSPCNTR(pipe)); |
| 9160 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 9161 | return; |
| 9162 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9163 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9164 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9165 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9166 | return; |
| 9167 | } |
| 9168 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9169 | fb = &intel_fb->base; |
| 9170 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9171 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9172 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9173 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9174 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 9175 | } |
| 9176 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9177 | |
| 9178 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 9179 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9180 | fb->pixel_format = fourcc; |
| 9181 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9182 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9183 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9184 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9185 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9186 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9187 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9188 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9189 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9190 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9191 | } |
| 9192 | plane_config->base = base; |
| 9193 | |
| 9194 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9195 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 9196 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9197 | |
| 9198 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9199 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9200 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9201 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9202 | fb->pixel_format, |
| 9203 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9204 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9205 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9206 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 9207 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9208 | pipe_name(pipe), fb->width, fb->height, |
| 9209 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9210 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9211 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9212 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9213 | } |
| 9214 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9215 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9216 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9217 | { |
| 9218 | struct drm_device *dev = crtc->base.dev; |
| 9219 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9220 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9221 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9222 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9223 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9224 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9225 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9226 | return false; |
| 9227 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9228 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9229 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9230 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9231 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9232 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9233 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9234 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9235 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9236 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9237 | case PIPECONF_6BPC: |
| 9238 | pipe_config->pipe_bpp = 18; |
| 9239 | break; |
| 9240 | case PIPECONF_8BPC: |
| 9241 | pipe_config->pipe_bpp = 24; |
| 9242 | break; |
| 9243 | case PIPECONF_10BPC: |
| 9244 | pipe_config->pipe_bpp = 30; |
| 9245 | break; |
| 9246 | case PIPECONF_12BPC: |
| 9247 | pipe_config->pipe_bpp = 36; |
| 9248 | break; |
| 9249 | default: |
| 9250 | break; |
| 9251 | } |
| 9252 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9253 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9254 | pipe_config->limited_color_range = true; |
| 9255 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9256 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9257 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9258 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9259 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9260 | pipe_config->has_pch_encoder = true; |
| 9261 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9262 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9263 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9264 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9265 | |
| 9266 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9267 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9268 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9269 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9270 | } else { |
| 9271 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9272 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9273 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9274 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9275 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9276 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9277 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9278 | pipe_config->shared_dpll = |
| 9279 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9280 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9281 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9282 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 9283 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 9284 | |
| 9285 | tmp = pipe_config->dpll_hw_state.dpll; |
| 9286 | pipe_config->pixel_multiplier = |
| 9287 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 9288 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9289 | |
| 9290 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9291 | } else { |
| 9292 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9293 | } |
| 9294 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9295 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9296 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9297 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9298 | ironlake_get_pfit_config(crtc, pipe_config); |
| 9299 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9300 | ret = true; |
| 9301 | |
| 9302 | out: |
| 9303 | intel_display_power_put(dev_priv, power_domain); |
| 9304 | |
| 9305 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9306 | } |
| 9307 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9308 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 9309 | { |
| 9310 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9311 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9312 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9313 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9314 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9315 | pipe_name(crtc->pipe)); |
| 9316 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9317 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 9318 | 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] | 9319 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 9320 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9321 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 9322 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9323 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9324 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9325 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 9326 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9327 | 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] | 9328 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9329 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9330 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9331 | 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] | 9332 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 9333 | /* |
| 9334 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 9335 | * interrupts remain enabled. We used to check for that, but since it's |
| 9336 | * gen-specific and since we only disable LCPLL after we fully disable |
| 9337 | * the interrupts, the check below should be enough. |
| 9338 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 9339 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9340 | } |
| 9341 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9342 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 9343 | { |
| 9344 | struct drm_device *dev = dev_priv->dev; |
| 9345 | |
| 9346 | if (IS_HASWELL(dev)) |
| 9347 | return I915_READ(D_COMP_HSW); |
| 9348 | else |
| 9349 | return I915_READ(D_COMP_BDW); |
| 9350 | } |
| 9351 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9352 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 9353 | { |
| 9354 | struct drm_device *dev = dev_priv->dev; |
| 9355 | |
| 9356 | if (IS_HASWELL(dev)) { |
| 9357 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9358 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 9359 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 9360 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9361 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9362 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9363 | I915_WRITE(D_COMP_BDW, val); |
| 9364 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9365 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | /* |
| 9369 | * This function implements pieces of two sequences from BSpec: |
| 9370 | * - Sequence for display software to disable LCPLL |
| 9371 | * - Sequence for display software to allow package C8+ |
| 9372 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 9373 | * register. Callers should take care of disabling all the display engine |
| 9374 | * functions, doing the mode unset, fixing interrupts, etc. |
| 9375 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9376 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 9377 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9378 | { |
| 9379 | uint32_t val; |
| 9380 | |
| 9381 | assert_can_disable_lcpll(dev_priv); |
| 9382 | |
| 9383 | val = I915_READ(LCPLL_CTL); |
| 9384 | |
| 9385 | if (switch_to_fclk) { |
| 9386 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9387 | I915_WRITE(LCPLL_CTL, val); |
| 9388 | |
| 9389 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 9390 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 9391 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9392 | |
| 9393 | val = I915_READ(LCPLL_CTL); |
| 9394 | } |
| 9395 | |
| 9396 | val |= LCPLL_PLL_DISABLE; |
| 9397 | I915_WRITE(LCPLL_CTL, val); |
| 9398 | POSTING_READ(LCPLL_CTL); |
| 9399 | |
| 9400 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 9401 | DRM_ERROR("LCPLL still locked\n"); |
| 9402 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9403 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9404 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9405 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9406 | ndelay(100); |
| 9407 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9408 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 9409 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9410 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 9411 | |
| 9412 | if (allow_power_down) { |
| 9413 | val = I915_READ(LCPLL_CTL); |
| 9414 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 9415 | I915_WRITE(LCPLL_CTL, val); |
| 9416 | POSTING_READ(LCPLL_CTL); |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | /* |
| 9421 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 9422 | * source. |
| 9423 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 9424 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9425 | { |
| 9426 | uint32_t val; |
| 9427 | |
| 9428 | val = I915_READ(LCPLL_CTL); |
| 9429 | |
| 9430 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 9431 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 9432 | return; |
| 9433 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 9434 | /* |
| 9435 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 9436 | * 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] | 9437 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9438 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9439 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9440 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 9441 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 9442 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 9443 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9444 | } |
| 9445 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 9446 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9447 | val |= D_COMP_COMP_FORCE; |
| 9448 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 9449 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9450 | |
| 9451 | val = I915_READ(LCPLL_CTL); |
| 9452 | val &= ~LCPLL_PLL_DISABLE; |
| 9453 | I915_WRITE(LCPLL_CTL, val); |
| 9454 | |
| 9455 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 9456 | DRM_ERROR("LCPLL not locked yet\n"); |
| 9457 | |
| 9458 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 9459 | val = I915_READ(LCPLL_CTL); |
| 9460 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9461 | I915_WRITE(LCPLL_CTL, val); |
| 9462 | |
| 9463 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 9464 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 9465 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9466 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 9467 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 9468 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 9469 | intel_update_cdclk(dev_priv->dev); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 9470 | } |
| 9471 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 9472 | /* |
| 9473 | * Package states C8 and deeper are really deep PC states that can only be |
| 9474 | * reached when all the devices on the system allow it, so even if the graphics |
| 9475 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 9476 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 9477 | * |
| 9478 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 9479 | * well is disabled and most interrupts are disabled, and these are also |
| 9480 | * requirements for runtime PM. When these conditions are met, we manually do |
| 9481 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 9482 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 9483 | * hang the machine. |
| 9484 | * |
| 9485 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 9486 | * the state of some registers, so when we come back from PC8+ we need to |
| 9487 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 9488 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 9489 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 9490 | * because of the runtime PM support). |
| 9491 | * |
| 9492 | * For more, read "Display Sequences for Package C8" on the hardware |
| 9493 | * documentation. |
| 9494 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9495 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9496 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9497 | struct drm_device *dev = dev_priv->dev; |
| 9498 | uint32_t val; |
| 9499 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9500 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 9501 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9502 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9503 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9504 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9505 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9506 | } |
| 9507 | |
| 9508 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9509 | hsw_disable_lcpll(dev_priv, true, true); |
| 9510 | } |
| 9511 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 9512 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9513 | { |
| 9514 | struct drm_device *dev = dev_priv->dev; |
| 9515 | uint32_t val; |
| 9516 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9517 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 9518 | |
| 9519 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9520 | lpt_init_pch_refclk(dev); |
| 9521 | |
Ville Syrjälä | c269952 | 2015-08-27 23:55:59 +0300 | [diff] [blame] | 9522 | if (HAS_PCH_LPT_LP(dev)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9523 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 9524 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 9525 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 9526 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9527 | } |
| 9528 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9529 | static void broxton_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9530 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 9531 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9532 | struct intel_atomic_state *old_intel_state = |
| 9533 | to_intel_atomic_state(old_state); |
| 9534 | unsigned int req_cdclk = old_intel_state->dev_cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9535 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9536 | broxton_set_cdclk(dev, req_cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 9537 | } |
| 9538 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9539 | /* compute the max rate for new configuration */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9540 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9541 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9542 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 9543 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 9544 | struct drm_crtc *crtc; |
| 9545 | struct drm_crtc_state *cstate; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9546 | struct intel_crtc_state *crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9547 | unsigned max_pixel_rate = 0, i; |
| 9548 | enum pipe pipe; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9549 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9550 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 9551 | sizeof(intel_state->min_pixclk)); |
| 9552 | |
| 9553 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9554 | int pixel_rate; |
| 9555 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9556 | crtc_state = to_intel_crtc_state(cstate); |
| 9557 | if (!crtc_state->base.enable) { |
| 9558 | intel_state->min_pixclk[i] = 0; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9559 | continue; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9560 | } |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9561 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9562 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9563 | |
| 9564 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9565 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9566 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
| 9567 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9568 | intel_state->min_pixclk[i] = pixel_rate; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9569 | } |
| 9570 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 9571 | for_each_pipe(dev_priv, pipe) |
| 9572 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); |
| 9573 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9574 | return max_pixel_rate; |
| 9575 | } |
| 9576 | |
| 9577 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) |
| 9578 | { |
| 9579 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9580 | uint32_t val, data; |
| 9581 | int ret; |
| 9582 | |
| 9583 | if (WARN((I915_READ(LCPLL_CTL) & |
| 9584 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | |
| 9585 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | |
| 9586 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | |
| 9587 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, |
| 9588 | "trying to change cdclk frequency with cdclk not enabled\n")) |
| 9589 | return; |
| 9590 | |
| 9591 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9592 | ret = sandybridge_pcode_write(dev_priv, |
| 9593 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); |
| 9594 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9595 | if (ret) { |
| 9596 | DRM_ERROR("failed to inform pcode about cdclk change\n"); |
| 9597 | return; |
| 9598 | } |
| 9599 | |
| 9600 | val = I915_READ(LCPLL_CTL); |
| 9601 | val |= LCPLL_CD_SOURCE_FCLK; |
| 9602 | I915_WRITE(LCPLL_CTL, val); |
| 9603 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9604 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 9605 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9606 | DRM_ERROR("Switching to FCLK failed\n"); |
| 9607 | |
| 9608 | val = I915_READ(LCPLL_CTL); |
| 9609 | val &= ~LCPLL_CLK_FREQ_MASK; |
| 9610 | |
| 9611 | switch (cdclk) { |
| 9612 | case 450000: |
| 9613 | val |= LCPLL_CLK_FREQ_450; |
| 9614 | data = 0; |
| 9615 | break; |
| 9616 | case 540000: |
| 9617 | val |= LCPLL_CLK_FREQ_54O_BDW; |
| 9618 | data = 1; |
| 9619 | break; |
| 9620 | case 337500: |
| 9621 | val |= LCPLL_CLK_FREQ_337_5_BDW; |
| 9622 | data = 2; |
| 9623 | break; |
| 9624 | case 675000: |
| 9625 | val |= LCPLL_CLK_FREQ_675_BDW; |
| 9626 | data = 3; |
| 9627 | break; |
| 9628 | default: |
| 9629 | WARN(1, "invalid cdclk frequency\n"); |
| 9630 | return; |
| 9631 | } |
| 9632 | |
| 9633 | I915_WRITE(LCPLL_CTL, val); |
| 9634 | |
| 9635 | val = I915_READ(LCPLL_CTL); |
| 9636 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 9637 | I915_WRITE(LCPLL_CTL, val); |
| 9638 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 9639 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 9640 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9641 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 9642 | |
| 9643 | mutex_lock(&dev_priv->rps.hw_lock); |
| 9644 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); |
| 9645 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 9646 | |
| 9647 | intel_update_cdclk(dev); |
| 9648 | |
| 9649 | WARN(cdclk != dev_priv->cdclk_freq, |
| 9650 | "cdclk requested %d kHz but got %d kHz\n", |
| 9651 | cdclk, dev_priv->cdclk_freq); |
| 9652 | } |
| 9653 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9654 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9655 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9656 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9657 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9658 | int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9659 | int cdclk; |
| 9660 | |
| 9661 | /* |
| 9662 | * FIXME should also account for plane ratio |
| 9663 | * once 64bpp pixel formats are supported. |
| 9664 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9665 | if (max_pixclk > 540000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9666 | cdclk = 675000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9667 | else if (max_pixclk > 450000) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9668 | cdclk = 540000; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9669 | else if (max_pixclk > 337500) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9670 | cdclk = 450000; |
| 9671 | else |
| 9672 | cdclk = 337500; |
| 9673 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9674 | if (cdclk > dev_priv->max_cdclk_freq) { |
Maarten Lankhorst | 63ba534 | 2015-11-24 11:29:03 +0100 | [diff] [blame] | 9675 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 9676 | cdclk, dev_priv->max_cdclk_freq); |
| 9677 | return -EINVAL; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9678 | } |
| 9679 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9680 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 9681 | if (!intel_state->active_crtcs) |
| 9682 | intel_state->dev_cdclk = 337500; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9683 | |
| 9684 | return 0; |
| 9685 | } |
| 9686 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9687 | static void broadwell_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9688 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9689 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 9690 | struct intel_atomic_state *old_intel_state = |
| 9691 | to_intel_atomic_state(old_state); |
| 9692 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9693 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 9694 | broadwell_set_cdclk(dev, req_cdclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 9695 | } |
| 9696 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9697 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 9698 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9699 | { |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 9700 | struct intel_encoder *intel_encoder = |
| 9701 | intel_ddi_get_crtc_new_encoder(crtc_state); |
| 9702 | |
| 9703 | if (intel_encoder->type != INTEL_OUTPUT_DSI) { |
| 9704 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
| 9705 | return -EINVAL; |
| 9706 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 9707 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9708 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 9709 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9710 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9711 | } |
| 9712 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9713 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9714 | enum port port, |
| 9715 | struct intel_crtc_state *pipe_config) |
| 9716 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9717 | enum intel_dpll_id id; |
| 9718 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9719 | switch (port) { |
| 9720 | case PORT_A: |
| 9721 | pipe_config->ddi_pll_sel = SKL_DPLL0; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9722 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9723 | break; |
| 9724 | case PORT_B: |
| 9725 | pipe_config->ddi_pll_sel = SKL_DPLL1; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9726 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9727 | break; |
| 9728 | case PORT_C: |
| 9729 | pipe_config->ddi_pll_sel = SKL_DPLL2; |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 9730 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9731 | break; |
| 9732 | default: |
| 9733 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9734 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9735 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9736 | |
| 9737 | 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] | 9738 | } |
| 9739 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9740 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9741 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9742 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9743 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9744 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9745 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9746 | |
| 9747 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 9748 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 9749 | |
| 9750 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 9751 | case SKL_DPLL0: |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 9752 | id = DPLL_ID_SKL_DPLL0; |
| 9753 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9754 | case SKL_DPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9755 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9756 | break; |
| 9757 | case SKL_DPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9758 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9759 | break; |
| 9760 | case SKL_DPLL3: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9761 | id = DPLL_ID_SKL_DPLL3; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9762 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9763 | default: |
| 9764 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9765 | return; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9766 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9767 | |
| 9768 | 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] | 9769 | } |
| 9770 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9771 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 9772 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9773 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9774 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9775 | enum intel_dpll_id id; |
| 9776 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9777 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 9778 | |
| 9779 | switch (pipe_config->ddi_pll_sel) { |
| 9780 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9781 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9782 | break; |
| 9783 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9784 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9785 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 9786 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9787 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 9788 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 9789 | case PORT_CLK_SEL_LCPLL_810: |
| 9790 | id = DPLL_ID_LCPLL_810; |
| 9791 | break; |
| 9792 | case PORT_CLK_SEL_LCPLL_1350: |
| 9793 | id = DPLL_ID_LCPLL_1350; |
| 9794 | break; |
| 9795 | case PORT_CLK_SEL_LCPLL_2700: |
| 9796 | id = DPLL_ID_LCPLL_2700; |
| 9797 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9798 | default: |
| 9799 | MISSING_CASE(pipe_config->ddi_pll_sel); |
| 9800 | /* fall through */ |
| 9801 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9802 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 9803 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9804 | |
| 9805 | 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] | 9806 | } |
| 9807 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9808 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 9809 | struct intel_crtc_state *pipe_config, |
| 9810 | unsigned long *power_domain_mask) |
| 9811 | { |
| 9812 | struct drm_device *dev = crtc->base.dev; |
| 9813 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9814 | enum intel_display_power_domain power_domain; |
| 9815 | u32 tmp; |
| 9816 | |
| 9817 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 9818 | |
| 9819 | /* |
| 9820 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 9821 | * consistency and less surprising code; it's in always on power). |
| 9822 | */ |
| 9823 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 9824 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 9825 | enum pipe trans_edp_pipe; |
| 9826 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 9827 | default: |
| 9828 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 9829 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 9830 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 9831 | trans_edp_pipe = PIPE_A; |
| 9832 | break; |
| 9833 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 9834 | trans_edp_pipe = PIPE_B; |
| 9835 | break; |
| 9836 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 9837 | trans_edp_pipe = PIPE_C; |
| 9838 | break; |
| 9839 | } |
| 9840 | |
| 9841 | if (trans_edp_pipe == crtc->pipe) |
| 9842 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 9843 | } |
| 9844 | |
| 9845 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 9846 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9847 | return false; |
| 9848 | *power_domain_mask |= BIT(power_domain); |
| 9849 | |
| 9850 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 9851 | |
| 9852 | return tmp & PIPECONF_ENABLE; |
| 9853 | } |
| 9854 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9855 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 9856 | struct intel_crtc_state *pipe_config, |
| 9857 | unsigned long *power_domain_mask) |
| 9858 | { |
| 9859 | struct drm_device *dev = crtc->base.dev; |
| 9860 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9861 | enum intel_display_power_domain power_domain; |
| 9862 | enum port port; |
| 9863 | enum transcoder cpu_transcoder; |
| 9864 | u32 tmp; |
| 9865 | |
| 9866 | pipe_config->has_dsi_encoder = false; |
| 9867 | |
| 9868 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 9869 | if (port == PORT_A) |
| 9870 | cpu_transcoder = TRANSCODER_DSI_A; |
| 9871 | else |
| 9872 | cpu_transcoder = TRANSCODER_DSI_C; |
| 9873 | |
| 9874 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 9875 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 9876 | continue; |
| 9877 | *power_domain_mask |= BIT(power_domain); |
| 9878 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 9879 | /* |
| 9880 | * The PLL needs to be enabled with a valid divider |
| 9881 | * configuration, otherwise accessing DSI registers will hang |
| 9882 | * the machine. See BSpec North Display Engine |
| 9883 | * registers/MIPI[BXT]. We can break out here early, since we |
| 9884 | * need the same DSI PLL to be enabled for both DSI ports. |
| 9885 | */ |
| 9886 | if (!intel_dsi_pll_is_enabled(dev_priv)) |
| 9887 | break; |
| 9888 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9889 | /* XXX: this works for video mode only */ |
| 9890 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 9891 | if (!(tmp & DPI_ENABLE)) |
| 9892 | continue; |
| 9893 | |
| 9894 | tmp = I915_READ(MIPI_CTRL(port)); |
| 9895 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 9896 | continue; |
| 9897 | |
| 9898 | pipe_config->cpu_transcoder = cpu_transcoder; |
| 9899 | pipe_config->has_dsi_encoder = true; |
| 9900 | break; |
| 9901 | } |
| 9902 | |
| 9903 | return pipe_config->has_dsi_encoder; |
| 9904 | } |
| 9905 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9906 | 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] | 9907 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9908 | { |
| 9909 | struct drm_device *dev = crtc->base.dev; |
| 9910 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9911 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9912 | enum port port; |
| 9913 | uint32_t tmp; |
| 9914 | |
| 9915 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 9916 | |
| 9917 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 9918 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 9919 | if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9920 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 9921 | else if (IS_BROXTON(dev)) |
| 9922 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 9923 | else |
| 9924 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 9925 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9926 | pll = pipe_config->shared_dpll; |
| 9927 | if (pll) { |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9928 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 9929 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 9930 | } |
| 9931 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9932 | /* |
| 9933 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 9934 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 9935 | * the PCH transcoder is on. |
| 9936 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 9937 | if (INTEL_INFO(dev)->gen < 9 && |
| 9938 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 9939 | pipe_config->has_pch_encoder = true; |
| 9940 | |
| 9941 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 9942 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9943 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 9944 | |
| 9945 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 9946 | } |
| 9947 | } |
| 9948 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9949 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9950 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9951 | { |
| 9952 | struct drm_device *dev = crtc->base.dev; |
| 9953 | struct drm_i915_private *dev_priv = dev->dev_private; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9954 | enum intel_display_power_domain power_domain; |
| 9955 | unsigned long power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9956 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9957 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9958 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9959 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 9960 | return false; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9961 | power_domain_mask = BIT(power_domain); |
| 9962 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9963 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9964 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9965 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9966 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9967 | if (IS_BROXTON(dev_priv)) { |
| 9968 | bxt_get_dsi_transcoder_state(crtc, pipe_config, |
| 9969 | &power_domain_mask); |
| 9970 | WARN_ON(active && pipe_config->has_dsi_encoder); |
| 9971 | if (pipe_config->has_dsi_encoder) |
| 9972 | active = true; |
| 9973 | } |
| 9974 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 9975 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9976 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9977 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 9978 | if (!pipe_config->has_dsi_encoder) { |
| 9979 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 9980 | intel_get_pipe_timings(crtc, pipe_config); |
| 9981 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9982 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 9983 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 9984 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 9985 | pipe_config->gamma_mode = |
| 9986 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 9987 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9988 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9989 | skl_init_scalers(dev, crtc, pipe_config); |
| 9990 | } |
| 9991 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 9992 | if (INTEL_INFO(dev)->gen >= 9) { |
| 9993 | pipe_config->scaler_state.scaler_id = -1; |
| 9994 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
| 9995 | } |
| 9996 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9997 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 9998 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
| 9999 | power_domain_mask |= BIT(power_domain); |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 10000 | if (INTEL_INFO(dev)->gen >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10001 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 10002 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 10003 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10004 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10005 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10006 | if (IS_HASWELL(dev)) |
| 10007 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 10008 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10009 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10010 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 10011 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 10012 | pipe_config->pixel_multiplier = |
| 10013 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 10014 | } else { |
| 10015 | pipe_config->pixel_multiplier = 1; |
| 10016 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10017 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10018 | out: |
| 10019 | for_each_power_domain(power_domain, power_domain_mask) |
| 10020 | intel_display_power_put(dev_priv, power_domain); |
| 10021 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10022 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10023 | } |
| 10024 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10025 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10026 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10027 | { |
| 10028 | struct drm_device *dev = crtc->dev; |
| 10029 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10030 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10031 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10032 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10033 | if (plane_state && plane_state->visible) { |
| 10034 | unsigned int width = plane_state->base.crtc_w; |
| 10035 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10036 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 10037 | |
| 10038 | switch (stride) { |
| 10039 | default: |
| 10040 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 10041 | width, stride); |
| 10042 | stride = 256; |
| 10043 | /* fallthrough */ |
| 10044 | case 256: |
| 10045 | case 512: |
| 10046 | case 1024: |
| 10047 | case 2048: |
| 10048 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10049 | } |
| 10050 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10051 | cntl |= CURSOR_ENABLE | |
| 10052 | CURSOR_GAMMA_ENABLE | |
| 10053 | CURSOR_FORMAT_ARGB | |
| 10054 | CURSOR_STRIDE(stride); |
| 10055 | |
| 10056 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10057 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10058 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10059 | if (intel_crtc->cursor_cntl != 0 && |
| 10060 | (intel_crtc->cursor_base != base || |
| 10061 | intel_crtc->cursor_size != size || |
| 10062 | intel_crtc->cursor_cntl != cntl)) { |
| 10063 | /* On these chipsets we can only modify the base/size/stride |
| 10064 | * whilst the cursor is disabled. |
| 10065 | */ |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10066 | I915_WRITE(CURCNTR(PIPE_A), 0); |
| 10067 | POSTING_READ(CURCNTR(PIPE_A)); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10068 | intel_crtc->cursor_cntl = 0; |
| 10069 | } |
| 10070 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10071 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10072 | I915_WRITE(CURBASE(PIPE_A), base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10073 | intel_crtc->cursor_base = base; |
| 10074 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10075 | |
| 10076 | if (intel_crtc->cursor_size != size) { |
| 10077 | I915_WRITE(CURSIZE, size); |
| 10078 | intel_crtc->cursor_size = size; |
| 10079 | } |
| 10080 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10081 | if (intel_crtc->cursor_cntl != cntl) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10082 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
| 10083 | POSTING_READ(CURCNTR(PIPE_A)); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10084 | intel_crtc->cursor_cntl = cntl; |
| 10085 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10086 | } |
| 10087 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10088 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10089 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10090 | { |
| 10091 | struct drm_device *dev = crtc->dev; |
| 10092 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10093 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10094 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | 663f312 | 2015-12-14 13:16:48 +0200 | [diff] [blame] | 10095 | uint32_t cntl = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10096 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10097 | if (plane_state && plane_state->visible) { |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10098 | cntl = MCURSOR_GAMMA_ENABLE; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10099 | switch (plane_state->base.crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10100 | case 64: |
| 10101 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 10102 | break; |
| 10103 | case 128: |
| 10104 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 10105 | break; |
| 10106 | case 256: |
| 10107 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 10108 | break; |
| 10109 | default: |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10110 | MISSING_CASE(plane_state->base.crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10111 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10112 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10113 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10114 | |
Bob Paauwe | fc6f93b | 2015-08-31 14:03:30 -0700 | [diff] [blame] | 10115 | if (HAS_DDI(dev)) |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10116 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10117 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10118 | if (plane_state->base.rotation == BIT(DRM_ROTATE_180)) |
| 10119 | cntl |= CURSOR_ROTATE_180; |
| 10120 | } |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 10121 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10122 | if (intel_crtc->cursor_cntl != cntl) { |
| 10123 | I915_WRITE(CURCNTR(pipe), cntl); |
| 10124 | POSTING_READ(CURCNTR(pipe)); |
| 10125 | intel_crtc->cursor_cntl = cntl; |
| 10126 | } |
| 10127 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10128 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10129 | I915_WRITE(CURBASE(pipe), base); |
| 10130 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10131 | |
| 10132 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10133 | } |
| 10134 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10135 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 10136 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10137 | const struct intel_plane_state *plane_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10138 | { |
| 10139 | struct drm_device *dev = crtc->dev; |
| 10140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10141 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10142 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10143 | u32 base = intel_crtc->cursor_addr; |
| 10144 | u32 pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10145 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10146 | if (plane_state) { |
| 10147 | int x = plane_state->base.crtc_x; |
| 10148 | int y = plane_state->base.crtc_y; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10149 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10150 | if (x < 0) { |
| 10151 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 10152 | x = -x; |
| 10153 | } |
| 10154 | pos |= x << CURSOR_X_SHIFT; |
| 10155 | |
| 10156 | if (y < 0) { |
| 10157 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 10158 | y = -y; |
| 10159 | } |
| 10160 | pos |= y << CURSOR_Y_SHIFT; |
| 10161 | |
| 10162 | /* ILK+ do this automagically */ |
| 10163 | if (HAS_GMCH_DISPLAY(dev) && |
| 10164 | plane_state->base.rotation == BIT(DRM_ROTATE_180)) { |
| 10165 | base += (plane_state->base.crtc_h * |
| 10166 | plane_state->base.crtc_w - 1) * 4; |
| 10167 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10168 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10169 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10170 | I915_WRITE(CURPOS(pipe), pos); |
| 10171 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 10172 | if (IS_845G(dev) || IS_I865G(dev)) |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10173 | i845_update_cursor(crtc, base, plane_state); |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10174 | else |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10175 | i9xx_update_cursor(crtc, base, plane_state); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10176 | } |
| 10177 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10178 | static bool cursor_size_ok(struct drm_device *dev, |
| 10179 | uint32_t width, uint32_t height) |
| 10180 | { |
| 10181 | if (width == 0 || height == 0) |
| 10182 | return false; |
| 10183 | |
| 10184 | /* |
| 10185 | * 845g/865g are special in that they are only limited by |
| 10186 | * the width of their cursors, the height is arbitrary up to |
| 10187 | * the precision of the register. Everything else requires |
| 10188 | * square cursors, limited to a few power-of-two sizes. |
| 10189 | */ |
| 10190 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 10191 | if ((width & 63) != 0) |
| 10192 | return false; |
| 10193 | |
| 10194 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 10195 | return false; |
| 10196 | |
| 10197 | if (height > 1023) |
| 10198 | return false; |
| 10199 | } else { |
| 10200 | switch (width | height) { |
| 10201 | case 256: |
| 10202 | case 128: |
| 10203 | if (IS_GEN2(dev)) |
| 10204 | return false; |
| 10205 | case 64: |
| 10206 | break; |
| 10207 | default: |
| 10208 | return false; |
| 10209 | } |
| 10210 | } |
| 10211 | |
| 10212 | return true; |
| 10213 | } |
| 10214 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10215 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 10216 | static struct drm_display_mode load_detect_mode = { |
| 10217 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10218 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10219 | }; |
| 10220 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10221 | struct drm_framebuffer * |
| 10222 | __intel_framebuffer_create(struct drm_device *dev, |
| 10223 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10224 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10225 | { |
| 10226 | struct intel_framebuffer *intel_fb; |
| 10227 | int ret; |
| 10228 | |
| 10229 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10230 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10231 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10232 | |
| 10233 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10234 | if (ret) |
| 10235 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10236 | |
| 10237 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10238 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10239 | err: |
| 10240 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10241 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10242 | } |
| 10243 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 10244 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10245 | intel_framebuffer_create(struct drm_device *dev, |
| 10246 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10247 | struct drm_i915_gem_object *obj) |
| 10248 | { |
| 10249 | struct drm_framebuffer *fb; |
| 10250 | int ret; |
| 10251 | |
| 10252 | ret = i915_mutex_lock_interruptible(dev); |
| 10253 | if (ret) |
| 10254 | return ERR_PTR(ret); |
| 10255 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 10256 | mutex_unlock(&dev->struct_mutex); |
| 10257 | |
| 10258 | return fb; |
| 10259 | } |
| 10260 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10261 | static u32 |
| 10262 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 10263 | { |
| 10264 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 10265 | return ALIGN(pitch, 64); |
| 10266 | } |
| 10267 | |
| 10268 | static u32 |
| 10269 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 10270 | { |
| 10271 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 10272 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10273 | } |
| 10274 | |
| 10275 | static struct drm_framebuffer * |
| 10276 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 10277 | struct drm_display_mode *mode, |
| 10278 | int depth, int bpp) |
| 10279 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10280 | struct drm_framebuffer *fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10281 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 10282 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10283 | |
| 10284 | obj = i915_gem_alloc_object(dev, |
| 10285 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 10286 | if (obj == NULL) |
| 10287 | return ERR_PTR(-ENOMEM); |
| 10288 | |
| 10289 | mode_cmd.width = mode->hdisplay; |
| 10290 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 10291 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 10292 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 10293 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10294 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10295 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
| 10296 | if (IS_ERR(fb)) |
| 10297 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10298 | |
| 10299 | return fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10300 | } |
| 10301 | |
| 10302 | static struct drm_framebuffer * |
| 10303 | mode_fits_in_fbdev(struct drm_device *dev, |
| 10304 | struct drm_display_mode *mode) |
| 10305 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 10306 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10307 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10308 | struct drm_i915_gem_object *obj; |
| 10309 | struct drm_framebuffer *fb; |
| 10310 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10311 | if (!dev_priv->fbdev) |
| 10312 | return NULL; |
| 10313 | |
| 10314 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10315 | return NULL; |
| 10316 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10317 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 10318 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10319 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 10320 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10321 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 10322 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10323 | return NULL; |
| 10324 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10325 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10326 | return NULL; |
| 10327 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10328 | drm_framebuffer_reference(fb); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10329 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 10330 | #else |
| 10331 | return NULL; |
| 10332 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10333 | } |
| 10334 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10335 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 10336 | struct drm_crtc *crtc, |
| 10337 | struct drm_display_mode *mode, |
| 10338 | struct drm_framebuffer *fb, |
| 10339 | int x, int y) |
| 10340 | { |
| 10341 | struct drm_plane_state *plane_state; |
| 10342 | int hdisplay, vdisplay; |
| 10343 | int ret; |
| 10344 | |
| 10345 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 10346 | if (IS_ERR(plane_state)) |
| 10347 | return PTR_ERR(plane_state); |
| 10348 | |
| 10349 | if (mode) |
| 10350 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 10351 | else |
| 10352 | hdisplay = vdisplay = 0; |
| 10353 | |
| 10354 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 10355 | if (ret) |
| 10356 | return ret; |
| 10357 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 10358 | plane_state->crtc_x = 0; |
| 10359 | plane_state->crtc_y = 0; |
| 10360 | plane_state->crtc_w = hdisplay; |
| 10361 | plane_state->crtc_h = vdisplay; |
| 10362 | plane_state->src_x = x << 16; |
| 10363 | plane_state->src_y = y << 16; |
| 10364 | plane_state->src_w = hdisplay << 16; |
| 10365 | plane_state->src_h = vdisplay << 16; |
| 10366 | |
| 10367 | return 0; |
| 10368 | } |
| 10369 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10370 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10371 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10372 | struct intel_load_detect_pipe *old, |
| 10373 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10374 | { |
| 10375 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10376 | struct intel_encoder *intel_encoder = |
| 10377 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10378 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10379 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10380 | struct drm_crtc *crtc = NULL; |
| 10381 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10382 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10383 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10384 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10385 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10386 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10387 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10388 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10389 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10390 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10391 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10392 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10393 | old->restore_state = NULL; |
| 10394 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10395 | retry: |
| 10396 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 10397 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10398 | goto fail; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 10399 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10400 | /* |
| 10401 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10402 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10403 | * - if the connector already has an assigned crtc, use it (but make |
| 10404 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 10405 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10406 | * - try to find the first unused crtc that can drive this connector, |
| 10407 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10408 | */ |
| 10409 | |
| 10410 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10411 | if (connector->state->crtc) { |
| 10412 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10413 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10414 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 10415 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10416 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 10417 | |
| 10418 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10419 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10420 | } |
| 10421 | |
| 10422 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 10423 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10424 | i++; |
| 10425 | if (!(encoder->possible_crtcs & (1 << i))) |
| 10426 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10427 | |
| 10428 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 10429 | if (ret) |
| 10430 | goto fail; |
| 10431 | |
| 10432 | if (possible_crtc->state->enable) { |
| 10433 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10434 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10435 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 10436 | |
| 10437 | crtc = possible_crtc; |
| 10438 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10439 | } |
| 10440 | |
| 10441 | /* |
| 10442 | * If we didn't find an unused CRTC, don't use any. |
| 10443 | */ |
| 10444 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10445 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10446 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10447 | } |
| 10448 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10449 | found: |
| 10450 | intel_crtc = to_intel_crtc(crtc); |
| 10451 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 10452 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 10453 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10454 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10455 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10456 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10457 | restore_state = drm_atomic_state_alloc(dev); |
| 10458 | if (!state || !restore_state) { |
| 10459 | ret = -ENOMEM; |
| 10460 | goto fail; |
| 10461 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10462 | |
| 10463 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10464 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10465 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10466 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 10467 | if (IS_ERR(connector_state)) { |
| 10468 | ret = PTR_ERR(connector_state); |
| 10469 | goto fail; |
| 10470 | } |
| 10471 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10472 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 10473 | if (ret) |
| 10474 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 10475 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10476 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 10477 | if (IS_ERR(crtc_state)) { |
| 10478 | ret = PTR_ERR(crtc_state); |
| 10479 | goto fail; |
| 10480 | } |
| 10481 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 10482 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 10483 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10484 | if (!mode) |
| 10485 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10486 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10487 | /* We need a framebuffer large enough to accommodate all accesses |
| 10488 | * that the plane may generate whilst we perform load detection. |
| 10489 | * We can not rely on the fbcon either being present (we get called |
| 10490 | * during its initialisation to detect all boot displays, or it may |
| 10491 | * not even exist) or that it is large enough to satisfy the |
| 10492 | * requested mode. |
| 10493 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10494 | fb = mode_fits_in_fbdev(dev, mode); |
| 10495 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10496 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10497 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10498 | } else |
| 10499 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 10500 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10501 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10502 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10503 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10504 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10505 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 10506 | if (ret) |
| 10507 | goto fail; |
| 10508 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10509 | drm_framebuffer_unreference(fb); |
| 10510 | |
| 10511 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
| 10512 | if (ret) |
| 10513 | goto fail; |
| 10514 | |
| 10515 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 10516 | if (!ret) |
| 10517 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); |
| 10518 | if (!ret) |
| 10519 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); |
| 10520 | if (ret) { |
| 10521 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 10522 | goto fail; |
| 10523 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 10524 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 10525 | ret = drm_atomic_commit(state); |
| 10526 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 10527 | 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] | 10528 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10529 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10530 | |
| 10531 | old->restore_state = restore_state; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10532 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10533 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 10534 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 10535 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10536 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 10537 | fail: |
Ander Conselvan de Oliveira | e5d958e | 2015-04-21 17:12:57 +0300 | [diff] [blame] | 10538 | drm_atomic_state_free(state); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10539 | drm_atomic_state_free(restore_state); |
| 10540 | restore_state = state = NULL; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10541 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 10542 | if (ret == -EDEADLK) { |
| 10543 | drm_modeset_backoff(ctx); |
| 10544 | goto retry; |
| 10545 | } |
| 10546 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 10547 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10548 | } |
| 10549 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10550 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 10551 | struct intel_load_detect_pipe *old, |
| 10552 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10553 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 10554 | struct intel_encoder *intel_encoder = |
| 10555 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 10556 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10557 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 10558 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10559 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10560 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10561 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10562 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10563 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10564 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 10565 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 10566 | |
| 10567 | ret = drm_atomic_commit(state); |
| 10568 | if (ret) { |
| 10569 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
| 10570 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10571 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10572 | } |
| 10573 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10574 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10575 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10576 | { |
| 10577 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10578 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 10579 | |
| 10580 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 10581 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10582 | else if (HAS_PCH_SPLIT(dev)) |
| 10583 | return 120000; |
| 10584 | else if (!IS_GEN2(dev)) |
| 10585 | return 96000; |
| 10586 | else |
| 10587 | return 48000; |
| 10588 | } |
| 10589 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10590 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10591 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10592 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10593 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10594 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10595 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10596 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10597 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10598 | u32 fp; |
| 10599 | intel_clock_t clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10600 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10601 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10602 | |
| 10603 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10604 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10605 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10606 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10607 | |
| 10608 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10609 | if (IS_PINEVIEW(dev)) { |
| 10610 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 10611 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10612 | } else { |
| 10613 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 10614 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 10615 | } |
| 10616 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 10617 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 10618 | if (IS_PINEVIEW(dev)) |
| 10619 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 10620 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 10621 | else |
| 10622 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10623 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 10624 | |
| 10625 | switch (dpll & DPLL_MODE_MASK) { |
| 10626 | case DPLLB_MODE_DAC_SERIAL: |
| 10627 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 10628 | 5 : 10; |
| 10629 | break; |
| 10630 | case DPLLB_MODE_LVDS: |
| 10631 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 10632 | 7 : 14; |
| 10633 | break; |
| 10634 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 10635 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10636 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10637 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10638 | } |
| 10639 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10640 | if (IS_PINEVIEW(dev)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10641 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 10642 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10643 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10644 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 10645 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10646 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10647 | |
| 10648 | if (is_lvds) { |
| 10649 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 10650 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 10651 | |
| 10652 | if (lvds & LVDS_CLKB_POWER_UP) |
| 10653 | clock.p2 = 7; |
| 10654 | else |
| 10655 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10656 | } else { |
| 10657 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 10658 | clock.p1 = 2; |
| 10659 | else { |
| 10660 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 10661 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 10662 | } |
| 10663 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 10664 | clock.p2 = 4; |
| 10665 | else |
| 10666 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10667 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 10668 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10669 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10670 | } |
| 10671 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10672 | /* |
| 10673 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10674 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10675 | * encoder's get_config() function. |
| 10676 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 10677 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10678 | } |
| 10679 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10680 | int intel_dotclock_calculate(int link_freq, |
| 10681 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10682 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10683 | /* |
| 10684 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10685 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10686 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10687 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10688 | * |
| 10689 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 10690 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10691 | */ |
| 10692 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10693 | if (!m_n->link_n) |
| 10694 | return 0; |
| 10695 | |
| 10696 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 10697 | } |
| 10698 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10699 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10700 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10701 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10702 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10703 | |
| 10704 | /* read out port_clock from the DPLL */ |
| 10705 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 10706 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10707 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 10708 | * In case there is an active pipe without active ports, |
| 10709 | * we may need some idea for the dotclock anyway. |
| 10710 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10711 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10712 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 10713 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10714 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10715 | } |
| 10716 | |
| 10717 | /** Returns the currently programmed mode of the given pipe. */ |
| 10718 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 10719 | struct drm_crtc *crtc) |
| 10720 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 10721 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10722 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10723 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10724 | struct drm_display_mode *mode; |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10725 | struct intel_crtc_state *pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10726 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 10727 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10728 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 10729 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 10730 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10731 | |
| 10732 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 10733 | if (!mode) |
| 10734 | return NULL; |
| 10735 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10736 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10737 | if (!pipe_config) { |
| 10738 | kfree(mode); |
| 10739 | return NULL; |
| 10740 | } |
| 10741 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10742 | /* |
| 10743 | * Construct a pipe_config sufficient for getting the clock info |
| 10744 | * back out of crtc_clock_get. |
| 10745 | * |
| 10746 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 10747 | * to use a real value here instead. |
| 10748 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10749 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
| 10750 | pipe_config->pixel_multiplier = 1; |
| 10751 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 10752 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 10753 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
| 10754 | i9xx_crtc_clock_get(intel_crtc, pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10755 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10756 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10757 | mode->hdisplay = (htot & 0xffff) + 1; |
| 10758 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 10759 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 10760 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 10761 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 10762 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 10763 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 10764 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 10765 | |
| 10766 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10767 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 10768 | kfree(pipe_config); |
| 10769 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10770 | return mode; |
| 10771 | } |
| 10772 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10773 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10774 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10775 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10776 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10777 | if (dev_priv->mm.busy) |
| 10778 | return; |
| 10779 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10780 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10781 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 10782 | if (INTEL_INFO(dev)->gen >= 6) |
| 10783 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10784 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10785 | } |
| 10786 | |
| 10787 | void intel_mark_idle(struct drm_device *dev) |
| 10788 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10789 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 10790 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 10791 | if (!dev_priv->mm.busy) |
| 10792 | return; |
| 10793 | |
| 10794 | dev_priv->mm.busy = false; |
| 10795 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 10796 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 10797 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 10798 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 10799 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 10800 | } |
| 10801 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10802 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 10803 | { |
| 10804 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10805 | struct drm_device *dev = crtc->dev; |
| 10806 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10807 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10808 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10809 | work = intel_crtc->unpin_work; |
| 10810 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10811 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10812 | |
| 10813 | if (work) { |
| 10814 | cancel_work_sync(&work->work); |
| 10815 | kfree(work); |
| 10816 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10817 | |
| 10818 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 10819 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10820 | kfree(intel_crtc); |
| 10821 | } |
| 10822 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10823 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 10824 | { |
| 10825 | struct intel_unpin_work *work = |
| 10826 | container_of(__work, struct intel_unpin_work, work); |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10827 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 10828 | struct drm_device *dev = crtc->base.dev; |
| 10829 | struct drm_plane *primary = crtc->base.primary; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10830 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10831 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 10832 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10833 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 10834 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10835 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10836 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10837 | mutex_unlock(&dev->struct_mutex); |
| 10838 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10839 | intel_frontbuffer_flip_complete(dev, to_intel_plane(primary)->frontbuffer_bit); |
Paulo Zanoni | 1eb5223 | 2016-01-19 11:35:44 -0200 | [diff] [blame] | 10840 | intel_fbc_post_update(crtc); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10841 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10842 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 10843 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
| 10844 | atomic_dec(&crtc->unpin_work_count); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10845 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10846 | kfree(work); |
| 10847 | } |
| 10848 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10849 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10850 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10851 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10852 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10853 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10854 | unsigned long flags; |
| 10855 | |
| 10856 | /* Ignore early vblank irqs */ |
| 10857 | if (intel_crtc == NULL) |
| 10858 | return; |
| 10859 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10860 | /* |
| 10861 | * This is called both by irq handlers and the reset code (to complete |
| 10862 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10863 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10864 | spin_lock_irqsave(&dev->event_lock, flags); |
| 10865 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10866 | |
| 10867 | /* Ensure we don't miss a work->pending update ... */ |
| 10868 | smp_rmb(); |
| 10869 | |
| 10870 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10871 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10872 | return; |
| 10873 | } |
| 10874 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10875 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 10876 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10877 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10878 | } |
| 10879 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10880 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 10881 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10882 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10883 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10884 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10885 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10886 | } |
| 10887 | |
| 10888 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 10889 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10890 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10891 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 10892 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 10893 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 10894 | } |
| 10895 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10896 | /* Is 'a' after or equal to 'b'? */ |
| 10897 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 10898 | { |
| 10899 | return !((a - b) & 0x80000000); |
| 10900 | } |
| 10901 | |
| 10902 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 10903 | { |
| 10904 | struct drm_device *dev = crtc->base.dev; |
| 10905 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10906 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 10907 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 10908 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 10909 | return true; |
| 10910 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10911 | /* |
| 10912 | * The relevant registers doen't exist on pre-ctg. |
| 10913 | * As the flip done interrupt doesn't trigger for mmio |
| 10914 | * flips on gmch platforms, a flip count check isn't |
| 10915 | * really needed there. But since ctg has the registers, |
| 10916 | * include it in the check anyway. |
| 10917 | */ |
| 10918 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 10919 | return true; |
| 10920 | |
| 10921 | /* |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 10922 | * BDW signals flip done immediately if the plane |
| 10923 | * is disabled, even if the plane enable is already |
| 10924 | * armed to occur at the next vblank :( |
| 10925 | */ |
| 10926 | |
| 10927 | /* |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10928 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 10929 | * used the same base address. In that case the mmio flip might |
| 10930 | * have completed, but the CS hasn't even executed the flip yet. |
| 10931 | * |
| 10932 | * A flip count check isn't enough as the CS might have updated |
| 10933 | * the base address just after start of vblank, but before we |
| 10934 | * managed to process the interrupt. This means we'd complete the |
| 10935 | * CS flip too soon. |
| 10936 | * |
| 10937 | * Combining both checks should get us a good enough result. It may |
| 10938 | * still happen that the CS flip has been executed, but has not |
| 10939 | * yet actually completed. But in case the base address is the same |
| 10940 | * anyway, we don't really care. |
| 10941 | */ |
| 10942 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 10943 | crtc->unpin_work->gtt_offset && |
Ville Syrjälä | fd8f507c | 2015-09-18 20:03:42 +0300 | [diff] [blame] | 10944 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10945 | crtc->unpin_work->flip_count); |
| 10946 | } |
| 10947 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10948 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 10949 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10950 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10951 | struct intel_crtc *intel_crtc = |
| 10952 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 10953 | unsigned long flags; |
| 10954 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10955 | |
| 10956 | /* |
| 10957 | * This is called both by irq handlers and the reset code (to complete |
| 10958 | * lost pageflips) so needs the full irqsave spinlocks. |
| 10959 | * |
| 10960 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10961 | * generate a page-flip completion irq, i.e. every modeset |
| 10962 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 10963 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10964 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10965 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10966 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10967 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10968 | } |
| 10969 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10970 | static inline void intel_mark_page_flip_active(struct intel_unpin_work *work) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10971 | { |
| 10972 | /* Ensure that the work item is consistent when activating it ... */ |
| 10973 | smp_wmb(); |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 10974 | atomic_set(&work->pending, INTEL_FLIP_PENDING); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10975 | /* and that it is marked active as soon as the irq could fire. */ |
| 10976 | smp_wmb(); |
| 10977 | } |
| 10978 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10979 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 10980 | struct drm_crtc *crtc, |
| 10981 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10982 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 10983 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10984 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10985 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 10986 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10987 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10988 | u32 flip_mask; |
| 10989 | int ret; |
| 10990 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 10991 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10992 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10993 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10994 | |
| 10995 | /* Can't queue multiple flips, so wait for the previous |
| 10996 | * one to finish before executing the next. |
| 10997 | */ |
| 10998 | if (intel_crtc->plane) |
| 10999 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11000 | else |
| 11001 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11002 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 11003 | intel_ring_emit(engine, MI_NOOP); |
| 11004 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 11005 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11006 | intel_ring_emit(engine, fb->pitches[0]); |
| 11007 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 11008 | intel_ring_emit(engine, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11009 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11010 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11011 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11012 | } |
| 11013 | |
| 11014 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 11015 | struct drm_crtc *crtc, |
| 11016 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11017 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11018 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11019 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11020 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11021 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11022 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11023 | u32 flip_mask; |
| 11024 | int ret; |
| 11025 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11026 | ret = intel_ring_begin(req, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11027 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11028 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11029 | |
| 11030 | if (intel_crtc->plane) |
| 11031 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11032 | else |
| 11033 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11034 | intel_ring_emit(engine, MI_WAIT_FOR_EVENT | flip_mask); |
| 11035 | intel_ring_emit(engine, MI_NOOP); |
| 11036 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 11037 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11038 | intel_ring_emit(engine, fb->pitches[0]); |
| 11039 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 11040 | intel_ring_emit(engine, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11041 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11042 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11043 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11044 | } |
| 11045 | |
| 11046 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 11047 | struct drm_crtc *crtc, |
| 11048 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11049 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11050 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11051 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11052 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11053 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11054 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11055 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11056 | uint32_t pf, pipesrc; |
| 11057 | int ret; |
| 11058 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11059 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11060 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11061 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11062 | |
| 11063 | /* i965+ uses the linear or tiled offsets from the |
| 11064 | * Display Registers (which do not change across a page-flip) |
| 11065 | * so we need only reprogram the base address. |
| 11066 | */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11067 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 11068 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11069 | intel_ring_emit(engine, fb->pitches[0]); |
| 11070 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 11071 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11072 | |
| 11073 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 11074 | * untested on non-native modes, so ignore it for now. |
| 11075 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 11076 | */ |
| 11077 | pf = 0; |
| 11078 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11079 | intel_ring_emit(engine, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11080 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11081 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11082 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11083 | } |
| 11084 | |
| 11085 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 11086 | struct drm_crtc *crtc, |
| 11087 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11088 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11089 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11090 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11091 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11092 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11093 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11094 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11095 | uint32_t pf, pipesrc; |
| 11096 | int ret; |
| 11097 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11098 | ret = intel_ring_begin(req, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11099 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11100 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11101 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11102 | intel_ring_emit(engine, MI_DISPLAY_FLIP | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 11103 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11104 | intel_ring_emit(engine, fb->pitches[0] | obj->tiling_mode); |
| 11105 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11106 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 11107 | /* Contrary to the suggestions in the documentation, |
| 11108 | * "Enable Panel Fitter" does not seem to be required when page |
| 11109 | * flipping with a non-native mode, and worse causes a normal |
| 11110 | * modeset to fail. |
| 11111 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 11112 | */ |
| 11113 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11114 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11115 | intel_ring_emit(engine, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11116 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11117 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11118 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11119 | } |
| 11120 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11121 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 11122 | struct drm_crtc *crtc, |
| 11123 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11124 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11125 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11126 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11127 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11128 | struct intel_engine_cs *engine = req->engine; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11129 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11130 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11131 | int len, ret; |
| 11132 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 11133 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11134 | case PLANE_A: |
| 11135 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 11136 | break; |
| 11137 | case PLANE_B: |
| 11138 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 11139 | break; |
| 11140 | case PLANE_C: |
| 11141 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 11142 | break; |
| 11143 | default: |
| 11144 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11145 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 11146 | } |
| 11147 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11148 | len = 4; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11149 | if (engine->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11150 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11151 | /* |
| 11152 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 11153 | * 48bits addresses, and we need a NOOP for the batch size to |
| 11154 | * stay even. |
| 11155 | */ |
| 11156 | if (IS_GEN8(dev)) |
| 11157 | len += 2; |
| 11158 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11159 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11160 | /* |
| 11161 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 11162 | * "The full packet must be contained within the same cache line." |
| 11163 | * |
| 11164 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 11165 | * cacheline, if we ever start emitting more commands before |
| 11166 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 11167 | * then do the cacheline alignment, and finally emit the |
| 11168 | * MI_DISPLAY_FLIP. |
| 11169 | */ |
John Harrison | bba09b1 | 2015-05-29 17:44:06 +0100 | [diff] [blame] | 11170 | ret = intel_ring_cacheline_align(req); |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11171 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11172 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 11173 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 11174 | ret = intel_ring_begin(req, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11175 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11176 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11177 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11178 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 11179 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 11180 | * more than one flip event at any time (or ensure that one flip message |
| 11181 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 11182 | * Experimentation says that BCS works despite DERRMR masking all |
| 11183 | * flip-done completion events and that unmasking all planes at once |
| 11184 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 11185 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 11186 | */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11187 | if (engine->id == RCS) { |
| 11188 | intel_ring_emit(engine, MI_LOAD_REGISTER_IMM(1)); |
| 11189 | intel_ring_emit_reg(engine, DERRMR); |
| 11190 | intel_ring_emit(engine, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 11191 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 11192 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11193 | if (IS_GEN8(dev)) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11194 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM_GEN8 | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11195 | MI_SRM_LRM_GLOBAL_GTT); |
| 11196 | else |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11197 | intel_ring_emit(engine, MI_STORE_REGISTER_MEM | |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11198 | MI_SRM_LRM_GLOBAL_GTT); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11199 | intel_ring_emit_reg(engine, DERRMR); |
| 11200 | intel_ring_emit(engine, engine->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11201 | if (IS_GEN8(dev)) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11202 | intel_ring_emit(engine, 0); |
| 11203 | intel_ring_emit(engine, MI_NOOP); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 11204 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 11205 | } |
| 11206 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11207 | intel_ring_emit(engine, MI_DISPLAY_FLIP_I915 | plane_bit); |
| 11208 | intel_ring_emit(engine, (fb->pitches[0] | obj->tiling_mode)); |
| 11209 | intel_ring_emit(engine, intel_crtc->unpin_work->gtt_offset); |
| 11210 | intel_ring_emit(engine, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11211 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11212 | intel_mark_page_flip_active(intel_crtc->unpin_work); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 11213 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 11214 | } |
| 11215 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11216 | static bool use_mmio_flip(struct intel_engine_cs *engine, |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11217 | struct drm_i915_gem_object *obj) |
| 11218 | { |
| 11219 | /* |
| 11220 | * This is not being used for older platforms, because |
| 11221 | * non-availability of flip done interrupt forces us to use |
| 11222 | * CS flips. Older platforms derive flip done using some clever |
| 11223 | * tricks involving the flip_pending status bits and vblank irqs. |
| 11224 | * So using MMIO flips there would disrupt this mechanism. |
| 11225 | */ |
| 11226 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11227 | if (engine == NULL) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11228 | return true; |
| 11229 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 11230 | if (INTEL_INFO(engine->dev)->gen < 5) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11231 | return false; |
| 11232 | |
| 11233 | if (i915.use_mmio_flip < 0) |
| 11234 | return false; |
| 11235 | else if (i915.use_mmio_flip > 0) |
| 11236 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 11237 | else if (i915.enable_execlists) |
| 11238 | return true; |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11239 | else if (obj->base.dma_buf && |
| 11240 | !reservation_object_test_signaled_rcu(obj->base.dma_buf->resv, |
| 11241 | false)) |
| 11242 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11243 | else |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 11244 | return engine != i915_gem_request_get_engine(obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11245 | } |
| 11246 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11247 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11248 | unsigned int rotation, |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11249 | struct intel_unpin_work *work) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11250 | { |
| 11251 | struct drm_device *dev = intel_crtc->base.dev; |
| 11252 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11253 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11254 | const enum pipe pipe = intel_crtc->pipe; |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11255 | u32 ctl, stride, tile_height; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11256 | |
| 11257 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 11258 | ctl &= ~PLANE_CTL_TILED_MASK; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11259 | switch (fb->modifier[0]) { |
| 11260 | case DRM_FORMAT_MOD_NONE: |
| 11261 | break; |
| 11262 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11263 | ctl |= PLANE_CTL_TILED_X; |
Tvrtko Ursulin | 2ebef63 | 2015-04-20 16:22:48 +0100 | [diff] [blame] | 11264 | break; |
| 11265 | case I915_FORMAT_MOD_Y_TILED: |
| 11266 | ctl |= PLANE_CTL_TILED_Y; |
| 11267 | break; |
| 11268 | case I915_FORMAT_MOD_Yf_TILED: |
| 11269 | ctl |= PLANE_CTL_TILED_YF; |
| 11270 | break; |
| 11271 | default: |
| 11272 | MISSING_CASE(fb->modifier[0]); |
| 11273 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11274 | |
| 11275 | /* |
| 11276 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 11277 | * linear buffers or in number of tiles for tiled buffers. |
| 11278 | */ |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11279 | if (intel_rotation_90_or_270(rotation)) { |
| 11280 | /* stride = Surface height in tiles */ |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 11281 | tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11282 | stride = DIV_ROUND_UP(fb->height, tile_height); |
| 11283 | } else { |
| 11284 | stride = fb->pitches[0] / |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 11285 | intel_fb_stride_alignment(dev_priv, fb->modifier[0], |
| 11286 | fb->pixel_format); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11287 | } |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11288 | |
| 11289 | /* |
| 11290 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 11291 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 11292 | */ |
| 11293 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 11294 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 11295 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11296 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11297 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 11298 | } |
| 11299 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11300 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 11301 | struct intel_unpin_work *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11302 | { |
| 11303 | struct drm_device *dev = intel_crtc->base.dev; |
| 11304 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11305 | struct intel_framebuffer *intel_fb = |
| 11306 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 11307 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 11308 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11309 | u32 dspcntr; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11310 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11311 | dspcntr = I915_READ(reg); |
| 11312 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 11313 | if (obj->tiling_mode != I915_TILING_NONE) |
| 11314 | dspcntr |= DISPPLANE_TILED; |
| 11315 | else |
| 11316 | dspcntr &= ~DISPPLANE_TILED; |
| 11317 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11318 | I915_WRITE(reg, dspcntr); |
| 11319 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11320 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11321 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11322 | } |
| 11323 | |
| 11324 | /* |
| 11325 | * XXX: This is the temporary way to update the plane registers until we get |
| 11326 | * around to using the usual plane update functions for MMIO flips |
| 11327 | */ |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11328 | static void intel_do_mmio_flip(struct intel_mmio_flip *mmio_flip) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11329 | { |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11330 | struct intel_crtc *crtc = mmio_flip->crtc; |
| 11331 | struct intel_unpin_work *work; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11332 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11333 | spin_lock_irq(&crtc->base.dev->event_lock); |
| 11334 | work = crtc->unpin_work; |
| 11335 | spin_unlock_irq(&crtc->base.dev->event_lock); |
| 11336 | if (work == NULL) |
| 11337 | return; |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11338 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11339 | intel_mark_page_flip_active(work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11340 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11341 | intel_pipe_update_start(crtc); |
| 11342 | |
| 11343 | if (INTEL_INFO(mmio_flip->i915)->gen >= 9) |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11344 | skl_do_mmio_flip(crtc, mmio_flip->rotation, work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11345 | else |
| 11346 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11347 | ilk_do_mmio_flip(crtc, work); |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 11348 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11349 | intel_pipe_update_end(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11350 | } |
| 11351 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 11352 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11353 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11354 | struct intel_mmio_flip *mmio_flip = |
| 11355 | container_of(work, struct intel_mmio_flip, work); |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11356 | struct intel_framebuffer *intel_fb = |
| 11357 | to_intel_framebuffer(mmio_flip->crtc->base.primary->fb); |
| 11358 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11359 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11360 | if (mmio_flip->req) { |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11361 | WARN_ON(__i915_wait_request(mmio_flip->req, |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11362 | mmio_flip->crtc->reset_counter, |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11363 | false, NULL, |
| 11364 | &mmio_flip->i915->rps.mmioflips)); |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11365 | i915_gem_request_unreference__unlocked(mmio_flip->req); |
| 11366 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11367 | |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 11368 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 11369 | if (obj->base.dma_buf) |
| 11370 | WARN_ON(reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 11371 | false, false, |
| 11372 | MAX_SCHEDULE_TIMEOUT) < 0); |
| 11373 | |
Chris Wilson | 6042639 | 2015-10-10 10:44:32 +0100 | [diff] [blame] | 11374 | intel_do_mmio_flip(mmio_flip); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11375 | kfree(mmio_flip); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11376 | } |
| 11377 | |
| 11378 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 11379 | struct drm_crtc *crtc, |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11380 | struct drm_i915_gem_object *obj) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11381 | { |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11382 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11383 | |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11384 | mmio_flip = kmalloc(sizeof(*mmio_flip), GFP_KERNEL); |
| 11385 | if (mmio_flip == NULL) |
| 11386 | return -ENOMEM; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11387 | |
Chris Wilson | bcafc4e | 2015-04-27 13:41:21 +0100 | [diff] [blame] | 11388 | mmio_flip->i915 = to_i915(dev); |
Daniel Vetter | eed29a5 | 2015-05-21 14:21:25 +0200 | [diff] [blame] | 11389 | mmio_flip->req = i915_gem_request_reference(obj->last_write_req); |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11390 | mmio_flip->crtc = to_intel_crtc(crtc); |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11391 | mmio_flip->rotation = crtc->primary->state->rotation; |
Chris Wilson | b2cfe0a | 2015-04-27 13:41:16 +0100 | [diff] [blame] | 11392 | |
| 11393 | INIT_WORK(&mmio_flip->work, intel_mmio_flip_work_func); |
| 11394 | schedule_work(&mmio_flip->work); |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 11395 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 11396 | return 0; |
| 11397 | } |
| 11398 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11399 | static int intel_default_queue_flip(struct drm_device *dev, |
| 11400 | struct drm_crtc *crtc, |
| 11401 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11402 | struct drm_i915_gem_object *obj, |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11403 | struct drm_i915_gem_request *req, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11404 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11405 | { |
| 11406 | return -ENODEV; |
| 11407 | } |
| 11408 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11409 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 11410 | struct drm_crtc *crtc) |
| 11411 | { |
| 11412 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11413 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11414 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 11415 | u32 addr; |
| 11416 | |
| 11417 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 11418 | return true; |
| 11419 | |
Chris Wilson | 908565c | 2015-08-12 13:08:22 +0100 | [diff] [blame] | 11420 | if (atomic_read(&work->pending) < INTEL_FLIP_PENDING) |
| 11421 | return false; |
| 11422 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11423 | if (!work->enable_stall_check) |
| 11424 | return false; |
| 11425 | |
| 11426 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 11427 | if (work->flip_queued_req && |
| 11428 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11429 | return false; |
| 11430 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11431 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11432 | } |
| 11433 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11434 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11435 | return false; |
| 11436 | |
| 11437 | /* Potential stall - if we see that the flip has happened, |
| 11438 | * assume a missed interrupt. */ |
| 11439 | if (INTEL_INFO(dev)->gen >= 4) |
| 11440 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 11441 | else |
| 11442 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 11443 | |
| 11444 | /* There is a potential issue here with a false positive after a flip |
| 11445 | * to the same address. We could address this by checking for a |
| 11446 | * non-incrementing frame counter. |
| 11447 | */ |
| 11448 | return addr == work->gtt_offset; |
| 11449 | } |
| 11450 | |
| 11451 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 11452 | { |
| 11453 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11454 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 11455 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11456 | struct intel_unpin_work *work; |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11457 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 11458 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11459 | |
| 11460 | if (crtc == NULL) |
| 11461 | return; |
| 11462 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11463 | spin_lock(&dev->event_lock); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11464 | work = intel_crtc->unpin_work; |
| 11465 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11466 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11467 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11468 | page_flip_completed(intel_crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11469 | work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11470 | } |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 11471 | if (work != NULL && |
| 11472 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) |
| 11473 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11474 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11475 | } |
| 11476 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11477 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 11478 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 11479 | struct drm_pending_vblank_event *event, |
| 11480 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11481 | { |
| 11482 | struct drm_device *dev = crtc->dev; |
| 11483 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11484 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11485 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11486 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11487 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11488 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11489 | struct intel_unpin_work *work; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11490 | struct intel_engine_cs *engine; |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11491 | bool mmio_flip; |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11492 | struct drm_i915_gem_request *request = NULL; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 11493 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11494 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11495 | /* |
| 11496 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 11497 | * check to be safe. In the future we may enable pageflipping from |
| 11498 | * a disabled primary plane. |
| 11499 | */ |
| 11500 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 11501 | return -EBUSY; |
| 11502 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11503 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11504 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11505 | return -EINVAL; |
| 11506 | |
| 11507 | /* |
| 11508 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 11509 | * Note that pitch changes could also affect these register. |
| 11510 | */ |
| 11511 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11512 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 11513 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 11514 | return -EINVAL; |
| 11515 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11516 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 11517 | goto out_hang; |
| 11518 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 11519 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11520 | if (work == NULL) |
| 11521 | return -ENOMEM; |
| 11522 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11523 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11524 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11525 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11526 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 11527 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11528 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11529 | if (ret) |
| 11530 | goto free_work; |
| 11531 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11532 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11533 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11534 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11535 | /* Before declaring the flip queue wedged, check if |
| 11536 | * the hardware completed the operation behind our backs. |
| 11537 | */ |
| 11538 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 11539 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 11540 | page_flip_completed(intel_crtc); |
| 11541 | } else { |
| 11542 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11543 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 11544 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11545 | drm_crtc_vblank_put(crtc); |
| 11546 | kfree(work); |
| 11547 | return -EBUSY; |
| 11548 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11549 | } |
| 11550 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11551 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11552 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11553 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 11554 | flush_workqueue(dev_priv->wq); |
| 11555 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 11556 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11557 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 11558 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11559 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11560 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11561 | update_state_fb(crtc->primary); |
Paulo Zanoni | e8216e5 | 2016-01-19 11:35:56 -0200 | [diff] [blame] | 11562 | intel_fbc_pre_update(intel_crtc); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 11563 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11564 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11565 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11566 | ret = i915_mutex_lock_interruptible(dev); |
| 11567 | if (ret) |
| 11568 | goto cleanup; |
| 11569 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11570 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 11571 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 11572 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11573 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Ville Syrjälä | fd8f507c | 2015-09-18 20:03:42 +0300 | [diff] [blame] | 11574 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 11575 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 11576 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11577 | engine = &dev_priv->engine[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11578 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 11579 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11580 | engine = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 11581 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11582 | engine = &dev_priv->engine[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11583 | } else if (INTEL_INFO(dev)->gen >= 7) { |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 11584 | engine = i915_gem_request_get_engine(obj->last_write_req); |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11585 | if (engine == NULL || engine->id != RCS) |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11586 | engine = &dev_priv->engine[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11587 | } else { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 11588 | engine = &dev_priv->engine[RCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11589 | } |
| 11590 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11591 | mmio_flip = use_mmio_flip(engine, obj); |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11592 | |
| 11593 | /* When using CS flips, we want to emit semaphores between rings. |
| 11594 | * However, when using mmio flips we will create a task to do the |
| 11595 | * synchronisation, so all we want here is to pin the framebuffer |
| 11596 | * into the display plane and skip any waits. |
| 11597 | */ |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 11598 | if (!mmio_flip) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11599 | ret = i915_gem_object_sync(obj, engine, &request); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 11600 | if (ret) |
| 11601 | goto cleanup_pending; |
| 11602 | } |
| 11603 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 11604 | ret = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11605 | if (ret) |
| 11606 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11607 | |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 11608 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), |
| 11609 | obj, 0); |
| 11610 | work->gtt_offset += intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11611 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 11612 | if (mmio_flip) { |
Tvrtko Ursulin | 86efe24 | 2015-10-20 16:20:21 +0100 | [diff] [blame] | 11613 | ret = intel_queue_mmio_flip(dev, crtc, obj); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11614 | if (ret) |
| 11615 | goto cleanup_unpin; |
| 11616 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 11617 | i915_gem_request_assign(&work->flip_queued_req, |
| 11618 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11619 | } else { |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11620 | if (!request) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 11621 | request = i915_gem_request_alloc(engine, NULL); |
Dave Gordon | 2682708 | 2016-01-19 19:02:53 +0000 | [diff] [blame] | 11622 | if (IS_ERR(request)) { |
| 11623 | ret = PTR_ERR(request); |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11624 | goto cleanup_unpin; |
Dave Gordon | 2682708 | 2016-01-19 19:02:53 +0000 | [diff] [blame] | 11625 | } |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11626 | } |
| 11627 | |
| 11628 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11629 | page_flip_flags); |
| 11630 | if (ret) |
| 11631 | goto cleanup_unpin; |
| 11632 | |
John Harrison | 6258fbe | 2015-05-29 17:43:48 +0100 | [diff] [blame] | 11633 | i915_gem_request_assign(&work->flip_queued_req, request); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11634 | } |
| 11635 | |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11636 | if (request) |
John Harrison | 7528987 | 2015-05-29 17:43:49 +0100 | [diff] [blame] | 11637 | i915_add_request_no_flush(request); |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11638 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 11639 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 11640 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11641 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 11642 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11643 | to_intel_plane(primary)->frontbuffer_bit); |
Paulo Zanoni | c80ac85 | 2015-07-02 19:25:13 -0300 | [diff] [blame] | 11644 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11645 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11646 | intel_frontbuffer_flip_prepare(dev, |
| 11647 | to_intel_plane(primary)->frontbuffer_bit); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11648 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 11649 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 11650 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11651 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11652 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 11653 | cleanup_unpin: |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 11654 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 11655 | cleanup_pending: |
Dave Gordon | 0aa498d | 2016-01-28 10:48:09 +0000 | [diff] [blame] | 11656 | if (!IS_ERR_OR_NULL(request)) |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 11657 | i915_gem_request_cancel(request); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 11658 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11659 | mutex_unlock(&dev->struct_mutex); |
| 11660 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11661 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 11662 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11663 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 11664 | drm_gem_object_unreference_unlocked(&obj->base); |
| 11665 | drm_framebuffer_unreference(work->old_fb); |
| 11666 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11667 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11668 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11669 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11670 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11671 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 11672 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11673 | kfree(work); |
| 11674 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11675 | if (ret == -EIO) { |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11676 | struct drm_atomic_state *state; |
| 11677 | struct drm_plane_state *plane_state; |
| 11678 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11679 | out_hang: |
Maarten Lankhorst | 02e0efb | 2015-06-12 11:15:40 +0200 | [diff] [blame] | 11680 | state = drm_atomic_state_alloc(dev); |
| 11681 | if (!state) |
| 11682 | return -ENOMEM; |
| 11683 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 11684 | |
| 11685 | retry: |
| 11686 | plane_state = drm_atomic_get_plane_state(state, primary); |
| 11687 | ret = PTR_ERR_OR_ZERO(plane_state); |
| 11688 | if (!ret) { |
| 11689 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 11690 | |
| 11691 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 11692 | if (!ret) |
| 11693 | ret = drm_atomic_commit(state); |
| 11694 | } |
| 11695 | |
| 11696 | if (ret == -EDEADLK) { |
| 11697 | drm_modeset_backoff(state->acquire_ctx); |
| 11698 | drm_atomic_state_clear(state); |
| 11699 | goto retry; |
| 11700 | } |
| 11701 | |
| 11702 | if (ret) |
| 11703 | drm_atomic_state_free(state); |
| 11704 | |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11705 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11706 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11707 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11708 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 11709 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 11710 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 11711 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11712 | } |
| 11713 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11714 | |
| 11715 | /** |
| 11716 | * intel_wm_need_update - Check whether watermarks need updating |
| 11717 | * @plane: drm plane |
| 11718 | * @state: new plane state |
| 11719 | * |
| 11720 | * Check current plane state versus the new one to determine whether |
| 11721 | * watermarks need to be recalculated. |
| 11722 | * |
| 11723 | * Returns true or false. |
| 11724 | */ |
| 11725 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 11726 | struct drm_plane_state *state) |
| 11727 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11728 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 11729 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 11730 | |
| 11731 | /* Update watermarks on tiling or size changes. */ |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11732 | if (new->visible != cur->visible) |
| 11733 | return true; |
| 11734 | |
| 11735 | if (!cur->base.fb || !new->base.fb) |
| 11736 | return false; |
| 11737 | |
| 11738 | if (cur->base.fb->modifier[0] != new->base.fb->modifier[0] || |
| 11739 | cur->base.rotation != new->base.rotation || |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11740 | drm_rect_width(&new->src) != drm_rect_width(&cur->src) || |
| 11741 | drm_rect_height(&new->src) != drm_rect_height(&cur->src) || |
| 11742 | drm_rect_width(&new->dst) != drm_rect_width(&cur->dst) || |
| 11743 | drm_rect_height(&new->dst) != drm_rect_height(&cur->dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11744 | return true; |
| 11745 | |
| 11746 | return false; |
| 11747 | } |
| 11748 | |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 11749 | static bool needs_scaling(struct intel_plane_state *state) |
| 11750 | { |
| 11751 | int src_w = drm_rect_width(&state->src) >> 16; |
| 11752 | int src_h = drm_rect_height(&state->src) >> 16; |
| 11753 | int dst_w = drm_rect_width(&state->dst); |
| 11754 | int dst_h = drm_rect_height(&state->dst); |
| 11755 | |
| 11756 | return (src_w != dst_w || src_h != dst_h); |
| 11757 | } |
| 11758 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11759 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
| 11760 | struct drm_plane_state *plane_state) |
| 11761 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11762 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11763 | struct drm_crtc *crtc = crtc_state->crtc; |
| 11764 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11765 | struct drm_plane *plane = plane_state->plane; |
| 11766 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11767 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11768 | struct intel_plane_state *old_plane_state = |
| 11769 | to_intel_plane_state(plane->state); |
| 11770 | int idx = intel_crtc->base.base.id, ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11771 | bool mode_changed = needs_modeset(crtc_state); |
| 11772 | bool was_crtc_enabled = crtc->state->active; |
| 11773 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11774 | bool turn_off, turn_on, visible, was_visible; |
| 11775 | struct drm_framebuffer *fb = plane_state->fb; |
| 11776 | |
| 11777 | if (crtc_state && INTEL_INFO(dev)->gen >= 9 && |
| 11778 | plane->type != DRM_PLANE_TYPE_CURSOR) { |
| 11779 | ret = skl_update_scaler_plane( |
| 11780 | to_intel_crtc_state(crtc_state), |
| 11781 | to_intel_plane_state(plane_state)); |
| 11782 | if (ret) |
| 11783 | return ret; |
| 11784 | } |
| 11785 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11786 | was_visible = old_plane_state->visible; |
| 11787 | visible = to_intel_plane_state(plane_state)->visible; |
| 11788 | |
| 11789 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 11790 | was_visible = false; |
| 11791 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 11792 | /* |
| 11793 | * Visibility is calculated as if the crtc was on, but |
| 11794 | * after scaler setup everything depends on it being off |
| 11795 | * when the crtc isn't active. |
| 11796 | */ |
| 11797 | if (!is_crtc_enabled) |
| 11798 | to_intel_plane_state(plane_state)->visible = visible = false; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11799 | |
| 11800 | if (!was_visible && !visible) |
| 11801 | return 0; |
| 11802 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11803 | if (fb != old_plane_state->base.fb) |
| 11804 | pipe_config->fb_changed = true; |
| 11805 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11806 | turn_off = was_visible && (!visible || mode_changed); |
| 11807 | turn_on = visible && (!was_visible || mode_changed); |
| 11808 | |
| 11809 | DRM_DEBUG_ATOMIC("[CRTC:%i] has [PLANE:%i] with fb %i\n", idx, |
| 11810 | plane->base.id, fb ? fb->base.id : -1); |
| 11811 | |
| 11812 | DRM_DEBUG_ATOMIC("[PLANE:%i] visible %i -> %i, off %i, on %i, ms %i\n", |
| 11813 | plane->base.id, was_visible, visible, |
| 11814 | turn_off, turn_on, mode_changed); |
| 11815 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11816 | if (turn_on) { |
| 11817 | pipe_config->update_wm_pre = true; |
| 11818 | |
| 11819 | /* must disable cxsr around plane enable/disable */ |
| 11820 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 11821 | pipe_config->disable_cxsr = true; |
| 11822 | } else if (turn_off) { |
| 11823 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 11824 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11825 | /* must disable cxsr around plane enable/disable */ |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 11826 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 11827 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11828 | } else if (intel_wm_need_update(plane, plane_state)) { |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11829 | /* FIXME bollocks */ |
| 11830 | pipe_config->update_wm_pre = true; |
| 11831 | pipe_config->update_wm_post = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11832 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11833 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11834 | /* Pre-gen9 platforms need two-step watermark updates */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11835 | if ((pipe_config->update_wm_pre || pipe_config->update_wm_post) && |
| 11836 | INTEL_INFO(dev)->gen < 9 && dev_priv->display.optimize_watermarks) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11837 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; |
| 11838 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 11839 | if (visible || was_visible) |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 11840 | pipe_config->fb_bits |= to_intel_plane(plane)->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 11841 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 11842 | /* |
| 11843 | * WaCxSRDisabledForSpriteScaling:ivb |
| 11844 | * |
| 11845 | * cstate->update_wm was already set above, so this flag will |
| 11846 | * take effect when we commit and program watermarks. |
| 11847 | */ |
| 11848 | if (plane->type == DRM_PLANE_TYPE_OVERLAY && IS_IVYBRIDGE(dev) && |
| 11849 | needs_scaling(to_intel_plane_state(plane_state)) && |
| 11850 | !needs_scaling(old_plane_state)) |
| 11851 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11852 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 11853 | return 0; |
| 11854 | } |
| 11855 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11856 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 11857 | const struct intel_encoder *b) |
| 11858 | { |
| 11859 | /* masks could be asymmetric, so check both ways */ |
| 11860 | return a == b || (a->cloneable & (1 << b->type) && |
| 11861 | b->cloneable & (1 << a->type)); |
| 11862 | } |
| 11863 | |
| 11864 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 11865 | struct intel_crtc *crtc, |
| 11866 | struct intel_encoder *encoder) |
| 11867 | { |
| 11868 | struct intel_encoder *source_encoder; |
| 11869 | struct drm_connector *connector; |
| 11870 | struct drm_connector_state *connector_state; |
| 11871 | int i; |
| 11872 | |
| 11873 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11874 | if (connector_state->crtc != &crtc->base) |
| 11875 | continue; |
| 11876 | |
| 11877 | source_encoder = |
| 11878 | to_intel_encoder(connector_state->best_encoder); |
| 11879 | if (!encoders_cloneable(encoder, source_encoder)) |
| 11880 | return false; |
| 11881 | } |
| 11882 | |
| 11883 | return true; |
| 11884 | } |
| 11885 | |
| 11886 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 11887 | struct intel_crtc *crtc) |
| 11888 | { |
| 11889 | struct intel_encoder *encoder; |
| 11890 | struct drm_connector *connector; |
| 11891 | struct drm_connector_state *connector_state; |
| 11892 | int i; |
| 11893 | |
| 11894 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 11895 | if (connector_state->crtc != &crtc->base) |
| 11896 | continue; |
| 11897 | |
| 11898 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 11899 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
| 11900 | return false; |
| 11901 | } |
| 11902 | |
| 11903 | return true; |
| 11904 | } |
| 11905 | |
| 11906 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 11907 | struct drm_crtc_state *crtc_state) |
| 11908 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11909 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11910 | struct drm_i915_private *dev_priv = dev->dev_private; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11911 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 11912 | struct intel_crtc_state *pipe_config = |
| 11913 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11914 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 11915 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11916 | bool mode_changed = needs_modeset(crtc_state); |
| 11917 | |
| 11918 | if (mode_changed && !check_encoder_cloning(state, intel_crtc)) { |
| 11919 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 11920 | return -EINVAL; |
| 11921 | } |
| 11922 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 11923 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 11924 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 11925 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11926 | if (mode_changed && crtc_state->enable && |
| 11927 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 11928 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 11929 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11930 | pipe_config); |
| 11931 | if (ret) |
| 11932 | return ret; |
| 11933 | } |
| 11934 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 11935 | if (crtc_state->color_mgmt_changed) { |
| 11936 | ret = intel_color_check(crtc, crtc_state); |
| 11937 | if (ret) |
| 11938 | return ret; |
| 11939 | } |
| 11940 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11941 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11942 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 11943 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11944 | if (ret) { |
| 11945 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11946 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 11947 | } |
| 11948 | } |
| 11949 | |
| 11950 | if (dev_priv->display.compute_intermediate_wm && |
| 11951 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 11952 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 11953 | return 0; |
| 11954 | |
| 11955 | /* |
| 11956 | * Calculate 'intermediate' watermarks that satisfy both the |
| 11957 | * old state and the new state. We can program these |
| 11958 | * immediately. |
| 11959 | */ |
| 11960 | ret = dev_priv->display.compute_intermediate_wm(crtc->dev, |
| 11961 | intel_crtc, |
| 11962 | pipe_config); |
| 11963 | if (ret) { |
| 11964 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 11965 | return ret; |
| 11966 | } |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 11967 | } |
| 11968 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 11969 | if (INTEL_INFO(dev)->gen >= 9) { |
| 11970 | if (mode_changed) |
| 11971 | ret = skl_update_scaler_crtc(pipe_config); |
| 11972 | |
| 11973 | if (!ret) |
| 11974 | ret = intel_atomic_setup_scalers(dev, intel_crtc, |
| 11975 | pipe_config); |
| 11976 | } |
| 11977 | |
| 11978 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11979 | } |
| 11980 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 11981 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11982 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 11983 | .atomic_begin = intel_begin_crtc_commit, |
| 11984 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 11985 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11986 | }; |
| 11987 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 11988 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 11989 | { |
| 11990 | struct intel_connector *connector; |
| 11991 | |
| 11992 | for_each_intel_connector(dev, connector) { |
| 11993 | if (connector->base.encoder) { |
| 11994 | connector->base.state->best_encoder = |
| 11995 | connector->base.encoder; |
| 11996 | connector->base.state->crtc = |
| 11997 | connector->base.encoder->crtc; |
| 11998 | } else { |
| 11999 | connector->base.state->best_encoder = NULL; |
| 12000 | connector->base.state->crtc = NULL; |
| 12001 | } |
| 12002 | } |
| 12003 | } |
| 12004 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12005 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 12006 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12007 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12008 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12009 | int bpp = pipe_config->pipe_bpp; |
| 12010 | |
| 12011 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 12012 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12013 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12014 | |
| 12015 | /* Don't use an invalid EDID bpc value */ |
| 12016 | if (connector->base.display_info.bpc && |
| 12017 | connector->base.display_info.bpc * 3 < bpp) { |
| 12018 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 12019 | bpp, connector->base.display_info.bpc*3); |
| 12020 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 12021 | } |
| 12022 | |
Jani Nikula | 013dd9e | 2016-01-13 16:35:20 +0200 | [diff] [blame] | 12023 | /* Clamp bpp to default limit on screens without EDID 1.4 */ |
| 12024 | if (connector->base.display_info.bpc == 0) { |
| 12025 | int type = connector->base.connector_type; |
| 12026 | int clamp_bpp = 24; |
| 12027 | |
| 12028 | /* Fall back to 18 bpp when DP sink capability is unknown. */ |
| 12029 | if (type == DRM_MODE_CONNECTOR_DisplayPort || |
| 12030 | type == DRM_MODE_CONNECTOR_eDP) |
| 12031 | clamp_bpp = 18; |
| 12032 | |
| 12033 | if (bpp > clamp_bpp) { |
| 12034 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of %d\n", |
| 12035 | bpp, clamp_bpp); |
| 12036 | pipe_config->pipe_bpp = clamp_bpp; |
| 12037 | } |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12038 | } |
| 12039 | } |
| 12040 | |
| 12041 | static int |
| 12042 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12043 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12044 | { |
| 12045 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12046 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12047 | struct drm_connector *connector; |
| 12048 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12049 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12050 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 12051 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12052 | bpp = 10*3; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12053 | else if (INTEL_INFO(dev)->gen >= 5) |
| 12054 | bpp = 12*3; |
| 12055 | else |
| 12056 | bpp = 8*3; |
| 12057 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12058 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12059 | pipe_config->pipe_bpp = bpp; |
| 12060 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12061 | state = pipe_config->base.state; |
| 12062 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12063 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12064 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12065 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12066 | continue; |
| 12067 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12068 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 12069 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12070 | } |
| 12071 | |
| 12072 | return bpp; |
| 12073 | } |
| 12074 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12075 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 12076 | { |
| 12077 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 12078 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 12079 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12080 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 12081 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 12082 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 12083 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 12084 | } |
| 12085 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12086 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12087 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12088 | const char *context) |
| 12089 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12090 | struct drm_device *dev = crtc->base.dev; |
| 12091 | struct drm_plane *plane; |
| 12092 | struct intel_plane *intel_plane; |
| 12093 | struct intel_plane_state *state; |
| 12094 | struct drm_framebuffer *fb; |
| 12095 | |
| 12096 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 12097 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12098 | |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 12099 | DRM_DEBUG_KMS("cpu_transcoder: %s\n", transcoder_name(pipe_config->cpu_transcoder)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12100 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 12101 | pipe_config->pipe_bpp, pipe_config->dither); |
| 12102 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 12103 | pipe_config->has_pch_encoder, |
| 12104 | pipe_config->fdi_lanes, |
| 12105 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 12106 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 12107 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12108 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12109 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12110 | pipe_config->lane_count, |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12111 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 12112 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 12113 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12114 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12115 | DRM_DEBUG_KMS("dp: %i, lanes: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12116 | pipe_config->has_dp_encoder, |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12117 | pipe_config->lane_count, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12118 | pipe_config->dp_m2_n2.gmch_m, |
| 12119 | pipe_config->dp_m2_n2.gmch_n, |
| 12120 | pipe_config->dp_m2_n2.link_m, |
| 12121 | pipe_config->dp_m2_n2.link_n, |
| 12122 | pipe_config->dp_m2_n2.tu); |
| 12123 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 12124 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 12125 | pipe_config->has_audio, |
| 12126 | pipe_config->has_infoframe); |
| 12127 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12128 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12129 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12130 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12131 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 12132 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 12133 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 12134 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 12135 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Tvrtko Ursulin | 0ec463d | 2015-05-13 16:51:08 +0100 | [diff] [blame] | 12136 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 12137 | crtc->num_scalers, |
| 12138 | pipe_config->scaler_state.scaler_users, |
| 12139 | pipe_config->scaler_state.scaler_id); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12140 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 12141 | pipe_config->gmch_pfit.control, |
| 12142 | pipe_config->gmch_pfit.pgm_ratios, |
| 12143 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12144 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12145 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 12146 | pipe_config->pch_pfit.size, |
| 12147 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12148 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 12149 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12150 | |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12151 | if (IS_BROXTON(dev)) { |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12152 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: ebb0: 0x%x, ebb4: 0x%x," |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12153 | "pll0: 0x%x, pll1: 0x%x, pll2: 0x%x, pll3: 0x%x, " |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12154 | "pll6: 0x%x, pll8: 0x%x, pll9: 0x%x, pll10: 0x%x, pcsdw12: 0x%x\n", |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12155 | pipe_config->ddi_pll_sel, |
| 12156 | pipe_config->dpll_hw_state.ebb0, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12157 | pipe_config->dpll_hw_state.ebb4, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12158 | pipe_config->dpll_hw_state.pll0, |
| 12159 | pipe_config->dpll_hw_state.pll1, |
| 12160 | pipe_config->dpll_hw_state.pll2, |
| 12161 | pipe_config->dpll_hw_state.pll3, |
| 12162 | pipe_config->dpll_hw_state.pll6, |
| 12163 | pipe_config->dpll_hw_state.pll8, |
Imre Deak | 05712c1 | 2015-06-18 17:25:54 +0300 | [diff] [blame] | 12164 | pipe_config->dpll_hw_state.pll9, |
Imre Deak | c845333 | 2015-06-18 17:25:55 +0300 | [diff] [blame] | 12165 | pipe_config->dpll_hw_state.pll10, |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12166 | pipe_config->dpll_hw_state.pcsdw12); |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 12167 | } else if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) { |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12168 | DRM_DEBUG_KMS("ddi_pll_sel: %u; dpll_hw_state: " |
| 12169 | "ctrl1: 0x%x, cfgcr1: 0x%x, cfgcr2: 0x%x\n", |
| 12170 | pipe_config->ddi_pll_sel, |
| 12171 | pipe_config->dpll_hw_state.ctrl1, |
| 12172 | pipe_config->dpll_hw_state.cfgcr1, |
| 12173 | pipe_config->dpll_hw_state.cfgcr2); |
| 12174 | } else if (HAS_DDI(dev)) { |
Ville Syrjälä | 1260f07 | 2016-02-17 21:41:08 +0200 | [diff] [blame] | 12175 | DRM_DEBUG_KMS("ddi_pll_sel: 0x%x; dpll_hw_state: wrpll: 0x%x spll: 0x%x\n", |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12176 | pipe_config->ddi_pll_sel, |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12177 | pipe_config->dpll_hw_state.wrpll, |
| 12178 | pipe_config->dpll_hw_state.spll); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12179 | } else { |
| 12180 | DRM_DEBUG_KMS("dpll_hw_state: dpll: 0x%x, dpll_md: 0x%x, " |
| 12181 | "fp0: 0x%x, fp1: 0x%x\n", |
| 12182 | pipe_config->dpll_hw_state.dpll, |
| 12183 | pipe_config->dpll_hw_state.dpll_md, |
| 12184 | pipe_config->dpll_hw_state.fp0, |
| 12185 | pipe_config->dpll_hw_state.fp1); |
| 12186 | } |
| 12187 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12188 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 12189 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 12190 | intel_plane = to_intel_plane(plane); |
| 12191 | if (intel_plane->pipe != crtc->pipe) |
| 12192 | continue; |
| 12193 | |
| 12194 | state = to_intel_plane_state(plane->state); |
| 12195 | fb = state->base.fb; |
| 12196 | if (!fb) { |
| 12197 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 12198 | "disabled, scaler_id = %d\n", |
| 12199 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12200 | plane->base.id, intel_plane->pipe, |
| 12201 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 12202 | drm_plane_index(plane), state->scaler_id); |
| 12203 | continue; |
| 12204 | } |
| 12205 | |
| 12206 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 12207 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 12208 | plane->base.id, intel_plane->pipe, |
| 12209 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 12210 | drm_plane_index(plane)); |
| 12211 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 12212 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 12213 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 12214 | state->scaler_id, |
| 12215 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 12216 | drm_rect_width(&state->src) >> 16, |
| 12217 | drm_rect_height(&state->src) >> 16, |
| 12218 | state->dst.x1, state->dst.y1, |
| 12219 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 12220 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12221 | } |
| 12222 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12223 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12224 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12225 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12226 | struct drm_connector *connector; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12227 | unsigned int used_ports = 0; |
| 12228 | |
| 12229 | /* |
| 12230 | * Walk the connector list instead of the encoder |
| 12231 | * list to detect the problem on ddi platforms |
| 12232 | * where there's just one encoder per digital port. |
| 12233 | */ |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 12234 | drm_for_each_connector(connector, dev) { |
| 12235 | struct drm_connector_state *connector_state; |
| 12236 | struct intel_encoder *encoder; |
| 12237 | |
| 12238 | connector_state = drm_atomic_get_existing_connector_state(state, connector); |
| 12239 | if (!connector_state) |
| 12240 | connector_state = connector->state; |
| 12241 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12242 | if (!connector_state->best_encoder) |
| 12243 | continue; |
| 12244 | |
| 12245 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12246 | |
| 12247 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12248 | |
| 12249 | switch (encoder->type) { |
| 12250 | unsigned int port_mask; |
| 12251 | case INTEL_OUTPUT_UNKNOWN: |
| 12252 | if (WARN_ON(!HAS_DDI(dev))) |
| 12253 | break; |
| 12254 | case INTEL_OUTPUT_DISPLAYPORT: |
| 12255 | case INTEL_OUTPUT_HDMI: |
| 12256 | case INTEL_OUTPUT_EDP: |
| 12257 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 12258 | |
| 12259 | /* the same port mustn't appear more than once */ |
| 12260 | if (used_ports & port_mask) |
| 12261 | return false; |
| 12262 | |
| 12263 | used_ports |= port_mask; |
| 12264 | default: |
| 12265 | break; |
| 12266 | } |
| 12267 | } |
| 12268 | |
| 12269 | return true; |
| 12270 | } |
| 12271 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12272 | static void |
| 12273 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 12274 | { |
| 12275 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12276 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12277 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12278 | struct intel_shared_dpll *shared_dpll; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12279 | uint32_t ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12280 | bool force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12281 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 12282 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 12283 | * kzalloc'd. Code that depends on any field being zero should be |
| 12284 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 12285 | * only fields that are know to not cause problems are preserved. */ |
| 12286 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12287 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12288 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12289 | shared_dpll = crtc_state->shared_dpll; |
| 12290 | dpll_hw_state = crtc_state->dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12291 | ddi_pll_sel = crtc_state->ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12292 | force_thru = crtc_state->pch_pfit.force_thru; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12293 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12294 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12295 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12296 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12297 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12298 | crtc_state->shared_dpll = shared_dpll; |
| 12299 | crtc_state->dpll_hw_state = dpll_hw_state; |
Ander Conselvan de Oliveira | 8504c74 | 2015-05-15 11:51:50 +0300 | [diff] [blame] | 12300 | crtc_state->ddi_pll_sel = ddi_pll_sel; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12301 | crtc_state->pch_pfit.force_thru = force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12302 | } |
| 12303 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12304 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12305 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12306 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12307 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12308 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12309 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12310 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12311 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12312 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12313 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12314 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12315 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12316 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12317 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 12318 | pipe_config->cpu_transcoder = |
| 12319 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12320 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12321 | /* |
| 12322 | * Sanitize sync polarity flags based on requested ones. If neither |
| 12323 | * positive or negative polarity is requested, treat this as meaning |
| 12324 | * negative polarity. |
| 12325 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12326 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12327 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12328 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12329 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12330 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12331 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12332 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12333 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12334 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 12335 | pipe_config); |
| 12336 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12337 | goto fail; |
| 12338 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12339 | /* |
| 12340 | * Determine the real pipe dimensions. Note that stereo modes can |
| 12341 | * increase the actual pipe size due to the frame doubling and |
| 12342 | * insertion of additional space for blanks between the frame. This |
| 12343 | * is stored in the crtc timings. We use the requested mode to do this |
| 12344 | * computation to clearly distinguish it from the adjusted mode, which |
| 12345 | * can be changed by the connectors in the below retry loop. |
| 12346 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12347 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 12348 | &pipe_config->pipe_src_w, |
| 12349 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12350 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12351 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12352 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12353 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 12354 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12355 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12356 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12357 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 12358 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 12359 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12360 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 12361 | * adjust it according to limitations or connector properties, and also |
| 12362 | * a chance to reject the mode entirely. |
| 12363 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12364 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12365 | if (connector_state->crtc != crtc) |
| 12366 | continue; |
| 12367 | |
| 12368 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12369 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 12370 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 12371 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12372 | goto fail; |
| 12373 | } |
| 12374 | } |
| 12375 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12376 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 12377 | * done afterwards in case the encoder adjusts the mode. */ |
| 12378 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12379 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 12380 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 12381 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 12382 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12383 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12384 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 12385 | goto fail; |
| 12386 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12387 | |
| 12388 | if (ret == RETRY) { |
| 12389 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 12390 | ret = -EINVAL; |
| 12391 | goto fail; |
| 12392 | } |
| 12393 | |
| 12394 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 12395 | retry = false; |
| 12396 | goto encoder_retry; |
| 12397 | } |
| 12398 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 12399 | /* Dithering seems to not pass-through bits correctly when it should, so |
| 12400 | * only enable it on 6bpc panels. */ |
| 12401 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 12402 | 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] | 12403 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12404 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12405 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12406 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12407 | } |
| 12408 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12409 | static void |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 12410 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12411 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 12412 | struct drm_crtc *crtc; |
| 12413 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12414 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12415 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12416 | /* Double check state. */ |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 12417 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 3cb480b | 2015-06-01 12:49:49 +0200 | [diff] [blame] | 12418 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 12419 | |
| 12420 | /* Update hwmode for vblank functions */ |
| 12421 | if (crtc->state->active) |
| 12422 | crtc->hwmode = crtc->state->adjusted_mode; |
| 12423 | else |
| 12424 | crtc->hwmode.crtc_clock = 0; |
Maarten Lankhorst | 61067a5 | 2015-09-23 16:29:36 +0200 | [diff] [blame] | 12425 | |
| 12426 | /* |
| 12427 | * Update legacy state to satisfy fbc code. This can |
| 12428 | * be removed when fbc uses the atomic state. |
| 12429 | */ |
| 12430 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { |
| 12431 | struct drm_plane_state *plane_state = crtc->primary->state; |
| 12432 | |
| 12433 | crtc->primary->fb = plane_state->fb; |
| 12434 | crtc->x = plane_state->src_x >> 16; |
| 12435 | crtc->y = plane_state->src_y >> 16; |
| 12436 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12437 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 12438 | } |
| 12439 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12440 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12441 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 12442 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 12443 | |
| 12444 | if (clock1 == clock2) |
| 12445 | return true; |
| 12446 | |
| 12447 | if (!clock1 || !clock2) |
| 12448 | return false; |
| 12449 | |
| 12450 | diff = abs(clock1 - clock2); |
| 12451 | |
| 12452 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 12453 | return true; |
| 12454 | |
| 12455 | return false; |
| 12456 | } |
| 12457 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12458 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 12459 | list_for_each_entry((intel_crtc), \ |
| 12460 | &(dev)->mode_config.crtc_list, \ |
| 12461 | base.head) \ |
Jani Nikula | 95150bd | 2015-11-24 21:21:56 +0200 | [diff] [blame] | 12462 | for_each_if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 12463 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12464 | static bool |
| 12465 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 12466 | unsigned int m2, unsigned int n2, |
| 12467 | bool exact) |
| 12468 | { |
| 12469 | if (m == m2 && n == n2) |
| 12470 | return true; |
| 12471 | |
| 12472 | if (exact || !m || !n || !m2 || !n2) |
| 12473 | return false; |
| 12474 | |
| 12475 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 12476 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12477 | if (n > n2) { |
| 12478 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12479 | m2 <<= 1; |
| 12480 | n2 <<= 1; |
| 12481 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12482 | } else if (n < n2) { |
| 12483 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12484 | m <<= 1; |
| 12485 | n <<= 1; |
| 12486 | } |
| 12487 | } |
| 12488 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 12489 | if (n != n2) |
| 12490 | return false; |
| 12491 | |
| 12492 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12493 | } |
| 12494 | |
| 12495 | static bool |
| 12496 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 12497 | struct intel_link_m_n *m2_n2, |
| 12498 | bool adjust) |
| 12499 | { |
| 12500 | if (m_n->tu == m2_n2->tu && |
| 12501 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 12502 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 12503 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 12504 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 12505 | if (adjust) |
| 12506 | *m2_n2 = *m_n; |
| 12507 | |
| 12508 | return true; |
| 12509 | } |
| 12510 | |
| 12511 | return false; |
| 12512 | } |
| 12513 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12514 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12515 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12516 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12517 | struct intel_crtc_state *pipe_config, |
| 12518 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12519 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12520 | bool ret = true; |
| 12521 | |
| 12522 | #define INTEL_ERR_OR_DBG_KMS(fmt, ...) \ |
| 12523 | do { \ |
| 12524 | if (!adjust) \ |
| 12525 | DRM_ERROR(fmt, ##__VA_ARGS__); \ |
| 12526 | else \ |
| 12527 | DRM_DEBUG_KMS(fmt, ##__VA_ARGS__); \ |
| 12528 | } while (0) |
| 12529 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12530 | #define PIPE_CONF_CHECK_X(name) \ |
| 12531 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12532 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12533 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 12534 | current_config->name, \ |
| 12535 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12536 | ret = false; \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12537 | } |
| 12538 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12539 | #define PIPE_CONF_CHECK_I(name) \ |
| 12540 | if (current_config->name != pipe_config->name) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12541 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12542 | "(expected %i, found %i)\n", \ |
| 12543 | current_config->name, \ |
| 12544 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12545 | ret = false; \ |
| 12546 | } |
| 12547 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12548 | #define PIPE_CONF_CHECK_P(name) \ |
| 12549 | if (current_config->name != pipe_config->name) { \ |
| 12550 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12551 | "(expected %p, found %p)\n", \ |
| 12552 | current_config->name, \ |
| 12553 | pipe_config->name); \ |
| 12554 | ret = false; \ |
| 12555 | } |
| 12556 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12557 | #define PIPE_CONF_CHECK_M_N(name) \ |
| 12558 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12559 | &pipe_config->name,\ |
| 12560 | adjust)) { \ |
| 12561 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12562 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12563 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12564 | current_config->name.tu, \ |
| 12565 | current_config->name.gmch_m, \ |
| 12566 | current_config->name.gmch_n, \ |
| 12567 | current_config->name.link_m, \ |
| 12568 | current_config->name.link_n, \ |
| 12569 | pipe_config->name.tu, \ |
| 12570 | pipe_config->name.gmch_m, \ |
| 12571 | pipe_config->name.gmch_n, \ |
| 12572 | pipe_config->name.link_m, \ |
| 12573 | pipe_config->name.link_n); \ |
| 12574 | ret = false; \ |
| 12575 | } |
| 12576 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 12577 | /* This is required for BDW+ where there is only one set of registers for |
| 12578 | * switching between high and low RR. |
| 12579 | * This macro can be used whenever a comparison has to be made between one |
| 12580 | * hw state and multiple sw state variables. |
| 12581 | */ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12582 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
| 12583 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 12584 | &pipe_config->name, adjust) && \ |
| 12585 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 12586 | &pipe_config->name, adjust)) { \ |
| 12587 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
| 12588 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 12589 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 12590 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 12591 | current_config->name.tu, \ |
| 12592 | current_config->name.gmch_m, \ |
| 12593 | current_config->name.gmch_n, \ |
| 12594 | current_config->name.link_m, \ |
| 12595 | current_config->name.link_n, \ |
| 12596 | current_config->alt_name.tu, \ |
| 12597 | current_config->alt_name.gmch_m, \ |
| 12598 | current_config->alt_name.gmch_n, \ |
| 12599 | current_config->alt_name.link_m, \ |
| 12600 | current_config->alt_name.link_n, \ |
| 12601 | pipe_config->name.tu, \ |
| 12602 | pipe_config->name.gmch_m, \ |
| 12603 | pipe_config->name.gmch_n, \ |
| 12604 | pipe_config->name.link_m, \ |
| 12605 | pipe_config->name.link_n); \ |
| 12606 | ret = false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 12607 | } |
| 12608 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12609 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 12610 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12611 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12612 | "(expected %i, found %i)\n", \ |
| 12613 | current_config->name & (mask), \ |
| 12614 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12615 | ret = false; \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12616 | } |
| 12617 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12618 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 12619 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12620 | INTEL_ERR_OR_DBG_KMS("mismatch in " #name " " \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12621 | "(expected %i, found %i)\n", \ |
| 12622 | current_config->name, \ |
| 12623 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12624 | ret = false; \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12625 | } |
| 12626 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12627 | #define PIPE_CONF_QUIRK(quirk) \ |
| 12628 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 12629 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 12630 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 12631 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12632 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 12633 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12634 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12635 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 12636 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 12637 | PIPE_CONF_CHECK_I(lane_count); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12638 | |
| 12639 | if (INTEL_INFO(dev)->gen < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12640 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12641 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12642 | if (current_config->has_drrs) |
| 12643 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 12644 | } else |
| 12645 | 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] | 12646 | |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 12647 | PIPE_CONF_CHECK_I(has_dsi_encoder); |
| 12648 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12649 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 12650 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 12651 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 12652 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 12653 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 12654 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12655 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12656 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 12657 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 12658 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 12659 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 12660 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 12661 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12662 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 12663 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 12664 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12665 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 12666 | IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 12667 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 12668 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 12669 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 12670 | PIPE_CONF_CHECK_I(has_audio); |
| 12671 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12672 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12673 | DRM_MODE_FLAG_INTERLACE); |
| 12674 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12675 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12676 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12677 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12678 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12679 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12680 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12681 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12682 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12683 | DRM_MODE_FLAG_NVSYNC); |
| 12684 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 12685 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12686 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 12687 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 12688 | if (INTEL_INFO(dev)->gen < 4) |
| 12689 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 12690 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 12691 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12692 | if (!adjust) { |
| 12693 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 12694 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 12695 | |
| 12696 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 12697 | if (current_config->pch_pfit.enabled) { |
| 12698 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 12699 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 12700 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 12701 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 12702 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 12703 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 12704 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 12705 | /* BDW+ don't expose a synchronous way to read the state */ |
| 12706 | if (IS_HASWELL(dev)) |
| 12707 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 12708 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 12709 | PIPE_CONF_CHECK_I(double_wide); |
| 12710 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 12711 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 12712 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12713 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12714 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 12715 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12716 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 12717 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 12718 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 12719 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 12720 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 12721 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 12722 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 12723 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 12724 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 12725 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 12726 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12727 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 12728 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12729 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12730 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 12731 | #undef PIPE_CONF_CHECK_I |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12732 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 12733 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 12734 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 12735 | #undef PIPE_CONF_QUIRK |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12736 | #undef INTEL_ERR_OR_DBG_KMS |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 12737 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12738 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12739 | } |
| 12740 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12741 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 12742 | const struct intel_crtc_state *pipe_config) |
| 12743 | { |
| 12744 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 12745 | 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] | 12746 | &pipe_config->fdi_m_n); |
| 12747 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 12748 | |
| 12749 | /* |
| 12750 | * FDI already provided one idea for the dotclock. |
| 12751 | * Yell if the encoder disagrees. |
| 12752 | */ |
| 12753 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 12754 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 12755 | fdi_dotclock, dotclock); |
| 12756 | } |
| 12757 | } |
| 12758 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12759 | static void check_wm_state(struct drm_device *dev) |
| 12760 | { |
| 12761 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12762 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 12763 | struct intel_crtc *intel_crtc; |
| 12764 | int plane; |
| 12765 | |
| 12766 | if (INTEL_INFO(dev)->gen < 9) |
| 12767 | return; |
| 12768 | |
| 12769 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 12770 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 12771 | |
| 12772 | for_each_intel_crtc(dev, intel_crtc) { |
| 12773 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 12774 | const enum pipe pipe = intel_crtc->pipe; |
| 12775 | |
| 12776 | if (!intel_crtc->active) |
| 12777 | continue; |
| 12778 | |
| 12779 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 12780 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12781 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 12782 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 12783 | |
| 12784 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12785 | continue; |
| 12786 | |
| 12787 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 12788 | "(expected (%u,%u), found (%u,%u))\n", |
| 12789 | pipe_name(pipe), plane + 1, |
| 12790 | sw_entry->start, sw_entry->end, |
| 12791 | hw_entry->start, hw_entry->end); |
| 12792 | } |
| 12793 | |
| 12794 | /* cursor */ |
Matt Roper | 4969d33 | 2015-09-24 15:53:10 -0700 | [diff] [blame] | 12795 | hw_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 12796 | sw_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 12797 | |
| 12798 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 12799 | continue; |
| 12800 | |
| 12801 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 12802 | "(expected (%u,%u), found (%u,%u))\n", |
| 12803 | pipe_name(pipe), |
| 12804 | sw_entry->start, sw_entry->end, |
| 12805 | hw_entry->start, hw_entry->end); |
| 12806 | } |
| 12807 | } |
| 12808 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12809 | static void |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12810 | check_connector_state(struct drm_device *dev, |
| 12811 | struct drm_atomic_state *old_state) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12812 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12813 | struct drm_connector_state *old_conn_state; |
| 12814 | struct drm_connector *connector; |
| 12815 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12816 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12817 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 12818 | struct drm_encoder *encoder = connector->encoder; |
| 12819 | struct drm_connector_state *state = connector->state; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12820 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12821 | /* This also checks the encoder/connector hw state with the |
| 12822 | * ->get_hw_state callbacks. */ |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12823 | intel_connector_check_state(to_intel_connector(connector)); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12824 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12825 | I915_STATE_WARN(state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 12826 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12827 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12828 | } |
| 12829 | |
| 12830 | static void |
| 12831 | check_encoder_state(struct drm_device *dev) |
| 12832 | { |
| 12833 | struct intel_encoder *encoder; |
| 12834 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12835 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12836 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12837 | bool enabled = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12838 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12839 | |
| 12840 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 12841 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 12842 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12843 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12844 | for_each_intel_connector(dev, connector) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12845 | if (connector->base.state->best_encoder != &encoder->base) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12846 | continue; |
| 12847 | enabled = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 12848 | |
| 12849 | I915_STATE_WARN(connector->base.state->crtc != |
| 12850 | encoder->base.crtc, |
| 12851 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12852 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12853 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12854 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12855 | "encoder's enabled state mismatch " |
| 12856 | "(expected %i, found %i)\n", |
| 12857 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12858 | |
| 12859 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12860 | bool active; |
| 12861 | |
| 12862 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12863 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12864 | "encoder detached but still enabled on pipe %c.\n", |
| 12865 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 12866 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12867 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12868 | } |
| 12869 | |
| 12870 | static void |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12871 | check_crtc_state(struct drm_device *dev, struct drm_atomic_state *old_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12872 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12873 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12874 | struct intel_encoder *encoder; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12875 | struct drm_crtc_state *old_crtc_state; |
| 12876 | struct drm_crtc *crtc; |
| 12877 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12878 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12879 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 12880 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12881 | struct intel_crtc_state *pipe_config, *sw_config; |
Maarten Lankhorst | 7b89b8d | 2015-08-05 12:37:03 +0200 | [diff] [blame] | 12882 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12883 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 12884 | if (!needs_modeset(crtc->state) && |
| 12885 | !to_intel_crtc_state(crtc->state)->update_pipe) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 12886 | continue; |
| 12887 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12888 | __drm_atomic_helper_crtc_destroy_state(crtc, old_crtc_state); |
| 12889 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 12890 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 12891 | pipe_config->base.crtc = crtc; |
| 12892 | pipe_config->base.state = old_state; |
| 12893 | |
| 12894 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 12895 | crtc->base.id); |
| 12896 | |
| 12897 | active = dev_priv->display.get_pipe_config(intel_crtc, |
| 12898 | pipe_config); |
| 12899 | |
| 12900 | /* hw state is inconsistent with the pipe quirk */ |
| 12901 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 12902 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 12903 | active = crtc->state->active; |
| 12904 | |
| 12905 | I915_STATE_WARN(crtc->state->active != active, |
| 12906 | "crtc active state doesn't match with hw state " |
| 12907 | "(expected %i, found %i)\n", crtc->state->active, active); |
| 12908 | |
| 12909 | I915_STATE_WARN(intel_crtc->active != crtc->state->active, |
| 12910 | "transitional active state does not match atomic hw state " |
| 12911 | "(expected %i, found %i)\n", crtc->state->active, intel_crtc->active); |
| 12912 | |
| 12913 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 12914 | enum pipe pipe; |
| 12915 | |
| 12916 | active = encoder->get_hw_state(encoder, &pipe); |
| 12917 | I915_STATE_WARN(active != crtc->state->active, |
| 12918 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 12919 | encoder->base.base.id, active, crtc->state->active); |
| 12920 | |
| 12921 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 12922 | "Encoder connected to wrong pipe %c\n", |
| 12923 | pipe_name(pipe)); |
| 12924 | |
| 12925 | if (active) |
| 12926 | encoder->get_config(encoder, pipe_config); |
| 12927 | } |
| 12928 | |
| 12929 | if (!crtc->state->active) |
| 12930 | continue; |
| 12931 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 12932 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
| 12933 | |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12934 | sw_config = to_intel_crtc_state(crtc->state); |
| 12935 | if (!intel_pipe_config_compare(dev, sw_config, |
| 12936 | pipe_config, false)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12937 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12938 | intel_dump_pipe_config(intel_crtc, pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12939 | "[hw state]"); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12940 | intel_dump_pipe_config(intel_crtc, sw_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12941 | "[sw state]"); |
| 12942 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 12943 | } |
| 12944 | } |
| 12945 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12946 | static void |
| 12947 | check_shared_dpll_state(struct drm_device *dev) |
| 12948 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12949 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 12950 | struct intel_crtc *crtc; |
| 12951 | struct intel_dpll_hw_state dpll_hw_state; |
| 12952 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12953 | |
| 12954 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12955 | struct intel_shared_dpll *pll = |
| 12956 | intel_get_shared_dpll_by_id(dev_priv, i); |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12957 | unsigned enabled_crtcs = 0, active_crtcs = 0; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12958 | bool active; |
| 12959 | |
| 12960 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 12961 | |
| 12962 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 12963 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 12964 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12965 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12966 | I915_STATE_WARN(pll->active_mask & ~pll->config.crtc_mask, |
| 12967 | "more active pll users than references: %x vs %x\n", |
| 12968 | pll->active_mask, pll->config.crtc_mask); |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 12969 | |
| 12970 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12971 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 12972 | "pll in active use but not on in sw tracking\n"); |
| 12973 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 12974 | "pll is on but not used by any active crtc\n"); |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 12975 | I915_STATE_WARN(pll->on != active, |
| 12976 | "pll on state mismatch (expected %i, found %i)\n", |
| 12977 | pll->on, active); |
| 12978 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12979 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12980 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12981 | if (crtc->base.state->enable && crtc->config->shared_dpll == pll) |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12982 | enabled_crtcs |= 1 << drm_crtc_index(&crtc->base); |
| 12983 | if (crtc->base.state->active && crtc->config->shared_dpll == pll) |
| 12984 | active_crtcs |= 1 << drm_crtc_index(&crtc->base); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12985 | } |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 12986 | |
| 12987 | I915_STATE_WARN(pll->active_mask != active_crtcs, |
| 12988 | "pll active crtcs mismatch (expected %x, found %x)\n", |
| 12989 | pll->active_mask, active_crtcs); |
| 12990 | I915_STATE_WARN(pll->config.crtc_mask != enabled_crtcs, |
| 12991 | "pll enabled crtcs mismatch (expected %x, found %x)\n", |
| 12992 | pll->config.crtc_mask, enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12993 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 12994 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12995 | sizeof(dpll_hw_state)), |
| 12996 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12997 | } |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 12998 | } |
| 12999 | |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 13000 | static void |
| 13001 | intel_modeset_check_state(struct drm_device *dev, |
| 13002 | struct drm_atomic_state *old_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13003 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13004 | check_wm_state(dev); |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 13005 | check_connector_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13006 | check_encoder_state(dev); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13007 | check_crtc_state(dev, old_state); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13008 | check_shared_dpll_state(dev); |
| 13009 | } |
| 13010 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13011 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 13012 | { |
| 13013 | struct drm_device *dev = crtc->base.dev; |
| 13014 | |
| 13015 | /* |
| 13016 | * The scanline counter increments at the leading edge of hsync. |
| 13017 | * |
| 13018 | * On most platforms it starts counting from vtotal-1 on the |
| 13019 | * first active line. That means the scanline counter value is |
| 13020 | * always one less than what we would expect. Ie. just after |
| 13021 | * start of vblank, which also occurs at start of hsync (on the |
| 13022 | * last active line), the scanline counter will read vblank_start-1. |
| 13023 | * |
| 13024 | * On gen2 the scanline counter starts counting from 1 instead |
| 13025 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 13026 | * to keep the value positive), instead of adding one. |
| 13027 | * |
| 13028 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 13029 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 13030 | * there's an extra 1 line difference. So we need to add two instead of |
| 13031 | * one to the value. |
| 13032 | */ |
| 13033 | if (IS_GEN2(dev)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13034 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13035 | int vtotal; |
| 13036 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13037 | vtotal = adjusted_mode->crtc_vtotal; |
| 13038 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13039 | vtotal /= 2; |
| 13040 | |
| 13041 | crtc->scanline_offset = vtotal - 1; |
| 13042 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 13043 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13044 | crtc->scanline_offset = 2; |
| 13045 | } else |
| 13046 | crtc->scanline_offset = 1; |
| 13047 | } |
| 13048 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13049 | 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] | 13050 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13051 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13052 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13053 | struct intel_shared_dpll_config *shared_dpll = NULL; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13054 | struct drm_crtc *crtc; |
| 13055 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13056 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13057 | |
| 13058 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13059 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13060 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13061 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13062 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13063 | struct intel_shared_dpll *old_dpll = |
| 13064 | to_intel_crtc_state(crtc->state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13065 | |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13066 | if (!needs_modeset(crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13067 | continue; |
| 13068 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13069 | to_intel_crtc_state(crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13070 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13071 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13072 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13073 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13074 | if (!shared_dpll) |
| 13075 | shared_dpll = intel_atomic_get_shared_dpll_state(state); |
| 13076 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13077 | intel_shared_dpll_config_put(shared_dpll, old_dpll, intel_crtc); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13078 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13079 | } |
| 13080 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13081 | /* |
| 13082 | * This implements the workaround described in the "notes" section of the mode |
| 13083 | * set sequence documentation. When going from no pipes or single pipe to |
| 13084 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 13085 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 13086 | */ |
| 13087 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 13088 | { |
| 13089 | struct drm_crtc_state *crtc_state; |
| 13090 | struct intel_crtc *intel_crtc; |
| 13091 | struct drm_crtc *crtc; |
| 13092 | struct intel_crtc_state *first_crtc_state = NULL; |
| 13093 | struct intel_crtc_state *other_crtc_state = NULL; |
| 13094 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 13095 | int i; |
| 13096 | |
| 13097 | /* look at all crtc's that are going to be enabled in during modeset */ |
| 13098 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13099 | intel_crtc = to_intel_crtc(crtc); |
| 13100 | |
| 13101 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 13102 | continue; |
| 13103 | |
| 13104 | if (first_crtc_state) { |
| 13105 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 13106 | break; |
| 13107 | } else { |
| 13108 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 13109 | first_pipe = intel_crtc->pipe; |
| 13110 | } |
| 13111 | } |
| 13112 | |
| 13113 | /* No workaround needed? */ |
| 13114 | if (!first_crtc_state) |
| 13115 | return 0; |
| 13116 | |
| 13117 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 13118 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 13119 | struct intel_crtc_state *pipe_config; |
| 13120 | |
| 13121 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 13122 | if (IS_ERR(pipe_config)) |
| 13123 | return PTR_ERR(pipe_config); |
| 13124 | |
| 13125 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 13126 | |
| 13127 | if (!pipe_config->base.active || |
| 13128 | needs_modeset(&pipe_config->base)) |
| 13129 | continue; |
| 13130 | |
| 13131 | /* 2 or more enabled crtcs means no need for w/a */ |
| 13132 | if (enabled_pipe != INVALID_PIPE) |
| 13133 | return 0; |
| 13134 | |
| 13135 | enabled_pipe = intel_crtc->pipe; |
| 13136 | } |
| 13137 | |
| 13138 | if (enabled_pipe != INVALID_PIPE) |
| 13139 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 13140 | else if (other_crtc_state) |
| 13141 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 13142 | |
| 13143 | return 0; |
| 13144 | } |
| 13145 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13146 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 13147 | { |
| 13148 | struct drm_crtc *crtc; |
| 13149 | struct drm_crtc_state *crtc_state; |
| 13150 | int ret = 0; |
| 13151 | |
| 13152 | /* add all active pipes to the state */ |
| 13153 | for_each_crtc(state->dev, crtc) { |
| 13154 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13155 | if (IS_ERR(crtc_state)) |
| 13156 | return PTR_ERR(crtc_state); |
| 13157 | |
| 13158 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 13159 | continue; |
| 13160 | |
| 13161 | crtc_state->mode_changed = true; |
| 13162 | |
| 13163 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13164 | if (ret) |
| 13165 | break; |
| 13166 | |
| 13167 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13168 | if (ret) |
| 13169 | break; |
| 13170 | } |
| 13171 | |
| 13172 | return ret; |
| 13173 | } |
| 13174 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13175 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13176 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13177 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13178 | struct drm_i915_private *dev_priv = state->dev->dev_private; |
| 13179 | struct drm_crtc *crtc; |
| 13180 | struct drm_crtc_state *crtc_state; |
| 13181 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13182 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13183 | if (!check_digital_port_conflicts(state)) { |
| 13184 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 13185 | return -EINVAL; |
| 13186 | } |
| 13187 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13188 | intel_state->modeset = true; |
| 13189 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 13190 | |
| 13191 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13192 | if (crtc_state->active) |
| 13193 | intel_state->active_crtcs |= 1 << i; |
| 13194 | else |
| 13195 | intel_state->active_crtcs &= ~(1 << i); |
| 13196 | } |
| 13197 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13198 | /* |
| 13199 | * See if the config requires any additional preparation, e.g. |
| 13200 | * to adjust global state with pipes off. We need to do this |
| 13201 | * here so we can get the modeset_pipe updated config for the new |
| 13202 | * mode set on this crtc. For other crtcs we need to use the |
| 13203 | * adjusted_mode bits in the crtc directly. |
| 13204 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13205 | if (dev_priv->display.modeset_calc_cdclk) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13206 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 13207 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13208 | if (!ret && intel_state->dev_cdclk != dev_priv->cdclk_freq) |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13209 | ret = intel_modeset_all_pipes(state); |
| 13210 | |
| 13211 | if (ret < 0) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13212 | return ret; |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 13213 | |
| 13214 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", |
| 13215 | intel_state->cdclk, intel_state->dev_cdclk); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13216 | } else |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13217 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13218 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13219 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13220 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13221 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13222 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13223 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13224 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13225 | } |
| 13226 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13227 | /* |
| 13228 | * Handle calculation of various watermark data at the end of the atomic check |
| 13229 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 13230 | * handlers to ensure that all derived state has been updated. |
| 13231 | */ |
| 13232 | static void calc_watermark_data(struct drm_atomic_state *state) |
| 13233 | { |
| 13234 | struct drm_device *dev = state->dev; |
| 13235 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 13236 | struct drm_crtc *crtc; |
| 13237 | struct drm_crtc_state *cstate; |
| 13238 | struct drm_plane *plane; |
| 13239 | struct drm_plane_state *pstate; |
| 13240 | |
| 13241 | /* |
| 13242 | * Calculate watermark configuration details now that derived |
| 13243 | * plane/crtc state is all properly updated. |
| 13244 | */ |
| 13245 | drm_for_each_crtc(crtc, dev) { |
| 13246 | cstate = drm_atomic_get_existing_crtc_state(state, crtc) ?: |
| 13247 | crtc->state; |
| 13248 | |
| 13249 | if (cstate->active) |
| 13250 | intel_state->wm_config.num_pipes_active++; |
| 13251 | } |
| 13252 | drm_for_each_legacy_plane(plane, dev) { |
| 13253 | pstate = drm_atomic_get_existing_plane_state(state, plane) ?: |
| 13254 | plane->state; |
| 13255 | |
| 13256 | if (!to_intel_plane_state(pstate)->visible) |
| 13257 | continue; |
| 13258 | |
| 13259 | intel_state->wm_config.sprites_enabled = true; |
| 13260 | if (pstate->crtc_w != pstate->src_w >> 16 || |
| 13261 | pstate->crtc_h != pstate->src_h >> 16) |
| 13262 | intel_state->wm_config.sprites_scaled = true; |
| 13263 | } |
| 13264 | } |
| 13265 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13266 | /** |
| 13267 | * intel_atomic_check - validate state object |
| 13268 | * @dev: drm device |
| 13269 | * @state: state to validate |
| 13270 | */ |
| 13271 | static int intel_atomic_check(struct drm_device *dev, |
| 13272 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13273 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13274 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13275 | 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] | 13276 | struct drm_crtc *crtc; |
| 13277 | struct drm_crtc_state *crtc_state; |
| 13278 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13279 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13280 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13281 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13282 | if (ret) |
| 13283 | return ret; |
| 13284 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13285 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13286 | struct intel_crtc_state *pipe_config = |
| 13287 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13288 | |
| 13289 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 13290 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) |
| 13291 | crtc_state->mode_changed = true; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13292 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13293 | if (!crtc_state->enable) { |
| 13294 | if (needs_modeset(crtc_state)) |
| 13295 | any_ms = true; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13296 | continue; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13297 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13298 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13299 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13300 | continue; |
| 13301 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13302 | /* FIXME: For only active_changed we shouldn't need to do any |
| 13303 | * state recomputation at all. */ |
| 13304 | |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13305 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13306 | if (ret) |
| 13307 | return ret; |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13308 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13309 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13310 | if (ret) |
| 13311 | return ret; |
| 13312 | |
Jani Nikula | 7383123 | 2015-11-19 10:26:30 +0200 | [diff] [blame] | 13313 | if (i915.fastboot && |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13314 | intel_pipe_config_compare(dev, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13315 | to_intel_crtc_state(crtc->state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 13316 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13317 | crtc_state->mode_changed = false; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13318 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13319 | } |
| 13320 | |
| 13321 | if (needs_modeset(crtc_state)) { |
| 13322 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13323 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13324 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13325 | if (ret) |
| 13326 | return ret; |
| 13327 | } |
| 13328 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 13329 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 13330 | needs_modeset(crtc_state) ? |
| 13331 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13332 | } |
| 13333 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13334 | if (any_ms) { |
| 13335 | ret = intel_modeset_checks(state); |
| 13336 | |
| 13337 | if (ret) |
| 13338 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13339 | } else |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13340 | intel_state->cdclk = dev_priv->cdclk_freq; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13341 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 13342 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13343 | if (ret) |
| 13344 | return ret; |
| 13345 | |
Paulo Zanoni | f51be2e | 2016-01-19 11:35:50 -0200 | [diff] [blame] | 13346 | intel_fbc_choose_crtc(dev_priv, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 13347 | calc_watermark_data(state); |
| 13348 | |
| 13349 | return 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13350 | } |
| 13351 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13352 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
| 13353 | struct drm_atomic_state *state, |
| 13354 | bool async) |
| 13355 | { |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13356 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13357 | struct drm_plane_state *plane_state; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13358 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13359 | struct drm_plane *plane; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13360 | struct drm_crtc *crtc; |
| 13361 | int i, ret; |
| 13362 | |
| 13363 | if (async) { |
| 13364 | DRM_DEBUG_KMS("i915 does not yet support async commit\n"); |
| 13365 | return -EINVAL; |
| 13366 | } |
| 13367 | |
| 13368 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13369 | ret = intel_crtc_wait_for_pending_flips(crtc); |
| 13370 | if (ret) |
| 13371 | return ret; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13372 | |
| 13373 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) |
| 13374 | flush_workqueue(dev_priv->wq); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13375 | } |
| 13376 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13377 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 13378 | if (ret) |
| 13379 | return ret; |
| 13380 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13381 | ret = drm_atomic_helper_prepare_planes(dev, state); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13382 | if (!ret && !async && !i915_reset_in_progress(&dev_priv->gpu_error)) { |
| 13383 | u32 reset_counter; |
| 13384 | |
| 13385 | reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
| 13386 | mutex_unlock(&dev->struct_mutex); |
| 13387 | |
| 13388 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 13389 | struct intel_plane_state *intel_plane_state = |
| 13390 | to_intel_plane_state(plane_state); |
| 13391 | |
| 13392 | if (!intel_plane_state->wait_req) |
| 13393 | continue; |
| 13394 | |
| 13395 | ret = __i915_wait_request(intel_plane_state->wait_req, |
| 13396 | reset_counter, true, |
| 13397 | NULL, NULL); |
| 13398 | |
| 13399 | /* Swallow -EIO errors to allow updates during hw lockup. */ |
| 13400 | if (ret == -EIO) |
| 13401 | ret = 0; |
| 13402 | |
| 13403 | if (ret) |
| 13404 | break; |
| 13405 | } |
| 13406 | |
| 13407 | if (!ret) |
| 13408 | return 0; |
| 13409 | |
| 13410 | mutex_lock(&dev->struct_mutex); |
| 13411 | drm_atomic_helper_cleanup_planes(dev, state); |
| 13412 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13413 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13414 | mutex_unlock(&dev->struct_mutex); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13415 | return ret; |
| 13416 | } |
| 13417 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13418 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
| 13419 | struct drm_i915_private *dev_priv, |
| 13420 | unsigned crtc_mask) |
| 13421 | { |
| 13422 | unsigned last_vblank_count[I915_MAX_PIPES]; |
| 13423 | enum pipe pipe; |
| 13424 | int ret; |
| 13425 | |
| 13426 | if (!crtc_mask) |
| 13427 | return; |
| 13428 | |
| 13429 | for_each_pipe(dev_priv, pipe) { |
| 13430 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 13431 | |
| 13432 | if (!((1 << pipe) & crtc_mask)) |
| 13433 | continue; |
| 13434 | |
| 13435 | ret = drm_crtc_vblank_get(crtc); |
| 13436 | if (WARN_ON(ret != 0)) { |
| 13437 | crtc_mask &= ~(1 << pipe); |
| 13438 | continue; |
| 13439 | } |
| 13440 | |
| 13441 | last_vblank_count[pipe] = drm_crtc_vblank_count(crtc); |
| 13442 | } |
| 13443 | |
| 13444 | for_each_pipe(dev_priv, pipe) { |
| 13445 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 13446 | long lret; |
| 13447 | |
| 13448 | if (!((1 << pipe) & crtc_mask)) |
| 13449 | continue; |
| 13450 | |
| 13451 | lret = wait_event_timeout(dev->vblank[pipe].queue, |
| 13452 | last_vblank_count[pipe] != |
| 13453 | drm_crtc_vblank_count(crtc), |
| 13454 | msecs_to_jiffies(50)); |
| 13455 | |
| 13456 | WARN_ON(!lret); |
| 13457 | |
| 13458 | drm_crtc_vblank_put(crtc); |
| 13459 | } |
| 13460 | } |
| 13461 | |
| 13462 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) |
| 13463 | { |
| 13464 | /* fb updated, need to unpin old fb */ |
| 13465 | if (crtc_state->fb_changed) |
| 13466 | return true; |
| 13467 | |
| 13468 | /* wm changes, need vblank before final wm's */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 13469 | if (crtc_state->update_wm_post) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13470 | return true; |
| 13471 | |
| 13472 | /* |
| 13473 | * cxsr is re-enabled after vblank. |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 13474 | * This is already handled by crtc_state->update_wm_post, |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13475 | * but added for clarity. |
| 13476 | */ |
| 13477 | if (crtc_state->disable_cxsr) |
| 13478 | return true; |
| 13479 | |
| 13480 | return false; |
| 13481 | } |
| 13482 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13483 | /** |
| 13484 | * intel_atomic_commit - commit validated state object |
| 13485 | * @dev: DRM device |
| 13486 | * @state: the top-level driver state object |
| 13487 | * @async: asynchronous commit |
| 13488 | * |
| 13489 | * This function commits a top-level state object that has been validated |
| 13490 | * with drm_atomic_helper_check(). |
| 13491 | * |
| 13492 | * FIXME: Atomic modeset support for i915 is not yet complete. At the moment |
| 13493 | * we can only handle plane-related operations and do not yet support |
| 13494 | * asynchronous commit. |
| 13495 | * |
| 13496 | * RETURNS |
| 13497 | * Zero for success or -errno. |
| 13498 | */ |
| 13499 | static int intel_atomic_commit(struct drm_device *dev, |
| 13500 | struct drm_atomic_state *state, |
| 13501 | bool async) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13502 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13503 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13504 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13505 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13506 | struct drm_crtc *crtc; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13507 | struct intel_crtc_state *intel_cstate; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13508 | int ret = 0, i; |
| 13509 | bool hw_check = intel_state->modeset; |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13510 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13511 | unsigned crtc_vblank_mask = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13512 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13513 | ret = intel_atomic_prepare_commit(dev, state, async); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13514 | if (ret) { |
| 13515 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13516 | return ret; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13517 | } |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13518 | |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13519 | drm_atomic_helper_swap_state(dev, state); |
Maarten Lankhorst | a1475e7 | 2016-03-14 09:27:53 +0100 | [diff] [blame] | 13520 | dev_priv->wm.config = intel_state->wm_config; |
| 13521 | intel_shared_dpll_commit(state); |
Maarten Lankhorst | 1c5e19f | 2015-06-01 12:50:06 +0200 | [diff] [blame] | 13522 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13523 | if (intel_state->modeset) { |
| 13524 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, |
| 13525 | sizeof(intel_state->min_pixclk)); |
| 13526 | dev_priv->active_crtcs = intel_state->active_crtcs; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 13527 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13528 | |
| 13529 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13530 | } |
| 13531 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13532 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13533 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13534 | |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13535 | if (needs_modeset(crtc->state) || |
| 13536 | to_intel_crtc_state(crtc->state)->update_pipe) { |
| 13537 | hw_check = true; |
| 13538 | |
| 13539 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 13540 | modeset_get_crtc_power_domains(crtc, |
| 13541 | to_intel_crtc_state(crtc->state)); |
| 13542 | } |
| 13543 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 13544 | if (!needs_modeset(crtc->state)) |
| 13545 | continue; |
| 13546 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13547 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 13548 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13549 | if (old_crtc_state->active) { |
| 13550 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13551 | dev_priv->display.crtc_disable(crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13552 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 13553 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 13554 | intel_disable_shared_dpll(intel_crtc); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 13555 | |
| 13556 | /* |
| 13557 | * Underruns don't always raise |
| 13558 | * interrupts, so check manually. |
| 13559 | */ |
| 13560 | intel_check_cpu_fifo_underruns(dev_priv); |
| 13561 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 13562 | |
| 13563 | if (!crtc->state->active) |
| 13564 | intel_update_watermarks(crtc); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13565 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 13566 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13567 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13568 | /* Only after disabling all output pipelines that will be changed can we |
| 13569 | * update the the output configuration. */ |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13570 | intel_modeset_update_crtc_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13571 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13572 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13573 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 13574 | |
| 13575 | if (dev_priv->display.modeset_commit_cdclk && |
| 13576 | intel_state->dev_cdclk != dev_priv->cdclk_freq) |
| 13577 | dev_priv->display.modeset_commit_cdclk(state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13578 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 13579 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13580 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13581 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13582 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13583 | bool modeset = needs_modeset(crtc->state); |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13584 | struct intel_crtc_state *pipe_config = |
| 13585 | to_intel_crtc_state(crtc->state); |
| 13586 | bool update_pipe = !modeset && pipe_config->update_pipe; |
Patrik Jakobsson | 9f836f9 | 2015-11-16 16:20:01 +0100 | [diff] [blame] | 13587 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13588 | if (modeset && crtc->state->active) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 13589 | update_scanline_offset(to_intel_crtc(crtc)); |
| 13590 | dev_priv->display.crtc_enable(crtc); |
| 13591 | } |
| 13592 | |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13593 | if (!modeset) |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13594 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 13595 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 13596 | if (crtc->state->active && |
| 13597 | drm_atomic_get_existing_plane_state(state, crtc->primary)) |
Paulo Zanoni | 49227c4 | 2016-01-19 11:35:52 -0200 | [diff] [blame] | 13598 | intel_fbc_enable(intel_crtc); |
| 13599 | |
Maarten Lankhorst | 6173ee2 | 2015-09-23 16:29:39 +0200 | [diff] [blame] | 13600 | if (crtc->state->active && |
| 13601 | (crtc->state->planes_changed || update_pipe)) |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13602 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13603 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13604 | if (pipe_config->base.active && needs_vblank_wait(pipe_config)) |
| 13605 | crtc_vblank_mask |= 1 << i; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13606 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13607 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 13608 | /* FIXME: add subpixel order */ |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13609 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 13610 | if (!state->legacy_cursor_update) |
| 13611 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13612 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13613 | /* |
| 13614 | * Now that the vblank has passed, we can go ahead and program the |
| 13615 | * optimal watermarks on platforms that need two-step watermark |
| 13616 | * programming. |
| 13617 | * |
| 13618 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 13619 | */ |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 13620 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 13621 | intel_cstate = to_intel_crtc_state(crtc->state); |
| 13622 | |
| 13623 | if (dev_priv->display.optimize_watermarks) |
| 13624 | dev_priv->display.optimize_watermarks(intel_cstate); |
| 13625 | } |
| 13626 | |
Matt Roper | 177246a | 2016-03-04 15:59:39 -0800 | [diff] [blame] | 13627 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 13628 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 13629 | |
| 13630 | if (put_domains[i]) |
| 13631 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 13632 | } |
| 13633 | |
| 13634 | if (intel_state->modeset) |
| 13635 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
| 13636 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13637 | mutex_lock(&dev->struct_mutex); |
Ander Conselvan de Oliveira | d4afb8c | 2015-04-21 17:13:22 +0300 | [diff] [blame] | 13638 | drm_atomic_helper_cleanup_planes(dev, state); |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13639 | mutex_unlock(&dev->struct_mutex); |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13640 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13641 | if (hw_check) |
Maarten Lankhorst | ee165b1 | 2015-08-05 12:37:00 +0200 | [diff] [blame] | 13642 | intel_modeset_check_state(dev, state); |
| 13643 | |
| 13644 | drm_atomic_state_free(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 13645 | |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 13646 | /* As one of the primary mmio accessors, KMS has a high likelihood |
| 13647 | * of triggering bugs in unclaimed access. After we finish |
| 13648 | * modesetting, see if an error has been flagged, and if so |
| 13649 | * enable debugging for the next modeset - and hope we catch |
| 13650 | * the culprit. |
| 13651 | * |
| 13652 | * XXX note that we assume display power is on at this point. |
| 13653 | * This might hold true now but we need to add pm helper to check |
| 13654 | * unclaimed only when the hardware is on, as atomic commits |
| 13655 | * can happen also when the device is completely off. |
| 13656 | */ |
| 13657 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
| 13658 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13659 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13660 | } |
| 13661 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13662 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 13663 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13664 | struct drm_device *dev = crtc->dev; |
| 13665 | struct drm_atomic_state *state; |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13666 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13667 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13668 | |
| 13669 | state = drm_atomic_state_alloc(dev); |
| 13670 | if (!state) { |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13671 | DRM_DEBUG_KMS("[CRTC:%d] crtc restore failed, out of memory", |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13672 | crtc->base.id); |
| 13673 | return; |
| 13674 | } |
| 13675 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13676 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13677 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13678 | retry: |
| 13679 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13680 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 13681 | if (!ret) { |
| 13682 | if (!crtc_state->active) |
| 13683 | goto out; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13684 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13685 | crtc_state->mode_changed = true; |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13686 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 13687 | } |
| 13688 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13689 | if (ret == -EDEADLK) { |
| 13690 | drm_atomic_state_clear(state); |
| 13691 | drm_modeset_backoff(state->acquire_ctx); |
| 13692 | goto retry; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 13693 | } |
| 13694 | |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13695 | if (ret) |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 13696 | out: |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 13697 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 13698 | } |
| 13699 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 13700 | #undef for_each_intel_crtc_masked |
| 13701 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13702 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13703 | .gamma_set = drm_atomic_helper_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 13704 | .set_config = drm_atomic_helper_set_config, |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 13705 | .set_property = drm_atomic_helper_crtc_set_property, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13706 | .destroy = intel_crtc_destroy, |
| 13707 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 13708 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 13709 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 13710 | }; |
| 13711 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13712 | /** |
| 13713 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 13714 | * @plane: drm plane to prepare for |
| 13715 | * @fb: framebuffer to prepare for presentation |
| 13716 | * |
| 13717 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 13718 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 13719 | * bits. Some older platforms need special physical address handling for |
| 13720 | * cursor planes. |
| 13721 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13722 | * Must be called with struct_mutex held. |
| 13723 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13724 | * Returns 0 on success, negative error code on failure. |
| 13725 | */ |
| 13726 | int |
| 13727 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13728 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13729 | { |
| 13730 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 13731 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13732 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13733 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13734 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13735 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13736 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13737 | if (!obj && !old_obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13738 | return 0; |
| 13739 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13740 | if (old_obj) { |
| 13741 | struct drm_crtc_state *crtc_state = |
| 13742 | drm_atomic_get_existing_crtc_state(new_state->state, plane->state->crtc); |
| 13743 | |
| 13744 | /* Big Hammer, we also need to ensure that any pending |
| 13745 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 13746 | * current scanout is retired before unpinning the old |
| 13747 | * framebuffer. Note that we rely on userspace rendering |
| 13748 | * into the buffer attached to the pipe they are waiting |
| 13749 | * on. If not, userspace generates a GPU hang with IPEHR |
| 13750 | * point to the MI_WAIT_FOR_EVENT. |
| 13751 | * |
| 13752 | * This should only fail upon a hung GPU, in which case we |
| 13753 | * can safely continue. |
| 13754 | */ |
| 13755 | if (needs_modeset(crtc_state)) |
| 13756 | ret = i915_gem_object_wait_rendering(old_obj, true); |
| 13757 | |
| 13758 | /* Swallow -EIO errors to allow updates during hw lockup. */ |
| 13759 | if (ret && ret != -EIO) |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13760 | return ret; |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13761 | } |
| 13762 | |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13763 | /* For framebuffer backed by dmabuf, wait for fence */ |
| 13764 | if (obj && obj->base.dma_buf) { |
Maarten Lankhorst | bcf8be2 | 2015-12-08 15:52:56 +0100 | [diff] [blame] | 13765 | long lret; |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13766 | |
Maarten Lankhorst | bcf8be2 | 2015-12-08 15:52:56 +0100 | [diff] [blame] | 13767 | lret = reservation_object_wait_timeout_rcu(obj->base.dma_buf->resv, |
| 13768 | false, true, |
| 13769 | MAX_SCHEDULE_TIMEOUT); |
| 13770 | if (lret == -ERESTARTSYS) |
| 13771 | return lret; |
| 13772 | |
| 13773 | WARN(lret < 0, "waiting returns %li\n", lret); |
Alex Goins | 3c28ff2 | 2015-11-25 18:43:39 -0800 | [diff] [blame] | 13774 | } |
| 13775 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13776 | if (!obj) { |
| 13777 | ret = 0; |
| 13778 | } else if (plane->type == DRM_PLANE_TYPE_CURSOR && |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13779 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 13780 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 13781 | ret = i915_gem_object_attach_phys(obj, align); |
| 13782 | if (ret) |
| 13783 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 13784 | } else { |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 13785 | ret = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13786 | } |
| 13787 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13788 | if (ret == 0) { |
| 13789 | if (obj) { |
| 13790 | struct intel_plane_state *plane_state = |
| 13791 | to_intel_plane_state(new_state); |
| 13792 | |
| 13793 | i915_gem_request_assign(&plane_state->wait_req, |
| 13794 | obj->last_write_req); |
| 13795 | } |
| 13796 | |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13797 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13798 | } |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13799 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 13800 | return ret; |
| 13801 | } |
| 13802 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13803 | /** |
| 13804 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 13805 | * @plane: drm plane to clean up for |
| 13806 | * @fb: old framebuffer that was on plane |
| 13807 | * |
| 13808 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 13809 | * |
| 13810 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13811 | */ |
| 13812 | void |
| 13813 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 13814 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13815 | { |
| 13816 | struct drm_device *dev = plane->dev; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13817 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13818 | struct intel_plane_state *old_intel_state; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13819 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
| 13820 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13821 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13822 | old_intel_state = to_intel_plane_state(old_state); |
| 13823 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13824 | if (!obj && !old_obj) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 13825 | return; |
| 13826 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13827 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 13828 | !INTEL_INFO(dev)->cursor_needs_physical)) |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 13829 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 13830 | |
| 13831 | /* prepare_fb aborted? */ |
| 13832 | if ((old_obj && (old_obj->frontbuffer_bits & intel_plane->frontbuffer_bit)) || |
| 13833 | (obj && !(obj->frontbuffer_bits & intel_plane->frontbuffer_bit))) |
| 13834 | i915_gem_track_fb(old_obj, obj, intel_plane->frontbuffer_bit); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 13835 | |
| 13836 | i915_gem_request_assign(&old_intel_state->wait_req, NULL); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13837 | } |
| 13838 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13839 | int |
| 13840 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 13841 | { |
| 13842 | int max_scale; |
| 13843 | struct drm_device *dev; |
| 13844 | struct drm_i915_private *dev_priv; |
| 13845 | int crtc_clock, cdclk; |
| 13846 | |
Maarten Lankhorst | bf8a0af | 2015-11-24 11:29:02 +0100 | [diff] [blame] | 13847 | if (!intel_crtc || !crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13848 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13849 | |
| 13850 | dev = intel_crtc->base.dev; |
| 13851 | dev_priv = dev->dev_private; |
| 13852 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13853 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13854 | |
Tvrtko Ursulin | 54bf1ce | 2015-10-20 17:17:07 +0100 | [diff] [blame] | 13855 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13856 | return DRM_PLANE_HELPER_NO_SCALING; |
| 13857 | |
| 13858 | /* |
| 13859 | * skl max scale is lower of: |
| 13860 | * close to 3 but not 3, -1 is for that purpose |
| 13861 | * or |
| 13862 | * cdclk/crtc_clock |
| 13863 | */ |
| 13864 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 13865 | |
| 13866 | return max_scale; |
| 13867 | } |
| 13868 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13869 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13870 | intel_check_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13871 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13872 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13873 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13874 | struct drm_crtc *crtc = state->base.crtc; |
| 13875 | struct drm_framebuffer *fb = state->base.fb; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13876 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13877 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 13878 | bool can_position = false; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13879 | |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 13880 | if (INTEL_INFO(plane->dev)->gen >= 9) { |
| 13881 | /* use scaler when colorkey is not required */ |
| 13882 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { |
| 13883 | min_scale = 1; |
| 13884 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); |
| 13885 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13886 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13887 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 13888 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 13889 | return drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 13890 | &state->dst, &state->clip, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 13891 | min_scale, max_scale, |
| 13892 | can_position, true, |
| 13893 | &state->visible); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13894 | } |
| 13895 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13896 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 13897 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13898 | { |
| 13899 | struct drm_device *dev = crtc->dev; |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13900 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13901 | struct intel_crtc_state *old_intel_state = |
| 13902 | to_intel_crtc_state(old_crtc_state); |
| 13903 | bool modeset = needs_modeset(crtc->state); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 13904 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 13905 | /* Perform vblank evasion around commit operation */ |
Maarten Lankhorst | 6285262 | 2015-09-23 16:29:38 +0200 | [diff] [blame] | 13906 | intel_pipe_update_start(intel_crtc); |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 13907 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13908 | if (modeset) |
| 13909 | return; |
| 13910 | |
Maarten Lankhorst | 20a34e7 | 2016-03-30 17:16:36 +0200 | [diff] [blame] | 13911 | if (crtc->state->color_mgmt_changed || to_intel_crtc_state(crtc->state)->update_pipe) { |
| 13912 | intel_color_set_csc(crtc->state); |
| 13913 | intel_color_load_luts(crtc->state); |
| 13914 | } |
| 13915 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13916 | if (to_intel_crtc_state(crtc->state)->update_pipe) |
| 13917 | intel_update_pipe_config(intel_crtc, old_intel_state); |
| 13918 | else if (INTEL_INFO(dev)->gen >= 9) |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 13919 | skl_detach_scalers(intel_crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13920 | } |
| 13921 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 13922 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 13923 | struct drm_crtc_state *old_crtc_state) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13924 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13925 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13926 | |
Maarten Lankhorst | 6285262 | 2015-09-23 16:29:38 +0200 | [diff] [blame] | 13927 | intel_pipe_update_end(intel_crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 13928 | } |
| 13929 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13930 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13931 | * intel_plane_destroy - destroy a plane |
| 13932 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13933 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13934 | * Common destruction function for all types of planes (primary, cursor, |
| 13935 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 13936 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 13937 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13938 | { |
| 13939 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 13940 | drm_plane_cleanup(plane); |
| 13941 | kfree(intel_plane); |
| 13942 | } |
| 13943 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13944 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 13945 | .update_plane = drm_atomic_helper_update_plane, |
| 13946 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13947 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 13948 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 13949 | .atomic_get_property = intel_plane_atomic_get_property, |
| 13950 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13951 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 13952 | .atomic_destroy_state = intel_plane_destroy_state, |
| 13953 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13954 | }; |
| 13955 | |
| 13956 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 13957 | int pipe) |
| 13958 | { |
| 13959 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13960 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13961 | const uint32_t *intel_primary_formats; |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 13962 | unsigned int num_formats; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13963 | |
| 13964 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 13965 | if (primary == NULL) |
| 13966 | return NULL; |
| 13967 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13968 | state = intel_create_plane_state(&primary->base); |
| 13969 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13970 | kfree(primary); |
| 13971 | return NULL; |
| 13972 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13973 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13974 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13975 | primary->can_scale = false; |
| 13976 | primary->max_downscale = 1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13977 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13978 | primary->can_scale = true; |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 13979 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 13980 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13981 | primary->pipe = pipe; |
| 13982 | primary->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 13983 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13984 | primary->check_plane = intel_check_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13985 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 13986 | primary->plane = !pipe; |
| 13987 | |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 13988 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13989 | intel_primary_formats = skl_primary_formats; |
| 13990 | num_formats = ARRAY_SIZE(skl_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 13991 | |
| 13992 | primary->update_plane = skylake_update_primary_plane; |
| 13993 | primary->disable_plane = skylake_disable_primary_plane; |
| 13994 | } else if (HAS_PCH_SPLIT(dev)) { |
| 13995 | intel_primary_formats = i965_primary_formats; |
| 13996 | num_formats = ARRAY_SIZE(i965_primary_formats); |
| 13997 | |
| 13998 | primary->update_plane = ironlake_update_primary_plane; |
| 13999 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14000 | } else if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 14001 | intel_primary_formats = i965_primary_formats; |
| 14002 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14003 | |
| 14004 | primary->update_plane = i9xx_update_primary_plane; |
| 14005 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14006 | } else { |
| 14007 | intel_primary_formats = i8xx_primary_formats; |
| 14008 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 14009 | |
| 14010 | primary->update_plane = i9xx_update_primary_plane; |
| 14011 | primary->disable_plane = i9xx_disable_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14012 | } |
| 14013 | |
| 14014 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 14015 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14016 | intel_primary_formats, num_formats, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 14017 | DRM_PLANE_TYPE_PRIMARY, NULL); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14018 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 14019 | if (INTEL_INFO(dev)->gen >= 4) |
| 14020 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 14021 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14022 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 14023 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14024 | return &primary->base; |
| 14025 | } |
| 14026 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 14027 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 14028 | { |
| 14029 | if (!dev->mode_config.rotation_property) { |
| 14030 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 14031 | BIT(DRM_ROTATE_180); |
| 14032 | |
| 14033 | if (INTEL_INFO(dev)->gen >= 9) |
| 14034 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 14035 | |
| 14036 | dev->mode_config.rotation_property = |
| 14037 | drm_mode_create_rotation_property(dev, flags); |
| 14038 | } |
| 14039 | if (dev->mode_config.rotation_property) |
| 14040 | drm_object_attach_property(&plane->base.base, |
| 14041 | dev->mode_config.rotation_property, |
| 14042 | plane->base.state->rotation); |
| 14043 | } |
| 14044 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14045 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14046 | intel_check_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14047 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14048 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14049 | { |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14050 | struct drm_crtc *crtc = crtc_state->base.crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14051 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14052 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 14053 | enum pipe pipe = to_intel_plane(plane)->pipe; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14054 | unsigned stride; |
| 14055 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14056 | |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14057 | ret = drm_plane_helper_check_update(plane, crtc, fb, &state->src, |
| 14058 | &state->dst, &state->clip, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14059 | DRM_PLANE_HELPER_NO_SCALING, |
| 14060 | DRM_PLANE_HELPER_NO_SCALING, |
| 14061 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14062 | if (ret) |
| 14063 | return ret; |
| 14064 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14065 | /* if we want to turn off the cursor ignore width and height */ |
| 14066 | if (!obj) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14067 | return 0; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14068 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14069 | /* Check for which cursor types we support */ |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14070 | if (!cursor_size_ok(plane->dev, state->base.crtc_w, state->base.crtc_h)) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14071 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 14072 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14073 | return -EINVAL; |
| 14074 | } |
| 14075 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14076 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 14077 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14078 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 14079 | return -ENOMEM; |
| 14080 | } |
| 14081 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 14082 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14083 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14084 | return -EINVAL; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14085 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 14086 | |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 14087 | /* |
| 14088 | * There's something wrong with the cursor on CHV pipe C. |
| 14089 | * If it straddles the left edge of the screen then |
| 14090 | * moving it away from the edge or disabling it often |
| 14091 | * results in a pipe underrun, and often that can lead to |
| 14092 | * dead pipe (constant underrun reported, and it scans |
| 14093 | * out just a solid color). To recover from that, the |
| 14094 | * display power well must be turned off and on again. |
| 14095 | * Refuse the put the cursor into that compromised position. |
| 14096 | */ |
| 14097 | if (IS_CHERRYVIEW(plane->dev) && pipe == PIPE_C && |
| 14098 | state->visible && state->base.crtc_x < 0) { |
| 14099 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 14100 | return -EINVAL; |
| 14101 | } |
| 14102 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 14103 | return 0; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14104 | } |
| 14105 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14106 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14107 | intel_disable_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 14108 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14109 | { |
Maarten Lankhorst | f285802 | 2016-01-07 11:54:09 +0100 | [diff] [blame] | 14110 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14111 | |
| 14112 | intel_crtc->cursor_addr = 0; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14113 | intel_crtc_update_cursor(crtc, NULL); |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14114 | } |
| 14115 | |
| 14116 | static void |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14117 | intel_update_cursor_plane(struct drm_plane *plane, |
| 14118 | const struct intel_crtc_state *crtc_state, |
| 14119 | const struct intel_plane_state *state) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14120 | { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14121 | struct drm_crtc *crtc = crtc_state->base.crtc; |
| 14122 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14123 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14124 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14125 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14126 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14127 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14128 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14129 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14130 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 14131 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14132 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14133 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 14134 | intel_crtc->cursor_addr = addr; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14135 | intel_crtc_update_cursor(crtc, state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14136 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 14137 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14138 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 14139 | int pipe) |
| 14140 | { |
| 14141 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14142 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14143 | |
| 14144 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 14145 | if (cursor == NULL) |
| 14146 | return NULL; |
| 14147 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14148 | state = intel_create_plane_state(&cursor->base); |
| 14149 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14150 | kfree(cursor); |
| 14151 | return NULL; |
| 14152 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14153 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14154 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14155 | cursor->can_scale = false; |
| 14156 | cursor->max_downscale = 1; |
| 14157 | cursor->pipe = pipe; |
| 14158 | cursor->plane = pipe; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 14159 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 14160 | cursor->check_plane = intel_check_cursor_plane; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 14161 | cursor->update_plane = intel_update_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 14162 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14163 | |
| 14164 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 14165 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14166 | intel_cursor_formats, |
| 14167 | ARRAY_SIZE(intel_cursor_formats), |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 14168 | DRM_PLANE_TYPE_CURSOR, NULL); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14169 | |
| 14170 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14171 | if (!dev->mode_config.rotation_property) |
| 14172 | dev->mode_config.rotation_property = |
| 14173 | drm_mode_create_rotation_property(dev, |
| 14174 | BIT(DRM_ROTATE_0) | |
| 14175 | BIT(DRM_ROTATE_180)); |
| 14176 | if (dev->mode_config.rotation_property) |
| 14177 | drm_object_attach_property(&cursor->base.base, |
| 14178 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 14179 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 14180 | } |
| 14181 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 14182 | if (INTEL_INFO(dev)->gen >=9) |
| 14183 | state->scaler_id = -1; |
| 14184 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14185 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 14186 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14187 | return &cursor->base; |
| 14188 | } |
| 14189 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14190 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 14191 | struct intel_crtc_state *crtc_state) |
| 14192 | { |
| 14193 | int i; |
| 14194 | struct intel_scaler *intel_scaler; |
| 14195 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 14196 | |
| 14197 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 14198 | intel_scaler = &scaler_state->scalers[i]; |
| 14199 | intel_scaler->in_use = 0; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14200 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 14201 | } |
| 14202 | |
| 14203 | scaler_state->scaler_id = -1; |
| 14204 | } |
| 14205 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 14206 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14207 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14208 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14209 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14210 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14211 | struct drm_plane *primary = NULL; |
| 14212 | struct drm_plane *cursor = NULL; |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14213 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14214 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 14215 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14216 | if (intel_crtc == NULL) |
| 14217 | return; |
| 14218 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14219 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 14220 | if (!crtc_state) |
| 14221 | goto fail; |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 14222 | intel_crtc->config = crtc_state; |
| 14223 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 14224 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14225 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 14226 | /* initialize shared scalers */ |
| 14227 | if (INTEL_INFO(dev)->gen >= 9) { |
| 14228 | if (pipe == PIPE_C) |
| 14229 | intel_crtc->num_scalers = 1; |
| 14230 | else |
| 14231 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 14232 | |
| 14233 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 14234 | } |
| 14235 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14236 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14237 | if (!primary) |
| 14238 | goto fail; |
| 14239 | |
| 14240 | cursor = intel_cursor_plane_create(dev, pipe); |
| 14241 | if (!cursor) |
| 14242 | goto fail; |
| 14243 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14244 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 14245 | cursor, &intel_crtc_funcs, NULL); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14246 | if (ret) |
| 14247 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14248 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 14249 | /* |
| 14250 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port |
Daniel Vetter | 8c0f92e | 2014-06-16 02:08:26 +0200 | [diff] [blame] | 14251 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 14252 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14253 | intel_crtc->pipe = pipe; |
| 14254 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 14255 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14256 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 14257 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 14258 | } |
| 14259 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 14260 | intel_crtc->cursor_base = ~0; |
| 14261 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14262 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 14263 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 14264 | intel_crtc->wm.cxsr_allowed = true; |
| 14265 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 14266 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 14267 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 14268 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 14269 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 14270 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14271 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14272 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 14273 | intel_color_init(&intel_crtc->base); |
| 14274 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 14275 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14276 | return; |
| 14277 | |
| 14278 | fail: |
| 14279 | if (primary) |
| 14280 | drm_plane_cleanup(primary); |
| 14281 | if (cursor) |
| 14282 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 14283 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14284 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14285 | } |
| 14286 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14287 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 14288 | { |
| 14289 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14290 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14291 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 14292 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14293 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 14294 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 14295 | return INVALID_PIPE; |
| 14296 | |
| 14297 | return to_intel_crtc(encoder->crtc)->pipe; |
| 14298 | } |
| 14299 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14300 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14301 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14302 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14303 | 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] | 14304 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14305 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14306 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14307 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14308 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14309 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14310 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 14311 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14312 | } |
| 14313 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 14314 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14315 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14316 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 14317 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 14318 | } |
| 14319 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14320 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14321 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14322 | struct drm_device *dev = encoder->base.dev; |
| 14323 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14324 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14325 | int entry = 0; |
| 14326 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14327 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 14328 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14329 | index_mask |= (1 << entry); |
| 14330 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14331 | entry++; |
| 14332 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14333 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14334 | return index_mask; |
| 14335 | } |
| 14336 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14337 | static bool has_edp_a(struct drm_device *dev) |
| 14338 | { |
| 14339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14340 | |
| 14341 | if (!IS_MOBILE(dev)) |
| 14342 | return false; |
| 14343 | |
| 14344 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 14345 | return false; |
| 14346 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 14347 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 14348 | return false; |
| 14349 | |
| 14350 | return true; |
| 14351 | } |
| 14352 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14353 | static bool intel_crt_present(struct drm_device *dev) |
| 14354 | { |
| 14355 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14356 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 14357 | if (INTEL_INFO(dev)->gen >= 9) |
| 14358 | return false; |
| 14359 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 14360 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14361 | return false; |
| 14362 | |
| 14363 | if (IS_CHERRYVIEW(dev)) |
| 14364 | return false; |
| 14365 | |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 14366 | if (HAS_PCH_LPT_H(dev) && I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
| 14367 | return false; |
| 14368 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 14369 | /* DDI E can't be used if DDI A requires 4 lanes */ |
| 14370 | if (HAS_DDI(dev) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
| 14371 | return false; |
| 14372 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 14373 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14374 | return false; |
| 14375 | |
| 14376 | return true; |
| 14377 | } |
| 14378 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14379 | static void intel_setup_outputs(struct drm_device *dev) |
| 14380 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14381 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14382 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14383 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14384 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 14385 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14386 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 14387 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 14388 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14389 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14390 | if (IS_BROXTON(dev)) { |
| 14391 | /* |
| 14392 | * FIXME: Broxton doesn't support port detection via the |
| 14393 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 14394 | * detect the ports. |
| 14395 | */ |
| 14396 | intel_ddi_init(dev, PORT_A); |
| 14397 | intel_ddi_init(dev, PORT_B); |
| 14398 | intel_ddi_init(dev, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 14399 | |
| 14400 | intel_dsi_init(dev); |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 14401 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14402 | int found; |
| 14403 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14404 | /* |
| 14405 | * Haswell uses DDI functions to detect digital outputs. |
| 14406 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 14407 | * it's there. |
| 14408 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 14409 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 14410 | /* WaIgnoreDDIAStrap: skl */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14411 | if (found || IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14412 | intel_ddi_init(dev, PORT_A); |
| 14413 | |
| 14414 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 14415 | * register */ |
| 14416 | found = I915_READ(SFUSE_STRAP); |
| 14417 | |
| 14418 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 14419 | intel_ddi_init(dev, PORT_B); |
| 14420 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 14421 | intel_ddi_init(dev, PORT_C); |
| 14422 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 14423 | intel_ddi_init(dev, PORT_D); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14424 | /* |
| 14425 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 14426 | */ |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 14427 | if ((IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 14428 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 14429 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 14430 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
| 14431 | intel_ddi_init(dev, PORT_E); |
| 14432 | |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 14433 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14434 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 14435 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14436 | |
| 14437 | if (has_edp_a(dev)) |
| 14438 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 14439 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14440 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 14441 | /* PCH SDVOB multiplex with HDMIB */ |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14442 | found = intel_sdvo_init(dev, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14443 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14444 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14445 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14446 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14447 | } |
| 14448 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14449 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14450 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14451 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 14452 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14453 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 14454 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14455 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14456 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 14457 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14458 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14459 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14460 | } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14461 | /* |
| 14462 | * The DP_DETECTED bit is the latched state of the DDC |
| 14463 | * SDA pin at boot. However since eDP doesn't require DDC |
| 14464 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 14465 | * eDP ports may have been muxed to an alternate function. |
| 14466 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 14467 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 14468 | * detect eDP ports. |
| 14469 | */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14470 | if (I915_READ(VLV_HDMIB) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14471 | !intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14472 | intel_hdmi_init(dev, VLV_HDMIB, PORT_B); |
| 14473 | if (I915_READ(VLV_DP_B) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14474 | intel_dp_is_edp(dev, PORT_B)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14475 | intel_dp_init(dev, VLV_DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 14476 | |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14477 | if (I915_READ(VLV_HDMIC) & SDVO_DETECTED && |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 14478 | !intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14479 | intel_hdmi_init(dev, VLV_HDMIC, PORT_C); |
| 14480 | if (I915_READ(VLV_DP_C) & DP_DETECTED || |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14481 | intel_dp_is_edp(dev, PORT_C)) |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14482 | intel_dp_init(dev, VLV_DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 14483 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14484 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 14485 | /* eDP not supported on port D, so don't check VBT */ |
Ville Syrjälä | e66eb81 | 2015-09-18 20:03:34 +0300 | [diff] [blame] | 14486 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED) |
| 14487 | intel_hdmi_init(dev, CHV_HDMID, PORT_D); |
| 14488 | if (I915_READ(CHV_DP_D) & DP_DETECTED) |
| 14489 | intel_dp_init(dev, CHV_DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 14490 | } |
| 14491 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 14492 | intel_dsi_init(dev); |
Daniel Vetter | 09da55d | 2015-07-07 11:44:32 +0200 | [diff] [blame] | 14493 | } else if (!IS_GEN2(dev) && !IS_PINEVIEW(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14494 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 14495 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14496 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14497 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14498 | found = intel_sdvo_init(dev, GEN3_SDVOB, PORT_B); |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14499 | if (!found && IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14500 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14501 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14502 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14503 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14504 | if (!found && IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14505 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14506 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14507 | |
| 14508 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 14509 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14510 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14511 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ville Syrjälä | 2a5c083 | 2015-11-06 21:29:59 +0200 | [diff] [blame] | 14512 | found = intel_sdvo_init(dev, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14513 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14514 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14515 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14516 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14517 | if (IS_G4X(dev)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14518 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 14519 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 14520 | } |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14521 | if (IS_G4X(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14522 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 14523 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 14524 | |
Daniel Vetter | 3fec3d2 | 2015-07-07 09:10:07 +0200 | [diff] [blame] | 14525 | if (IS_G4X(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 14526 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 14527 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 14528 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14529 | intel_dvo_init(dev); |
| 14530 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 14531 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14532 | intel_tv_init(dev); |
| 14533 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 14534 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 14535 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14536 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 14537 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 14538 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 14539 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14540 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 14541 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 14542 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 14543 | |
| 14544 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14545 | } |
| 14546 | |
| 14547 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 14548 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14549 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14550 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14551 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14552 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14553 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 14554 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 14555 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 14556 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14557 | kfree(intel_fb); |
| 14558 | } |
| 14559 | |
| 14560 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14561 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14562 | unsigned int *handle) |
| 14563 | { |
| 14564 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14565 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14566 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 14567 | if (obj->userptr.mm) { |
| 14568 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 14569 | return -EINVAL; |
| 14570 | } |
| 14571 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14572 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14573 | } |
| 14574 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14575 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 14576 | struct drm_file *file, |
| 14577 | unsigned flags, unsigned color, |
| 14578 | struct drm_clip_rect *clips, |
| 14579 | unsigned num_clips) |
| 14580 | { |
| 14581 | struct drm_device *dev = fb->dev; |
| 14582 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 14583 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 14584 | |
| 14585 | mutex_lock(&dev->struct_mutex); |
Paulo Zanoni | 74b4ea1 | 2015-07-14 16:29:14 -0300 | [diff] [blame] | 14586 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14587 | mutex_unlock(&dev->struct_mutex); |
| 14588 | |
| 14589 | return 0; |
| 14590 | } |
| 14591 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14592 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 14593 | .destroy = intel_user_framebuffer_destroy, |
| 14594 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 14595 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14596 | }; |
| 14597 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14598 | static |
| 14599 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 14600 | uint32_t pixel_format) |
| 14601 | { |
| 14602 | u32 gen = INTEL_INFO(dev)->gen; |
| 14603 | |
| 14604 | if (gen >= 9) { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14605 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 14606 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14607 | /* "The stride in bytes must not exceed the of the size of 8K |
| 14608 | * pixels and 32K bytes." |
| 14609 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 14610 | return min(8192 * cpp, 32768); |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14611 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14612 | return 32*1024; |
| 14613 | } else if (gen >= 4) { |
| 14614 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14615 | return 16*1024; |
| 14616 | else |
| 14617 | return 32*1024; |
| 14618 | } else if (gen >= 3) { |
| 14619 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 14620 | return 8*1024; |
| 14621 | else |
| 14622 | return 16*1024; |
| 14623 | } else { |
| 14624 | /* XXX DSPC is limited to 4k tiled */ |
| 14625 | return 8*1024; |
| 14626 | } |
| 14627 | } |
| 14628 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 14629 | static int intel_framebuffer_init(struct drm_device *dev, |
| 14630 | struct intel_framebuffer *intel_fb, |
| 14631 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 14632 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14633 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14634 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 14635 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14636 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14637 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14638 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 14639 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 14640 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14641 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 14642 | /* Enforce that fb modifier and tiling mode match, but only for |
| 14643 | * X-tiled. This is needed for FBC. */ |
| 14644 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 14645 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 14646 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 14647 | return -EINVAL; |
| 14648 | } |
| 14649 | } else { |
| 14650 | if (obj->tiling_mode == I915_TILING_X) |
| 14651 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 14652 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 14653 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 14654 | return -EINVAL; |
| 14655 | } |
| 14656 | } |
| 14657 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 14658 | /* Passed in modifier sanity checking. */ |
| 14659 | switch (mode_cmd->modifier[0]) { |
| 14660 | case I915_FORMAT_MOD_Y_TILED: |
| 14661 | case I915_FORMAT_MOD_Yf_TILED: |
| 14662 | if (INTEL_INFO(dev)->gen < 9) { |
| 14663 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 14664 | mode_cmd->modifier[0]); |
| 14665 | return -EINVAL; |
| 14666 | } |
| 14667 | case DRM_FORMAT_MOD_NONE: |
| 14668 | case I915_FORMAT_MOD_X_TILED: |
| 14669 | break; |
| 14670 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 14671 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 14672 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14673 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14674 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14675 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 14676 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
| 14677 | mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14678 | mode_cmd->pixel_format); |
| 14679 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 14680 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 14681 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14682 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14683 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14684 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14685 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 14686 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14687 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 14688 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 14689 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14690 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 14691 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14692 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14693 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14694 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 14695 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14696 | mode_cmd->pitches[0] != obj->stride) { |
| 14697 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 14698 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14699 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14700 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 14701 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14702 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14703 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14704 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14705 | case DRM_FORMAT_RGB565: |
| 14706 | case DRM_FORMAT_XRGB8888: |
| 14707 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14708 | break; |
| 14709 | case DRM_FORMAT_XRGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14710 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14711 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14712 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14713 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14714 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14715 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14716 | case DRM_FORMAT_ABGR8888: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14717 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev) && |
| 14718 | INTEL_INFO(dev)->gen < 9) { |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 14719 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14720 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14721 | return -EINVAL; |
| 14722 | } |
| 14723 | break; |
| 14724 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14725 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14726 | case DRM_FORMAT_XBGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14727 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14728 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14729 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14730 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14731 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 14732 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14733 | case DRM_FORMAT_ABGR2101010: |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 14734 | if (!IS_VALLEYVIEW(dev) && !IS_CHERRYVIEW(dev)) { |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 14735 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14736 | drm_get_format_name(mode_cmd->pixel_format)); |
| 14737 | return -EINVAL; |
| 14738 | } |
| 14739 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 14740 | case DRM_FORMAT_YUYV: |
| 14741 | case DRM_FORMAT_UYVY: |
| 14742 | case DRM_FORMAT_YVYU: |
| 14743 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14744 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14745 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14746 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 14747 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 14748 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14749 | break; |
| 14750 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 14751 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 14752 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 14753 | return -EINVAL; |
| 14754 | } |
| 14755 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 14756 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 14757 | if (mode_cmd->offsets[0] != 0) |
| 14758 | return -EINVAL; |
| 14759 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 14760 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 14761 | mode_cmd->pixel_format, |
| 14762 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 14763 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 14764 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 14765 | return -EINVAL; |
| 14766 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 14767 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 14768 | intel_fb->obj = obj; |
| 14769 | |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 14770 | intel_fill_fb_info(dev_priv, &intel_fb->base); |
| 14771 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14772 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 14773 | if (ret) { |
| 14774 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 14775 | return ret; |
| 14776 | } |
| 14777 | |
Ville Syrjälä | 0b05e1e | 2016-01-14 15:22:09 +0200 | [diff] [blame] | 14778 | intel_fb->obj->framebuffer_references++; |
| 14779 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14780 | return 0; |
| 14781 | } |
| 14782 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14783 | static struct drm_framebuffer * |
| 14784 | intel_user_framebuffer_create(struct drm_device *dev, |
| 14785 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 14786 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14787 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14788 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 14789 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14790 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14791 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 14792 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 14793 | mode_cmd.handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 14794 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 14795 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14796 | |
Daniel Vetter | 92907cb | 2015-11-23 09:04:05 +0100 | [diff] [blame] | 14797 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 14798 | if (IS_ERR(fb)) |
| 14799 | drm_gem_object_unreference_unlocked(&obj->base); |
| 14800 | |
| 14801 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14802 | } |
| 14803 | |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 14804 | #ifndef CONFIG_DRM_FBDEV_EMULATION |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14805 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 14806 | { |
| 14807 | } |
| 14808 | #endif |
| 14809 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14810 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14811 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 14812 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 14813 | .atomic_check = intel_atomic_check, |
| 14814 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 14815 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 14816 | .atomic_state_clear = intel_atomic_state_clear, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14817 | }; |
| 14818 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14819 | /** |
| 14820 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 14821 | * @dev_priv: device private |
| 14822 | */ |
| 14823 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14824 | { |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14825 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14826 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14827 | dev_priv->display.get_initial_plane_config = |
| 14828 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 14829 | dev_priv->display.crtc_compute_clock = |
| 14830 | haswell_crtc_compute_clock; |
| 14831 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14832 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14833 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14834 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14835 | dev_priv->display.get_initial_plane_config = |
| 14836 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 14837 | dev_priv->display.crtc_compute_clock = |
| 14838 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 14839 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 14840 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14841 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14842 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14843 | dev_priv->display.get_initial_plane_config = |
| 14844 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 14845 | dev_priv->display.crtc_compute_clock = |
| 14846 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14847 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 14848 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14849 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14850 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14851 | dev_priv->display.get_initial_plane_config = |
| 14852 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 14853 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 14854 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14855 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 14856 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 14857 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14858 | dev_priv->display.get_initial_plane_config = |
| 14859 | i9xx_get_initial_plane_config; |
| 14860 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 14861 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 14862 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 14863 | } else if (IS_G4X(dev_priv)) { |
| 14864 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14865 | dev_priv->display.get_initial_plane_config = |
| 14866 | i9xx_get_initial_plane_config; |
| 14867 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 14868 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14869 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 14870 | } else if (IS_PINEVIEW(dev_priv)) { |
| 14871 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14872 | dev_priv->display.get_initial_plane_config = |
| 14873 | i9xx_get_initial_plane_config; |
| 14874 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 14875 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14876 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14877 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14878 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14879 | dev_priv->display.get_initial_plane_config = |
| 14880 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 14881 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 14882 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14883 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 14884 | } else { |
| 14885 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 14886 | dev_priv->display.get_initial_plane_config = |
| 14887 | i9xx_get_initial_plane_config; |
| 14888 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 14889 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 14890 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 14891 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14892 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14893 | /* Returns the core display clock speed */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14894 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14895 | dev_priv->display.get_display_clock_speed = |
| 14896 | skylake_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14897 | else if (IS_BROXTON(dev_priv)) |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 14898 | dev_priv->display.get_display_clock_speed = |
| 14899 | broxton_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14900 | else if (IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14901 | dev_priv->display.get_display_clock_speed = |
| 14902 | broadwell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14903 | else if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 14904 | dev_priv->display.get_display_clock_speed = |
| 14905 | haswell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14906 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 14907 | dev_priv->display.get_display_clock_speed = |
| 14908 | valleyview_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14909 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 14910 | dev_priv->display.get_display_clock_speed = |
| 14911 | ilk_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14912 | else if (IS_I945G(dev_priv) || IS_BROADWATER(dev_priv) || |
| 14913 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14914 | dev_priv->display.get_display_clock_speed = |
| 14915 | i945_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14916 | else if (IS_GM45(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14917 | dev_priv->display.get_display_clock_speed = |
| 14918 | gm45_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14919 | else if (IS_CRESTLINE(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14920 | dev_priv->display.get_display_clock_speed = |
| 14921 | i965gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14922 | else if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14923 | dev_priv->display.get_display_clock_speed = |
| 14924 | pnv_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14925 | else if (IS_G33(dev_priv) || IS_G4X(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 14926 | dev_priv->display.get_display_clock_speed = |
| 14927 | g33_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14928 | else if (IS_I915G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14929 | dev_priv->display.get_display_clock_speed = |
| 14930 | i915_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14931 | else if (IS_I945GM(dev_priv) || IS_845G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14932 | dev_priv->display.get_display_clock_speed = |
| 14933 | i9xx_misc_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14934 | else if (IS_I915GM(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14935 | dev_priv->display.get_display_clock_speed = |
| 14936 | i915gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14937 | else if (IS_I865G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14938 | dev_priv->display.get_display_clock_speed = |
| 14939 | i865_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14940 | else if (IS_I85X(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14941 | dev_priv->display.get_display_clock_speed = |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 14942 | i85x_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14943 | else { /* 830 */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14944 | WARN(!IS_I830(dev_priv), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14945 | dev_priv->display.get_display_clock_speed = |
| 14946 | i830_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 14947 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14948 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14949 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14950 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14951 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14952 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14953 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14954 | /* FIXME: detect B0+ stepping and use auto training */ |
| 14955 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14956 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 14957 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14958 | if (IS_BROADWELL(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14959 | dev_priv->display.modeset_commit_cdclk = |
| 14960 | broadwell_modeset_commit_cdclk; |
| 14961 | dev_priv->display.modeset_calc_cdclk = |
| 14962 | broadwell_modeset_calc_cdclk; |
| 14963 | } |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14964 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14965 | dev_priv->display.modeset_commit_cdclk = |
| 14966 | valleyview_modeset_commit_cdclk; |
| 14967 | dev_priv->display.modeset_calc_cdclk = |
| 14968 | valleyview_modeset_calc_cdclk; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14969 | } else if (IS_BROXTON(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14970 | dev_priv->display.modeset_commit_cdclk = |
| 14971 | broxton_modeset_commit_cdclk; |
| 14972 | dev_priv->display.modeset_calc_cdclk = |
| 14973 | broxton_modeset_calc_cdclk; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14974 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14975 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 14976 | switch (INTEL_INFO(dev_priv)->gen) { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 14977 | case 2: |
| 14978 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 14979 | break; |
| 14980 | |
| 14981 | case 3: |
| 14982 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 14983 | break; |
| 14984 | |
| 14985 | case 4: |
| 14986 | case 5: |
| 14987 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 14988 | break; |
| 14989 | |
| 14990 | case 6: |
| 14991 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 14992 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14993 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 14994 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 14995 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 14996 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 14997 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 14998 | /* Drop through - unsupported since execlist only. */ |
| 14999 | default: |
| 15000 | /* Default just returns -ENODEV to indicate unsupported */ |
| 15001 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 15002 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15003 | } |
| 15004 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15005 | /* |
| 15006 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 15007 | * resume, or other times. This quirk makes sure that's the case for |
| 15008 | * affected systems. |
| 15009 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 15010 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15011 | { |
| 15012 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15013 | |
| 15014 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15015 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15016 | } |
| 15017 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 15018 | static void quirk_pipeb_force(struct drm_device *dev) |
| 15019 | { |
| 15020 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15021 | |
| 15022 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 15023 | DRM_INFO("applying pipe b force quirk\n"); |
| 15024 | } |
| 15025 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15026 | /* |
| 15027 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 15028 | */ |
| 15029 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 15030 | { |
| 15031 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15032 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15033 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15034 | } |
| 15035 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 15036 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 15037 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 15038 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 15039 | */ |
| 15040 | static void quirk_invert_brightness(struct drm_device *dev) |
| 15041 | { |
| 15042 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15043 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 15044 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15045 | } |
| 15046 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 15047 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 15048 | static void quirk_backlight_present(struct drm_device *dev) |
| 15049 | { |
| 15050 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15051 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 15052 | DRM_INFO("applying backlight present quirk\n"); |
| 15053 | } |
| 15054 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15055 | struct intel_quirk { |
| 15056 | int device; |
| 15057 | int subsystem_vendor; |
| 15058 | int subsystem_device; |
| 15059 | void (*hook)(struct drm_device *dev); |
| 15060 | }; |
| 15061 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 15062 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 15063 | struct intel_dmi_quirk { |
| 15064 | void (*hook)(struct drm_device *dev); |
| 15065 | const struct dmi_system_id (*dmi_id_list)[]; |
| 15066 | }; |
| 15067 | |
| 15068 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 15069 | { |
| 15070 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 15071 | return 1; |
| 15072 | } |
| 15073 | |
| 15074 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 15075 | { |
| 15076 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 15077 | { |
| 15078 | .callback = intel_dmi_reverse_brightness, |
| 15079 | .ident = "NCR Corporation", |
| 15080 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 15081 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 15082 | }, |
| 15083 | }, |
| 15084 | { } /* terminating entry */ |
| 15085 | }, |
| 15086 | .hook = quirk_invert_brightness, |
| 15087 | }, |
| 15088 | }; |
| 15089 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 15090 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15091 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 15092 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 15093 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15094 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 15095 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 15096 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 15097 | /* 830 needs to leave pipe A & dpll A up */ |
| 15098 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 15099 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 15100 | /* 830 needs to leave pipe B & dpll B up */ |
| 15101 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 15102 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 15103 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 15104 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 15105 | |
| 15106 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 15107 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 15108 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 15109 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 15110 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 15111 | |
| 15112 | /* Acer/eMachines G725 */ |
| 15113 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 15114 | |
| 15115 | /* Acer/eMachines e725 */ |
| 15116 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 15117 | |
| 15118 | /* Acer/Packard Bell NCL20 */ |
| 15119 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 15120 | |
| 15121 | /* Acer Aspire 4736Z */ |
| 15122 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 15123 | |
| 15124 | /* Acer Aspire 5336 */ |
| 15125 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 15126 | |
| 15127 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 15128 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15129 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 15130 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 15131 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 15132 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 15133 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 15134 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 15135 | |
Jani Nikula | 1b9448b0 | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 15136 | /* Apple Macbook 4,1 */ |
| 15137 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 15138 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 15139 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 15140 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 15141 | |
| 15142 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 15143 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 15144 | |
| 15145 | /* Dell Chromebook 11 */ |
| 15146 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 15147 | |
| 15148 | /* Dell Chromebook 11 (2015 version) */ |
| 15149 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15150 | }; |
| 15151 | |
| 15152 | static void intel_init_quirks(struct drm_device *dev) |
| 15153 | { |
| 15154 | struct pci_dev *d = dev->pdev; |
| 15155 | int i; |
| 15156 | |
| 15157 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 15158 | struct intel_quirk *q = &intel_quirks[i]; |
| 15159 | |
| 15160 | if (d->device == q->device && |
| 15161 | (d->subsystem_vendor == q->subsystem_vendor || |
| 15162 | q->subsystem_vendor == PCI_ANY_ID) && |
| 15163 | (d->subsystem_device == q->subsystem_device || |
| 15164 | q->subsystem_device == PCI_ANY_ID)) |
| 15165 | q->hook(dev); |
| 15166 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 15167 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 15168 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 15169 | intel_dmi_quirks[i].hook(dev); |
| 15170 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15171 | } |
| 15172 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15173 | /* Disable the VGA plane that we never use */ |
| 15174 | static void i915_disable_vga(struct drm_device *dev) |
| 15175 | { |
| 15176 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15177 | u8 sr1; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15178 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15179 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 15180 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15181 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 15182 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15183 | sr1 = inb(VGA_SR_DATA); |
| 15184 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 15185 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 15186 | udelay(300); |
| 15187 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 15188 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15189 | POSTING_READ(vga_reg); |
| 15190 | } |
| 15191 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15192 | void intel_modeset_init_hw(struct drm_device *dev) |
| 15193 | { |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15194 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15195 | |
Ville Syrjälä | b628305 | 2015-06-03 15:45:07 +0300 | [diff] [blame] | 15196 | intel_update_cdclk(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 15197 | |
| 15198 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; |
| 15199 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15200 | intel_init_clock_gating(dev); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 15201 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 15202 | } |
| 15203 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15204 | /* |
| 15205 | * Calculate what we think the watermarks should be for the state we've read |
| 15206 | * out of the hardware and then immediately program those watermarks so that |
| 15207 | * we ensure the hardware settings match our internal state. |
| 15208 | * |
| 15209 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 15210 | * current state (which was constructed during hardware readout) and running it |
| 15211 | * through the atomic check code to calculate new watermark values in the |
| 15212 | * state object. |
| 15213 | */ |
| 15214 | static void sanitize_watermarks(struct drm_device *dev) |
| 15215 | { |
| 15216 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15217 | struct drm_atomic_state *state; |
| 15218 | struct drm_crtc *crtc; |
| 15219 | struct drm_crtc_state *cstate; |
| 15220 | struct drm_modeset_acquire_ctx ctx; |
| 15221 | int ret; |
| 15222 | int i; |
| 15223 | |
| 15224 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15225 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15226 | return; |
| 15227 | |
| 15228 | /* |
| 15229 | * We need to hold connection_mutex before calling duplicate_state so |
| 15230 | * that the connector loop is protected. |
| 15231 | */ |
| 15232 | drm_modeset_acquire_init(&ctx, 0); |
| 15233 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15234 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15235 | if (ret == -EDEADLK) { |
| 15236 | drm_modeset_backoff(&ctx); |
| 15237 | goto retry; |
| 15238 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15239 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15240 | } |
| 15241 | |
| 15242 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 15243 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15244 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15245 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15246 | /* |
| 15247 | * Hardware readout is the only time we don't want to calculate |
| 15248 | * intermediate watermarks (since we don't trust the current |
| 15249 | * watermarks). |
| 15250 | */ |
| 15251 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
| 15252 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15253 | ret = intel_atomic_check(dev, state); |
| 15254 | if (ret) { |
| 15255 | /* |
| 15256 | * If we fail here, it means that the hardware appears to be |
| 15257 | * programmed in a way that shouldn't be possible, given our |
| 15258 | * understanding of watermark requirements. This might mean a |
| 15259 | * mistake in the hardware readout code or a mistake in the |
| 15260 | * watermark calculations for a given platform. Raise a WARN |
| 15261 | * so that this is noticeable. |
| 15262 | * |
| 15263 | * If this actually happens, we'll have to just leave the |
| 15264 | * BIOS-programmed watermarks untouched and hope for the best. |
| 15265 | */ |
| 15266 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15267 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15268 | } |
| 15269 | |
| 15270 | /* Write calculated watermark values back */ |
| 15271 | to_i915(dev)->wm.config = to_intel_atomic_state(state)->wm_config; |
| 15272 | for_each_crtc_in_state(state, crtc, cstate, i) { |
| 15273 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 15274 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 15275 | cs->wm.need_postvbl_update = true; |
| 15276 | dev_priv->display.optimize_watermarks(cs); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15277 | } |
| 15278 | |
| 15279 | drm_atomic_state_free(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 15280 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15281 | drm_modeset_drop_locks(&ctx); |
| 15282 | drm_modeset_acquire_fini(&ctx); |
| 15283 | } |
| 15284 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15285 | void intel_modeset_init(struct drm_device *dev) |
| 15286 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15287 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15288 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15289 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15290 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15291 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15292 | |
| 15293 | drm_mode_config_init(dev); |
| 15294 | |
| 15295 | dev->mode_config.min_width = 0; |
| 15296 | dev->mode_config.min_height = 0; |
| 15297 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 15298 | dev->mode_config.preferred_depth = 24; |
| 15299 | dev->mode_config.prefer_shadow = 1; |
| 15300 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 15301 | dev->mode_config.allow_fb_modifiers = true; |
| 15302 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 15303 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15304 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 15305 | intel_init_quirks(dev); |
| 15306 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 15307 | intel_init_pm(dev); |
| 15308 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 15309 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 15310 | return; |
| 15311 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 15312 | /* |
| 15313 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 15314 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 15315 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 15316 | * indicates as much. |
| 15317 | */ |
| 15318 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) { |
| 15319 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 15320 | DREF_SSC1_ENABLE); |
| 15321 | |
| 15322 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 15323 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 15324 | bios_lvds_use_ssc ? "en" : "dis", |
| 15325 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 15326 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 15327 | } |
| 15328 | } |
| 15329 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15330 | if (IS_GEN2(dev)) { |
| 15331 | dev->mode_config.max_width = 2048; |
| 15332 | dev->mode_config.max_height = 2048; |
| 15333 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 15334 | dev->mode_config.max_width = 4096; |
| 15335 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15336 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 15337 | dev->mode_config.max_width = 8192; |
| 15338 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15339 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15340 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15341 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 15342 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 15343 | dev->mode_config.cursor_height = 1023; |
| 15344 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 15345 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 15346 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 15347 | } else { |
| 15348 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 15349 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 15350 | } |
| 15351 | |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 15352 | dev->mode_config.fb_base = ggtt->mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15353 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 15354 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15355 | INTEL_INFO(dev)->num_pipes, |
| 15356 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15357 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15358 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 15359 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 15360 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15361 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15362 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 15363 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 15364 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 15365 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15366 | } |
| 15367 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 15368 | intel_update_czclk(dev_priv); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 15369 | intel_update_rawclk(dev_priv); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 15370 | intel_update_cdclk(dev); |
| 15371 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 15372 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 15373 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 15374 | /* Just disable it once at startup */ |
| 15375 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15376 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 15377 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15378 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15379 | intel_modeset_setup_hw_state(dev); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15380 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15381 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15382 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15383 | struct intel_initial_plane_config plane_config = {}; |
| 15384 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15385 | if (!crtc->active) |
| 15386 | continue; |
| 15387 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15388 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15389 | * Note that reserving the BIOS fb up front prevents us |
| 15390 | * from stuffing other stolen allocations like the ring |
| 15391 | * on top. This prevents some ugliness at boot time, and |
| 15392 | * can even allow for smooth boot transitions if the BIOS |
| 15393 | * fb is large enough for the active pipe configuration. |
| 15394 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 15395 | dev_priv->display.get_initial_plane_config(crtc, |
| 15396 | &plane_config); |
| 15397 | |
| 15398 | /* |
| 15399 | * If the fb is shared between multiple heads, we'll |
| 15400 | * just get the first one. |
| 15401 | */ |
| 15402 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 15403 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 15404 | |
| 15405 | /* |
| 15406 | * Make sure hardware watermarks really match the state we read out. |
| 15407 | * Note that we need to do this after reconstructing the BIOS fb's |
| 15408 | * since the watermark calculation done here will use pstate->fb. |
| 15409 | */ |
| 15410 | sanitize_watermarks(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15411 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 15412 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15413 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 15414 | { |
| 15415 | struct intel_connector *connector; |
| 15416 | struct drm_connector *crt = NULL; |
| 15417 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15418 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15419 | |
| 15420 | /* We can't just switch on the pipe A, we need to set things up with a |
| 15421 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 15422 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15423 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15424 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 15425 | crt = &connector->base; |
| 15426 | break; |
| 15427 | } |
| 15428 | } |
| 15429 | |
| 15430 | if (!crt) |
| 15431 | return; |
| 15432 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 15433 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 15434 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15435 | } |
| 15436 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15437 | static bool |
| 15438 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 15439 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15440 | struct drm_device *dev = crtc->base.dev; |
| 15441 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15442 | u32 val; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15443 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 15444 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15445 | return true; |
| 15446 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 15447 | val = I915_READ(DSPCNTR(!crtc->plane)); |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15448 | |
| 15449 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 15450 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 15451 | return false; |
| 15452 | |
| 15453 | return true; |
| 15454 | } |
| 15455 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 15456 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 15457 | { |
| 15458 | struct drm_device *dev = crtc->base.dev; |
| 15459 | struct intel_encoder *encoder; |
| 15460 | |
| 15461 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 15462 | return true; |
| 15463 | |
| 15464 | return false; |
| 15465 | } |
| 15466 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15467 | static bool intel_encoder_has_connectors(struct intel_encoder *encoder) |
| 15468 | { |
| 15469 | struct drm_device *dev = encoder->base.dev; |
| 15470 | struct intel_connector *connector; |
| 15471 | |
| 15472 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 15473 | return true; |
| 15474 | |
| 15475 | return false; |
| 15476 | } |
| 15477 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15478 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 15479 | { |
| 15480 | struct drm_device *dev = crtc->base.dev; |
| 15481 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15482 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15483 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15484 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 15485 | if (!transcoder_is_dsi(cpu_transcoder)) { |
| 15486 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 15487 | |
| 15488 | I915_WRITE(reg, |
| 15489 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 15490 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15491 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15492 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15493 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 15494 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15495 | struct intel_plane *plane; |
| 15496 | |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15497 | drm_crtc_vblank_on(&crtc->base); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15498 | |
| 15499 | /* Disable everything but the primary plane */ |
| 15500 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 15501 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 15502 | continue; |
| 15503 | |
| 15504 | plane->disable_plane(&plane->base, &crtc->base); |
| 15505 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 15506 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 15507 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15508 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 15509 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 15510 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 15511 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15512 | bool plane; |
| 15513 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15514 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 15515 | crtc->base.base.id); |
| 15516 | |
| 15517 | /* Pipe has the wrong plane attached and the plane is active. |
| 15518 | * Temporarily change the plane mapping and disable everything |
| 15519 | * ... */ |
| 15520 | plane = crtc->plane; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15521 | to_intel_plane_state(crtc->base.primary->state)->visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15522 | crtc->plane = !plane; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15523 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15524 | crtc->plane = plane; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15525 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15526 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 15527 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 15528 | crtc->pipe == PIPE_A && !crtc->active) { |
| 15529 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 15530 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 15531 | * call below we restore the pipe to the right state, but leave |
| 15532 | * the required bits on. */ |
| 15533 | intel_enable_pipe_a(dev); |
| 15534 | } |
| 15535 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15536 | /* Adjust the state of the output pipe according to whether we |
| 15537 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 15538 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 15539 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15540 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 15541 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15542 | /* |
| 15543 | * We start out with underrun reporting disabled to avoid races. |
| 15544 | * For correct bookkeeping mark this on active crtcs. |
| 15545 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 15546 | * Also on gmch platforms we dont have any hardware bits to |
| 15547 | * disable the underrun reporting. Which means we need to start |
| 15548 | * out with underrun reporting disabled also on inactive pipes, |
| 15549 | * since otherwise we'll complain about the garbage we read when |
| 15550 | * e.g. coming up after runtime pm. |
| 15551 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 15552 | * No protection against concurrent access is required - at |
| 15553 | * worst a fifo underrun happens which also sets this to false. |
| 15554 | */ |
| 15555 | crtc->cpu_fifo_underrun_disabled = true; |
| 15556 | crtc->pch_fifo_underrun_disabled = true; |
| 15557 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15558 | } |
| 15559 | |
| 15560 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 15561 | { |
| 15562 | struct intel_connector *connector; |
| 15563 | struct drm_device *dev = encoder->base.dev; |
| 15564 | |
| 15565 | /* We need to check both for a crtc link (meaning that the |
| 15566 | * encoder is active and trying to read from a pipe) and the |
| 15567 | * pipe itself being active. */ |
| 15568 | bool has_active_crtc = encoder->base.crtc && |
| 15569 | to_intel_crtc(encoder->base.crtc)->active; |
| 15570 | |
Ville Syrjälä | dd75619 | 2016-02-17 21:28:45 +0200 | [diff] [blame] | 15571 | if (intel_encoder_has_connectors(encoder) && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15572 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 15573 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15574 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15575 | |
| 15576 | /* Connector is active, but has no active pipe. This is |
| 15577 | * fallout from our resume register restoring. Disable |
| 15578 | * the encoder manually again. */ |
| 15579 | if (encoder->base.crtc) { |
| 15580 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 15581 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15582 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15583 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 15584 | if (encoder->post_disable) |
| 15585 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15586 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15587 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15588 | |
| 15589 | /* Inconsistent output/port/pipe state happens presumably due to |
| 15590 | * a bug in one of the get_hw_state functions. Or someplace else |
| 15591 | * in our code, like the register restore mess on resume. Clamp |
| 15592 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15593 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15594 | if (connector->encoder != encoder) |
| 15595 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 15596 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15597 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15598 | } |
| 15599 | } |
| 15600 | /* Enabled encoders without active connectors will be fixed in |
| 15601 | * the crtc fixup. */ |
| 15602 | } |
| 15603 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15604 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15605 | { |
| 15606 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 15607 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15608 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15609 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 15610 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 15611 | i915_disable_vga(dev); |
| 15612 | } |
| 15613 | } |
| 15614 | |
| 15615 | void i915_redisable_vga(struct drm_device *dev) |
| 15616 | { |
| 15617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15618 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15619 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 15620 | * at a very early point in our resume sequence, where the power well |
| 15621 | * structures are not yet restored. Since this function is at a very |
| 15622 | * paranoid "someone might have enabled VGA while we were not looking" |
| 15623 | * level, just check if the power well is enabled instead of trying to |
| 15624 | * follow the "don't touch the power well if we don't need it" policy |
| 15625 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15626 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 15627 | return; |
| 15628 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 15629 | i915_redisable_vga_power_on(dev); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 15630 | |
| 15631 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 15632 | } |
| 15633 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15634 | static bool primary_get_hw_state(struct intel_plane *plane) |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15635 | { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15636 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15637 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15638 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15639 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15640 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15641 | /* FIXME read out full plane state for all planes */ |
| 15642 | static void readout_plane_state(struct intel_crtc *crtc) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15643 | { |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15644 | struct drm_plane *primary = crtc->base.primary; |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15645 | struct intel_plane_state *plane_state = |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15646 | to_intel_plane_state(primary->state); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 15647 | |
Matt Roper | 19b8d38 | 2015-09-24 15:53:17 -0700 | [diff] [blame] | 15648 | plane_state->visible = crtc->active && |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 15649 | primary_get_hw_state(to_intel_plane(primary)); |
| 15650 | |
| 15651 | if (plane_state->visible) |
| 15652 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 15653 | } |
| 15654 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15655 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15656 | { |
| 15657 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15658 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15659 | struct intel_crtc *crtc; |
| 15660 | struct intel_encoder *encoder; |
| 15661 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15662 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15663 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15664 | dev_priv->active_crtcs = 0; |
| 15665 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15666 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15667 | struct intel_crtc_state *crtc_state = crtc->config; |
| 15668 | int pixclk = 0; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 15669 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15670 | __drm_atomic_helper_crtc_destroy_state(&crtc->base, &crtc_state->base); |
| 15671 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 15672 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15673 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 15674 | crtc_state->base.active = crtc_state->base.enable = |
| 15675 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 15676 | |
| 15677 | crtc->base.enabled = crtc_state->base.enable; |
| 15678 | crtc->active = crtc_state->base.active; |
| 15679 | |
| 15680 | if (crtc_state->base.active) { |
| 15681 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 15682 | |
| 15683 | if (IS_BROADWELL(dev_priv)) { |
| 15684 | pixclk = ilk_pipe_pixel_rate(crtc_state); |
| 15685 | |
| 15686 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 15687 | if (crtc_state->ips_enabled) |
| 15688 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); |
| 15689 | } else if (IS_VALLEYVIEW(dev_priv) || |
| 15690 | IS_CHERRYVIEW(dev_priv) || |
| 15691 | IS_BROXTON(dev_priv)) |
| 15692 | pixclk = crtc_state->base.adjusted_mode.crtc_clock; |
| 15693 | else |
| 15694 | WARN_ON(dev_priv->display.modeset_calc_cdclk); |
| 15695 | } |
| 15696 | |
| 15697 | dev_priv->min_pixclk[crtc->pipe] = pixclk; |
Maarten Lankhorst | b70709a | 2015-04-21 17:12:53 +0300 | [diff] [blame] | 15698 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 15699 | readout_plane_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15700 | |
| 15701 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 15702 | crtc->base.base.id, |
| 15703 | crtc->active ? "enabled" : "disabled"); |
| 15704 | } |
| 15705 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15706 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15707 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15708 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 15709 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
| 15710 | &pll->config.hw_state); |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15711 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 15712 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15713 | if (crtc->active && crtc->config->shared_dpll == pll) |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15714 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15715 | } |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15716 | pll->active_mask = pll->config.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15717 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 15718 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 15719 | pll->name, pll->config.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 15720 | } |
| 15721 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15722 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15723 | pipe = 0; |
| 15724 | |
| 15725 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 15726 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15727 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15728 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15729 | } else { |
| 15730 | encoder->base.crtc = NULL; |
| 15731 | } |
| 15732 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15733 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15734 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 15735 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15736 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 15737 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15738 | } |
| 15739 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 15740 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15741 | if (connector->get_hw_state(connector)) { |
| 15742 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15743 | |
| 15744 | encoder = connector->encoder; |
| 15745 | connector->base.encoder = &encoder->base; |
| 15746 | |
| 15747 | if (encoder->base.crtc && |
| 15748 | encoder->base.crtc->state->active) { |
| 15749 | /* |
| 15750 | * This has to be done during hardware readout |
| 15751 | * because anything calling .crtc_disable may |
| 15752 | * rely on the connector_mask being accurate. |
| 15753 | */ |
| 15754 | encoder->base.crtc->state->connector_mask |= |
| 15755 | 1 << drm_connector_index(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 15756 | encoder->base.crtc->state->encoder_mask |= |
| 15757 | 1 << drm_encoder_index(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 15758 | } |
| 15759 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15760 | } else { |
| 15761 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 15762 | connector->base.encoder = NULL; |
| 15763 | } |
| 15764 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 15765 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 15766 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15767 | connector->base.encoder ? "enabled" : "disabled"); |
| 15768 | } |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15769 | |
| 15770 | for_each_intel_crtc(dev, crtc) { |
| 15771 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
| 15772 | |
| 15773 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
| 15774 | if (crtc->base.state->active) { |
| 15775 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); |
| 15776 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); |
| 15777 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 15778 | |
| 15779 | /* |
| 15780 | * The initial mode needs to be set in order to keep |
| 15781 | * the atomic core happy. It wants a valid mode if the |
| 15782 | * crtc's enabled, so we do the above call. |
| 15783 | * |
| 15784 | * At this point some state updated by the connectors |
| 15785 | * in their ->detect() callback has not run yet, so |
| 15786 | * no recalculation can be done yet. |
| 15787 | * |
| 15788 | * Even if we could do a recalculation and modeset |
| 15789 | * right now it would cause a double modeset if |
| 15790 | * fbdev or userspace chooses a different initial mode. |
| 15791 | * |
| 15792 | * If that happens, someone indicated they wanted a |
| 15793 | * mode change, which means it's safe to do a full |
| 15794 | * recalculation. |
| 15795 | */ |
| 15796 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 15797 | |
| 15798 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
| 15799 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15800 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 15801 | |
| 15802 | intel_pipe_config_sanity_check(dev_priv, crtc->config); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 15803 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15804 | } |
| 15805 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15806 | /* Scan out the current hw modeset state, |
| 15807 | * and sanitizes it to the current state |
| 15808 | */ |
| 15809 | static void |
| 15810 | intel_modeset_setup_hw_state(struct drm_device *dev) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15811 | { |
| 15812 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 15813 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15814 | struct intel_crtc *crtc; |
| 15815 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15816 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 15817 | |
| 15818 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15819 | |
| 15820 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15821 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15822 | intel_sanitize_encoder(encoder); |
| 15823 | } |
| 15824 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 15825 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15826 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 15827 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 15828 | intel_dump_pipe_config(crtc, crtc->config, |
| 15829 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 15830 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 15831 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 15832 | intel_modeset_update_connector_atomic_state(dev); |
| 15833 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15834 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 15835 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 15836 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 15837 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15838 | continue; |
| 15839 | |
| 15840 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 15841 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 15842 | pll->funcs.disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 15843 | pll->on = false; |
| 15844 | } |
| 15845 | |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 15846 | if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 15847 | vlv_wm_get_hw_state(dev); |
| 15848 | else if (IS_GEN9(dev)) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 15849 | skl_wm_get_hw_state(dev); |
| 15850 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 15851 | ilk_wm_get_hw_state(dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15852 | |
| 15853 | for_each_intel_crtc(dev, crtc) { |
| 15854 | unsigned long put_domains; |
| 15855 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 15856 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 15857 | if (WARN_ON(put_domains)) |
| 15858 | modeset_put_power_domains(dev_priv, put_domains); |
| 15859 | } |
| 15860 | intel_display_set_init_power(dev_priv, false); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 15861 | |
| 15862 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15863 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 15864 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15865 | void intel_display_resume(struct drm_device *dev) |
| 15866 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15867 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 15868 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 15869 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15870 | int ret; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15871 | bool setup = false; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 15872 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15873 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15874 | |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 15875 | /* |
| 15876 | * This is a cludge because with real atomic modeset mode_config.mutex |
| 15877 | * won't be taken. Unfortunately some probed state like |
| 15878 | * audio_codec_enable is still protected by mode_config.mutex, so lock |
| 15879 | * it here for now. |
| 15880 | */ |
| 15881 | mutex_lock(&dev->mode_config.mutex); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15882 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15883 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15884 | retry: |
| 15885 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15886 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15887 | if (ret == 0 && !setup) { |
| 15888 | setup = true; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15889 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15890 | intel_modeset_setup_hw_state(dev); |
| 15891 | i915_redisable_vga(dev); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 15892 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 15893 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15894 | if (ret == 0 && state) { |
| 15895 | struct drm_crtc_state *crtc_state; |
| 15896 | struct drm_crtc *crtc; |
| 15897 | int i; |
| 15898 | |
| 15899 | state->acquire_ctx = &ctx; |
| 15900 | |
| 15901 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 15902 | /* |
| 15903 | * Force recalculation even if we restore |
| 15904 | * current state. With fast modeset this may not result |
| 15905 | * in a modeset when the state is compatible. |
| 15906 | */ |
| 15907 | crtc_state->mode_changed = true; |
| 15908 | } |
| 15909 | |
| 15910 | ret = drm_atomic_commit(state); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15911 | } |
| 15912 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15913 | if (ret == -EDEADLK) { |
| 15914 | drm_modeset_backoff(&ctx); |
| 15915 | goto retry; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15916 | } |
| 15917 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15918 | drm_modeset_drop_locks(&ctx); |
| 15919 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 15920 | mutex_unlock(&dev->mode_config.mutex); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 15921 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 15922 | if (ret) { |
| 15923 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 15924 | drm_atomic_state_free(state); |
| 15925 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 15926 | } |
| 15927 | |
| 15928 | void intel_modeset_gem_init(struct drm_device *dev) |
| 15929 | { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15930 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15931 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15932 | int ret; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15933 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15934 | intel_init_gt_powersave(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 15935 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 15936 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 15937 | |
| 15938 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15939 | |
| 15940 | /* |
| 15941 | * Make sure any fbs we allocated at startup are properly |
| 15942 | * pinned & fenced. When we do the allocation it's too early |
| 15943 | * for this. |
| 15944 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 15945 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 15946 | obj = intel_fb_obj(c->primary->fb); |
| 15947 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15948 | continue; |
| 15949 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15950 | mutex_lock(&dev->struct_mutex); |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 15951 | ret = intel_pin_and_fence_fb_obj(c->primary->fb, |
| 15952 | c->primary->state->rotation); |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 15953 | mutex_unlock(&dev->struct_mutex); |
| 15954 | if (ret) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15955 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 15956 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 15957 | drm_framebuffer_unreference(c->primary->fb); |
| 15958 | c->primary->fb = NULL; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15959 | c->primary->crtc = c->primary->state->crtc = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 15960 | update_state_fb(c->primary); |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 15961 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 15962 | } |
| 15963 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15964 | |
| 15965 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15966 | } |
| 15967 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15968 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 15969 | { |
| 15970 | struct drm_connector *connector = &intel_connector->base; |
| 15971 | |
| 15972 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 15973 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 15974 | } |
| 15975 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15976 | void intel_modeset_cleanup(struct drm_device *dev) |
| 15977 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15978 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 15979 | struct intel_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 15980 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15981 | intel_disable_gt_powersave(dev); |
| 15982 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 15983 | intel_backlight_unregister(dev); |
| 15984 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15985 | /* |
| 15986 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 15987 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15988 | * experience fancy races otherwise. |
| 15989 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 15990 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 15991 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15992 | /* |
| 15993 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 15994 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 15995 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 15996 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 15997 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 15998 | intel_unregister_dsm_handler(); |
| 15999 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 16000 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 16001 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 16002 | /* flush any delayed tasks or pending work */ |
| 16003 | flush_scheduled_work(); |
| 16004 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 16005 | /* destroy the backlight and sysfs files before encoders/connectors */ |
Jani Nikula | 19c8054 | 2015-12-16 12:48:16 +0200 | [diff] [blame] | 16006 | for_each_intel_connector(dev, connector) |
| 16007 | connector->unregister(connector); |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 16008 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16009 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 16010 | |
| 16011 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16012 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 16013 | intel_cleanup_gt_powersave(dev); |
Daniel Vetter | f594914 | 2016-01-13 11:55:28 +0100 | [diff] [blame] | 16014 | |
| 16015 | intel_teardown_gmbus(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16016 | } |
| 16017 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16018 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 16019 | * Return which encoder is currently attached for connector. |
| 16020 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16021 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16022 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16023 | return &intel_attached_encoder(connector)->base; |
| 16024 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16025 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 16026 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 16027 | struct intel_encoder *encoder) |
| 16028 | { |
| 16029 | connector->encoder = encoder; |
| 16030 | drm_mode_connector_attach_encoder(&connector->base, |
| 16031 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16032 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16033 | |
| 16034 | /* |
| 16035 | * set vga decode state - true == enable VGA decode |
| 16036 | */ |
| 16037 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 16038 | { |
| 16039 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 16040 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16041 | u16 gmch_ctrl; |
| 16042 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16043 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 16044 | DRM_ERROR("failed to read control word\n"); |
| 16045 | return -EIO; |
| 16046 | } |
| 16047 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 16048 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 16049 | return 0; |
| 16050 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16051 | if (state) |
| 16052 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 16053 | else |
| 16054 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 16055 | |
| 16056 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 16057 | DRM_ERROR("failed to write control word\n"); |
| 16058 | return -EIO; |
| 16059 | } |
| 16060 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 16061 | return 0; |
| 16062 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16063 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16064 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16065 | |
| 16066 | u32 power_well_driver; |
| 16067 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16068 | int num_transcoders; |
| 16069 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16070 | struct intel_cursor_error_state { |
| 16071 | u32 control; |
| 16072 | u32 position; |
| 16073 | u32 base; |
| 16074 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16075 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16076 | |
| 16077 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16078 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16079 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16080 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16081 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16082 | |
| 16083 | struct intel_plane_error_state { |
| 16084 | u32 control; |
| 16085 | u32 stride; |
| 16086 | u32 size; |
| 16087 | u32 pos; |
| 16088 | u32 addr; |
| 16089 | u32 surface; |
| 16090 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 16091 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16092 | |
| 16093 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16094 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16095 | enum transcoder cpu_transcoder; |
| 16096 | |
| 16097 | u32 conf; |
| 16098 | |
| 16099 | u32 htotal; |
| 16100 | u32 hblank; |
| 16101 | u32 hsync; |
| 16102 | u32 vtotal; |
| 16103 | u32 vblank; |
| 16104 | u32 vsync; |
| 16105 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16106 | }; |
| 16107 | |
| 16108 | struct intel_display_error_state * |
| 16109 | intel_display_capture_error_state(struct drm_device *dev) |
| 16110 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 16111 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16112 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16113 | int transcoders[] = { |
| 16114 | TRANSCODER_A, |
| 16115 | TRANSCODER_B, |
| 16116 | TRANSCODER_C, |
| 16117 | TRANSCODER_EDP, |
| 16118 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16119 | int i; |
| 16120 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16121 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 16122 | return NULL; |
| 16123 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16124 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16125 | if (error == NULL) |
| 16126 | return NULL; |
| 16127 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 16128 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16129 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 16130 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16131 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16132 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16133 | __intel_display_power_is_enabled(dev_priv, |
| 16134 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16135 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16136 | continue; |
| 16137 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 16138 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 16139 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 16140 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16141 | |
| 16142 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 16143 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16144 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 16145 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16146 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 16147 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 16148 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 16149 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16150 | if (INTEL_INFO(dev)->gen >= 4) { |
| 16151 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 16152 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 16153 | } |
| 16154 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16155 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16156 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 16157 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16158 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16159 | } |
| 16160 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16161 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16162 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 16163 | if (HAS_DDI(dev_priv->dev)) |
| 16164 | error->num_transcoders++; /* Account for eDP. */ |
| 16165 | |
| 16166 | for (i = 0; i < error->num_transcoders; i++) { |
| 16167 | enum transcoder cpu_transcoder = transcoders[i]; |
| 16168 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16169 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 16170 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 16171 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16172 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 16173 | continue; |
| 16174 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16175 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 16176 | |
| 16177 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 16178 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 16179 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 16180 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 16181 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 16182 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 16183 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16184 | } |
| 16185 | |
| 16186 | return error; |
| 16187 | } |
| 16188 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16189 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 16190 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16191 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16192 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16193 | struct drm_device *dev, |
| 16194 | struct intel_display_error_state *error) |
| 16195 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16196 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16197 | int i; |
| 16198 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16199 | if (!error) |
| 16200 | return; |
| 16201 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16202 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 16203 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16204 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 16205 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16206 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16207 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16208 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16209 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16210 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 16211 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16212 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16213 | err_printf(m, "Plane [%d]:\n", i); |
| 16214 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 16215 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16216 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16217 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 16218 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 16219 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 16220 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16221 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16222 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16223 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 16224 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16225 | } |
| 16226 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 16227 | err_printf(m, "Cursor [%d]:\n", i); |
| 16228 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 16229 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 16230 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16231 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16232 | |
| 16233 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 16234 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16235 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 16236 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 16237 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 16238 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 16239 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 16240 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 16241 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 16242 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 16243 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 16244 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 16245 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 16246 | } |