Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Daniel Vetter | 618563e | 2012-04-01 13:38:50 +0200 | [diff] [blame] | 27 | #include <linux/dmi.h> |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 34 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
Chris Wilson | 5d723d7 | 2016-08-04 16:32:35 +0100 | [diff] [blame] | 37 | #include "intel_frontbuffer.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 38 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 39 | #include "i915_drv.h" |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 40 | #include "intel_dsi.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 41 | #include "i915_trace.h" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 42 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 43 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 44 | #include <drm/drm_dp_helper.h> |
| 45 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 46 | #include <drm/drm_plane_helper.h> |
| 47 | #include <drm/drm_rect.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 48 | #include <linux/dma_remapping.h> |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 49 | #include <linux/reservation.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 50 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 51 | static bool is_mmio_work(struct intel_flip_work *work) |
| 52 | { |
| 53 | return work->mmio_work.func; |
| 54 | } |
| 55 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 56 | /* Primary plane formats for gen <= 3 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 57 | static const uint32_t i8xx_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 58 | DRM_FORMAT_C8, |
| 59 | DRM_FORMAT_RGB565, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 60 | DRM_FORMAT_XRGB1555, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 61 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /* Primary plane formats for gen >= 4 */ |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 65 | static const uint32_t i965_primary_formats[] = { |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 66 | DRM_FORMAT_C8, |
| 67 | DRM_FORMAT_RGB565, |
| 68 | DRM_FORMAT_XRGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 69 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 70 | DRM_FORMAT_XRGB2101010, |
| 71 | DRM_FORMAT_XBGR2101010, |
| 72 | }; |
| 73 | |
| 74 | static const uint32_t skl_primary_formats[] = { |
| 75 | DRM_FORMAT_C8, |
| 76 | DRM_FORMAT_RGB565, |
| 77 | DRM_FORMAT_XRGB8888, |
| 78 | DRM_FORMAT_XBGR8888, |
Damien Lespiau | 67fe7dc | 2015-05-15 19:06:00 +0100 | [diff] [blame] | 79 | DRM_FORMAT_ARGB8888, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 80 | DRM_FORMAT_ABGR8888, |
| 81 | DRM_FORMAT_XRGB2101010, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 82 | DRM_FORMAT_XBGR2101010, |
Kumar, Mahesh | ea916ea | 2015-09-03 16:17:09 +0530 | [diff] [blame] | 83 | DRM_FORMAT_YUYV, |
| 84 | DRM_FORMAT_YVYU, |
| 85 | DRM_FORMAT_UYVY, |
| 86 | DRM_FORMAT_VYUY, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 89 | /* Cursor formats */ |
| 90 | static const uint32_t intel_cursor_formats[] = { |
| 91 | DRM_FORMAT_ARGB8888, |
| 92 | }; |
| 93 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 94 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 95 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 96 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 97 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 98 | |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 99 | static int intel_framebuffer_init(struct drm_device *dev, |
| 100 | struct intel_framebuffer *ifb, |
| 101 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 102 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 103 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 104 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 105 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 106 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 107 | struct intel_link_m_n *m_n, |
| 108 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 109 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 110 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 111 | static void haswell_set_pipemisc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 112 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 113 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 114 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 115 | const struct intel_crtc_state *pipe_config); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 116 | static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
| 117 | static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *); |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 118 | static void skl_init_scalers(struct drm_i915_private *dev_priv, |
| 119 | struct intel_crtc *crtc, |
| 120 | struct intel_crtc_state *crtc_state); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 121 | static void skylake_pfit_enable(struct intel_crtc *crtc); |
| 122 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force); |
| 123 | static void ironlake_pfit_enable(struct intel_crtc *crtc); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 124 | static void intel_modeset_setup_hw_state(struct drm_device *dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 125 | static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc); |
Ville Syrjälä | 4e5ca60 | 2016-05-11 22:44:44 +0300 | [diff] [blame] | 126 | static int ilk_max_pixel_rate(struct drm_atomic_state *state); |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 127 | static int glk_calc_cdclk(int max_pixclk); |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 128 | static int bxt_calc_cdclk(int max_pixclk); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 129 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 130 | struct intel_limit { |
Ander Conselvan de Oliveira | 4c5def9 | 2016-05-04 12:11:58 +0300 | [diff] [blame] | 131 | struct { |
| 132 | int min, max; |
| 133 | } dot, vco, n, m, m1, m2, p, p1; |
| 134 | |
| 135 | struct { |
| 136 | int dot_limit; |
| 137 | int p2_slow, p2_fast; |
| 138 | } p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 139 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 140 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 141 | /* returns HPLL frequency in kHz */ |
| 142 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
| 143 | { |
| 144 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
| 145 | |
| 146 | /* Obtain SKU information */ |
| 147 | mutex_lock(&dev_priv->sb_lock); |
| 148 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 149 | CCK_FUSE_HPLL_FREQ_MASK; |
| 150 | mutex_unlock(&dev_priv->sb_lock); |
| 151 | |
| 152 | return vco_freq[hpll_freq] * 1000; |
| 153 | } |
| 154 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 155 | int vlv_get_cck_clock(struct drm_i915_private *dev_priv, |
| 156 | const char *name, u32 reg, int ref_freq) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 157 | { |
| 158 | u32 val; |
| 159 | int divider; |
| 160 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 161 | mutex_lock(&dev_priv->sb_lock); |
| 162 | val = vlv_cck_read(dev_priv, reg); |
| 163 | mutex_unlock(&dev_priv->sb_lock); |
| 164 | |
| 165 | divider = val & CCK_FREQUENCY_VALUES; |
| 166 | |
| 167 | WARN((val & CCK_FREQUENCY_STATUS) != |
| 168 | (divider << CCK_FREQUENCY_STATUS_SHIFT), |
| 169 | "%s change in progress\n", name); |
| 170 | |
Ville Syrjälä | c30fec6 | 2016-03-04 21:43:02 +0200 | [diff] [blame] | 171 | return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1); |
| 172 | } |
| 173 | |
| 174 | static int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv, |
| 175 | const char *name, u32 reg) |
| 176 | { |
| 177 | if (dev_priv->hpll_freq == 0) |
| 178 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 179 | |
| 180 | return vlv_get_cck_clock(dev_priv, name, reg, |
| 181 | dev_priv->hpll_freq); |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 182 | } |
| 183 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 184 | static int |
| 185 | intel_pch_rawclk(struct drm_i915_private *dev_priv) |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 186 | { |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 187 | return (I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK) * 1000; |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 190 | static int |
| 191 | intel_vlv_hrawclk(struct drm_i915_private *dev_priv) |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 192 | { |
Ville Syrjälä | 19ab4ed | 2016-04-27 17:43:22 +0300 | [diff] [blame] | 193 | /* RAWCLK_FREQ_VLV register updated from power well code */ |
Ville Syrjälä | 35d38d1 | 2016-03-02 17:22:16 +0200 | [diff] [blame] | 194 | return vlv_get_cck_clock_hpll(dev_priv, "hrawclk", |
| 195 | CCK_DISPLAY_REF_CLOCK_CONTROL); |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | static int |
| 199 | intel_g4x_hrawclk(struct drm_i915_private *dev_priv) |
| 200 | { |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 201 | uint32_t clkcfg; |
| 202 | |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 203 | /* hrawclock is 1/4 the FSB frequency */ |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 204 | clkcfg = I915_READ(CLKCFG); |
| 205 | switch (clkcfg & CLKCFG_FSB_MASK) { |
| 206 | case CLKCFG_FSB_400: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 207 | return 100000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 208 | case CLKCFG_FSB_533: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 209 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 210 | case CLKCFG_FSB_667: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 211 | return 166667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 212 | case CLKCFG_FSB_800: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 213 | return 200000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 214 | case CLKCFG_FSB_1067: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 215 | return 266667; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 216 | case CLKCFG_FSB_1333: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 217 | return 333333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 218 | /* these two are just a guess; one of them might be right */ |
| 219 | case CLKCFG_FSB_1600: |
| 220 | case CLKCFG_FSB_1600_ALT: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 221 | return 400000; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 222 | default: |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 223 | return 133333; |
Jani Nikula | 79e50a4 | 2015-08-26 10:58:20 +0300 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
Ville Syrjälä | 19ab4ed | 2016-04-27 17:43:22 +0300 | [diff] [blame] | 227 | void intel_update_rawclk(struct drm_i915_private *dev_priv) |
Ville Syrjälä | e7dc33f | 2016-03-02 17:22:13 +0200 | [diff] [blame] | 228 | { |
| 229 | if (HAS_PCH_SPLIT(dev_priv)) |
| 230 | dev_priv->rawclk_freq = intel_pch_rawclk(dev_priv); |
| 231 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 232 | dev_priv->rawclk_freq = intel_vlv_hrawclk(dev_priv); |
| 233 | else if (IS_G4X(dev_priv) || IS_PINEVIEW(dev_priv)) |
| 234 | dev_priv->rawclk_freq = intel_g4x_hrawclk(dev_priv); |
| 235 | else |
| 236 | return; /* no rawclk on other platforms, or no need to know it */ |
| 237 | |
| 238 | DRM_DEBUG_DRIVER("rawclk rate: %d kHz\n", dev_priv->rawclk_freq); |
| 239 | } |
| 240 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 241 | static void intel_update_czclk(struct drm_i915_private *dev_priv) |
| 242 | { |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 243 | if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))) |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 244 | return; |
| 245 | |
| 246 | dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk", |
| 247 | CCK_CZ_CLOCK_CONTROL); |
| 248 | |
| 249 | DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq); |
| 250 | } |
| 251 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 252 | static inline u32 /* units of 100MHz */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 253 | intel_fdi_link_freq(struct drm_i915_private *dev_priv, |
| 254 | const struct intel_crtc_state *pipe_config) |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 255 | { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 256 | if (HAS_DDI(dev_priv)) |
| 257 | return pipe_config->port_clock; /* SPLL */ |
| 258 | else if (IS_GEN5(dev_priv)) |
| 259 | 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] | 260 | else |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 261 | return 270000; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 264 | static const struct intel_limit intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 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 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [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 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 273 | .p2 = { .dot_limit = 165000, |
| 274 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 275 | }; |
| 276 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 277 | static const struct intel_limit intel_limits_i8xx_dvo = { |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [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 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [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 = 2, .max = 33 }, |
| 286 | .p2 = { .dot_limit = 165000, |
| 287 | .p2_slow = 4, .p2_fast = 4 }, |
| 288 | }; |
| 289 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 290 | static const struct intel_limit intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 291 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 292 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 293 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 294 | .m = { .min = 96, .max = 140 }, |
| 295 | .m1 = { .min = 18, .max = 26 }, |
| 296 | .m2 = { .min = 6, .max = 16 }, |
| 297 | .p = { .min = 4, .max = 128 }, |
| 298 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 299 | .p2 = { .dot_limit = 165000, |
| 300 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 301 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 302 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 303 | static const struct intel_limit intel_limits_i9xx_sdvo = { |
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 | 4f7dfb6 | 2013-02-13 22:20:22 +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 = 5, .max = 80 }, |
| 311 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 312 | .p2 = { .dot_limit = 200000, |
| 313 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 316 | static const struct intel_limit intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 317 | .dot = { .min = 20000, .max = 400000 }, |
| 318 | .vco = { .min = 1400000, .max = 2800000 }, |
| 319 | .n = { .min = 1, .max = 6 }, |
| 320 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 321 | .m1 = { .min = 8, .max = 18 }, |
| 322 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 323 | .p = { .min = 7, .max = 98 }, |
| 324 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 325 | .p2 = { .dot_limit = 112000, |
| 326 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 329 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 330 | static const struct intel_limit intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 331 | .dot = { .min = 25000, .max = 270000 }, |
| 332 | .vco = { .min = 1750000, .max = 3500000}, |
| 333 | .n = { .min = 1, .max = 4 }, |
| 334 | .m = { .min = 104, .max = 138 }, |
| 335 | .m1 = { .min = 17, .max = 23 }, |
| 336 | .m2 = { .min = 5, .max = 11 }, |
| 337 | .p = { .min = 10, .max = 30 }, |
| 338 | .p1 = { .min = 1, .max = 3}, |
| 339 | .p2 = { .dot_limit = 270000, |
| 340 | .p2_slow = 10, |
| 341 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 342 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 343 | }; |
| 344 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 345 | static const struct intel_limit intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 346 | .dot = { .min = 22000, .max = 400000 }, |
| 347 | .vco = { .min = 1750000, .max = 3500000}, |
| 348 | .n = { .min = 1, .max = 4 }, |
| 349 | .m = { .min = 104, .max = 138 }, |
| 350 | .m1 = { .min = 16, .max = 23 }, |
| 351 | .m2 = { .min = 5, .max = 11 }, |
| 352 | .p = { .min = 5, .max = 80 }, |
| 353 | .p1 = { .min = 1, .max = 8}, |
| 354 | .p2 = { .dot_limit = 165000, |
| 355 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 358 | static const struct intel_limit intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 359 | .dot = { .min = 20000, .max = 115000 }, |
| 360 | .vco = { .min = 1750000, .max = 3500000 }, |
| 361 | .n = { .min = 1, .max = 3 }, |
| 362 | .m = { .min = 104, .max = 138 }, |
| 363 | .m1 = { .min = 17, .max = 23 }, |
| 364 | .m2 = { .min = 5, .max = 11 }, |
| 365 | .p = { .min = 28, .max = 112 }, |
| 366 | .p1 = { .min = 2, .max = 8 }, |
| 367 | .p2 = { .dot_limit = 0, |
| 368 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 369 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 370 | }; |
| 371 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 372 | static const struct intel_limit intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 373 | .dot = { .min = 80000, .max = 224000 }, |
| 374 | .vco = { .min = 1750000, .max = 3500000 }, |
| 375 | .n = { .min = 1, .max = 3 }, |
| 376 | .m = { .min = 104, .max = 138 }, |
| 377 | .m1 = { .min = 17, .max = 23 }, |
| 378 | .m2 = { .min = 5, .max = 11 }, |
| 379 | .p = { .min = 14, .max = 42 }, |
| 380 | .p1 = { .min = 2, .max = 6 }, |
| 381 | .p2 = { .dot_limit = 0, |
| 382 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 383 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 384 | }; |
| 385 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 386 | static const struct intel_limit intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 387 | .dot = { .min = 20000, .max = 400000}, |
| 388 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 389 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 390 | .n = { .min = 3, .max = 6 }, |
| 391 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 392 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 393 | .m1 = { .min = 0, .max = 0 }, |
| 394 | .m2 = { .min = 0, .max = 254 }, |
| 395 | .p = { .min = 5, .max = 80 }, |
| 396 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 397 | .p2 = { .dot_limit = 200000, |
| 398 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 399 | }; |
| 400 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 401 | static const struct intel_limit intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 402 | .dot = { .min = 20000, .max = 400000 }, |
| 403 | .vco = { .min = 1700000, .max = 3500000 }, |
| 404 | .n = { .min = 3, .max = 6 }, |
| 405 | .m = { .min = 2, .max = 256 }, |
| 406 | .m1 = { .min = 0, .max = 0 }, |
| 407 | .m2 = { .min = 0, .max = 254 }, |
| 408 | .p = { .min = 7, .max = 112 }, |
| 409 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 410 | .p2 = { .dot_limit = 112000, |
| 411 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 412 | }; |
| 413 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 414 | /* Ironlake / Sandybridge |
| 415 | * |
| 416 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 417 | * the range value for them is (actual_value - 2). |
| 418 | */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 419 | static const struct intel_limit intel_limits_ironlake_dac = { |
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 = 5 }, |
| 423 | .m = { .min = 79, .max = 127 }, |
| 424 | .m1 = { .min = 12, .max = 22 }, |
| 425 | .m2 = { .min = 5, .max = 9 }, |
| 426 | .p = { .min = 5, .max = 80 }, |
| 427 | .p1 = { .min = 1, .max = 8 }, |
| 428 | .p2 = { .dot_limit = 225000, |
| 429 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 430 | }; |
| 431 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 432 | static const struct intel_limit intel_limits_ironlake_single_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 = 118 }, |
| 437 | .m1 = { .min = 12, .max = 22 }, |
| 438 | .m2 = { .min = 5, .max = 9 }, |
| 439 | .p = { .min = 28, .max = 112 }, |
| 440 | .p1 = { .min = 2, .max = 8 }, |
| 441 | .p2 = { .dot_limit = 225000, |
| 442 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 443 | }; |
| 444 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 445 | static const struct intel_limit intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 446 | .dot = { .min = 25000, .max = 350000 }, |
| 447 | .vco = { .min = 1760000, .max = 3510000 }, |
| 448 | .n = { .min = 1, .max = 3 }, |
| 449 | .m = { .min = 79, .max = 127 }, |
| 450 | .m1 = { .min = 12, .max = 22 }, |
| 451 | .m2 = { .min = 5, .max = 9 }, |
| 452 | .p = { .min = 14, .max = 56 }, |
| 453 | .p1 = { .min = 2, .max = 8 }, |
| 454 | .p2 = { .dot_limit = 225000, |
| 455 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 456 | }; |
| 457 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 458 | /* LVDS 100mhz refclk limits. */ |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 459 | static const struct intel_limit intel_limits_ironlake_single_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 = 2 }, |
| 463 | .m = { .min = 79, .max = 126 }, |
| 464 | .m1 = { .min = 12, .max = 22 }, |
| 465 | .m2 = { .min = 5, .max = 9 }, |
| 466 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 467 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 468 | .p2 = { .dot_limit = 225000, |
| 469 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 470 | }; |
| 471 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 472 | static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 473 | .dot = { .min = 25000, .max = 350000 }, |
| 474 | .vco = { .min = 1760000, .max = 3510000 }, |
| 475 | .n = { .min = 1, .max = 3 }, |
| 476 | .m = { .min = 79, .max = 126 }, |
| 477 | .m1 = { .min = 12, .max = 22 }, |
| 478 | .m2 = { .min = 5, .max = 9 }, |
| 479 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 480 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 481 | .p2 = { .dot_limit = 225000, |
| 482 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 483 | }; |
| 484 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 485 | static const struct intel_limit intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 486 | /* |
| 487 | * These are the data rate limits (measured in fast clocks) |
| 488 | * since those are the strictest limits we have. The fast |
| 489 | * clock and actual rate limits are more relaxed, so checking |
| 490 | * them would make no difference. |
| 491 | */ |
| 492 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 493 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 494 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 495 | .m1 = { .min = 2, .max = 3 }, |
| 496 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 497 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 498 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 499 | }; |
| 500 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 501 | static const struct intel_limit intel_limits_chv = { |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 502 | /* |
| 503 | * These are the data rate limits (measured in fast clocks) |
| 504 | * since those are the strictest limits we have. The fast |
| 505 | * clock and actual rate limits are more relaxed, so checking |
| 506 | * them would make no difference. |
| 507 | */ |
| 508 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 509 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 510 | .n = { .min = 1, .max = 1 }, |
| 511 | .m1 = { .min = 2, .max = 2 }, |
| 512 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 513 | .p1 = { .min = 2, .max = 4 }, |
| 514 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 515 | }; |
| 516 | |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 517 | static const struct intel_limit intel_limits_bxt = { |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 518 | /* FIXME: find real dot limits */ |
| 519 | .dot = { .min = 0, .max = INT_MAX }, |
Vandana Kannan | e629255 | 2015-07-01 17:02:57 +0530 | [diff] [blame] | 520 | .vco = { .min = 4800000, .max = 6700000 }, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 521 | .n = { .min = 1, .max = 1 }, |
| 522 | .m1 = { .min = 2, .max = 2 }, |
| 523 | /* FIXME: find real m2 limits */ |
| 524 | .m2 = { .min = 2 << 22, .max = 255 << 22 }, |
| 525 | .p1 = { .min = 2, .max = 4 }, |
| 526 | .p2 = { .p2_slow = 1, .p2_fast = 20 }, |
| 527 | }; |
| 528 | |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 529 | static bool |
| 530 | needs_modeset(struct drm_crtc_state *state) |
| 531 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 532 | return drm_atomic_crtc_needs_modeset(state); |
Ander Conselvan de Oliveira | cdba954 | 2015-06-01 12:49:51 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 535 | /* |
| 536 | * Platform specific helpers to calculate the port PLL loopback- (clock.m), |
| 537 | * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast |
| 538 | * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic. |
| 539 | * The helpers' return value is the rate of the clock that is fed to the |
| 540 | * display engine's pipe which can be the above fast dot clock rate or a |
| 541 | * divided-down version of it. |
| 542 | */ |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 543 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 544 | static int pnv_calc_dpll_params(int refclk, struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 545 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 546 | clock->m = clock->m2 + 2; |
| 547 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 548 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 549 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 550 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 551 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 552 | |
| 553 | return clock->dot; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 554 | } |
| 555 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 556 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 557 | { |
| 558 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 559 | } |
| 560 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 561 | static int i9xx_calc_dpll_params(int refclk, struct dpll *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 562 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 563 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 564 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 565 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 566 | return 0; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 567 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 568 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 569 | |
| 570 | return clock->dot; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 571 | } |
| 572 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 573 | static int vlv_calc_dpll_params(int refclk, struct dpll *clock) |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 574 | { |
| 575 | clock->m = clock->m1 * clock->m2; |
| 576 | clock->p = clock->p1 * clock->p2; |
| 577 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 578 | return 0; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 579 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 580 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 581 | |
| 582 | return clock->dot / 5; |
Imre Deak | 589eca6 | 2015-06-22 23:35:50 +0300 | [diff] [blame] | 583 | } |
| 584 | |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 585 | int chv_calc_dpll_params(int refclk, struct dpll *clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 586 | { |
| 587 | clock->m = clock->m1 * clock->m2; |
| 588 | clock->p = clock->p1 * clock->p2; |
| 589 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 590 | return 0; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 591 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 592 | clock->n << 22); |
| 593 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 594 | |
| 595 | return clock->dot / 5; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 596 | } |
| 597 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 598 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | /** |
| 600 | * Returns whether the given set of divisors are valid for a given refclk with |
| 601 | * the given connectors. |
| 602 | */ |
| 603 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 604 | static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 605 | const struct intel_limit *limit, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 606 | const struct dpll *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 607 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 608 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 609 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 611 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 613 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 614 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 615 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 616 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 617 | if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 618 | !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv)) |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 619 | if (clock->m1 <= clock->m2) |
| 620 | INTELPllInvalid("m1 <= m2\n"); |
| 621 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 622 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 623 | !IS_GEN9_LP(dev_priv)) { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 624 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 625 | INTELPllInvalid("p out of range\n"); |
| 626 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 627 | INTELPllInvalid("m out of range\n"); |
| 628 | } |
| 629 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 630 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 631 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 632 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 633 | * connector, etc., rather than just a single range. |
| 634 | */ |
| 635 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 636 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | |
| 638 | return true; |
| 639 | } |
| 640 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 641 | static int |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 642 | i9xx_select_p2_div(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 643 | const struct intel_crtc_state *crtc_state, |
| 644 | int target) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 645 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 646 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 647 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 648 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 649 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 650 | * For LVDS just rely on its current settings for dual-channel. |
| 651 | * We haven't figured out how to reliably set up different |
| 652 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 653 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 654 | if (intel_is_dual_link_lvds(dev)) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 655 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 656 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 657 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 658 | } else { |
| 659 | if (target < limit->p2.dot_limit) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 660 | return limit->p2.p2_slow; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 661 | else |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 662 | return limit->p2.p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 663 | } |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 664 | } |
| 665 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 666 | /* |
| 667 | * Returns a set of divisors for the desired target clock with the given |
| 668 | * refclk, or FALSE. The returned values represent the clock equation: |
| 669 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 670 | * |
| 671 | * Target and reference clocks are specified in kHz. |
| 672 | * |
| 673 | * If match_clock is provided, then best_clock P divider must match the P |
| 674 | * divider from @match_clock used for LVDS downclocking. |
| 675 | */ |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 676 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 677 | i9xx_find_best_dpll(const struct intel_limit *limit, |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 678 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 679 | int target, int refclk, struct dpll *match_clock, |
| 680 | struct dpll *best_clock) |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 681 | { |
| 682 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 683 | struct dpll clock; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 684 | int err = target; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 685 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 686 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 687 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 688 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 689 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 690 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 691 | clock.m1++) { |
| 692 | for (clock.m2 = limit->m2.min; |
| 693 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 694 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 695 | break; |
| 696 | for (clock.n = limit->n.min; |
| 697 | clock.n <= limit->n.max; clock.n++) { |
| 698 | for (clock.p1 = limit->p1.min; |
| 699 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 700 | int this_err; |
| 701 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 702 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 703 | if (!intel_PLL_is_valid(to_i915(dev), |
| 704 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 705 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 706 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 707 | if (match_clock && |
| 708 | clock.p != match_clock->p) |
| 709 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 710 | |
| 711 | this_err = abs(clock.dot - target); |
| 712 | if (this_err < err) { |
| 713 | *best_clock = clock; |
| 714 | err = this_err; |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | return (err != target); |
| 722 | } |
| 723 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 724 | /* |
| 725 | * Returns a set of divisors for the desired target clock with the given |
| 726 | * refclk, or FALSE. The returned values represent the clock equation: |
| 727 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 728 | * |
| 729 | * Target and reference clocks are specified in kHz. |
| 730 | * |
| 731 | * If match_clock is provided, then best_clock P divider must match the P |
| 732 | * divider from @match_clock used for LVDS downclocking. |
| 733 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 734 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 735 | pnv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 736 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 737 | int target, int refclk, struct dpll *match_clock, |
| 738 | struct dpll *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 739 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 740 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 741 | struct dpll clock; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 742 | int err = target; |
| 743 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 744 | memset(best_clock, 0, sizeof(*best_clock)); |
| 745 | |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 746 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 747 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 748 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 749 | clock.m1++) { |
| 750 | for (clock.m2 = limit->m2.min; |
| 751 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 752 | for (clock.n = limit->n.min; |
| 753 | clock.n <= limit->n.max; clock.n++) { |
| 754 | for (clock.p1 = limit->p1.min; |
| 755 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 756 | int this_err; |
| 757 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 758 | pnv_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 759 | if (!intel_PLL_is_valid(to_i915(dev), |
| 760 | limit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 761 | &clock)) |
| 762 | continue; |
| 763 | if (match_clock && |
| 764 | clock.p != match_clock->p) |
| 765 | continue; |
| 766 | |
| 767 | this_err = abs(clock.dot - target); |
| 768 | if (this_err < err) { |
| 769 | *best_clock = clock; |
| 770 | err = this_err; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | return (err != target); |
| 778 | } |
| 779 | |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 780 | /* |
| 781 | * Returns a set of divisors for the desired target clock with the given |
| 782 | * refclk, or FALSE. The returned values represent the clock equation: |
| 783 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 784 | * |
| 785 | * Target and reference clocks are specified in kHz. |
| 786 | * |
| 787 | * If match_clock is provided, then best_clock P divider must match the P |
| 788 | * divider from @match_clock used for LVDS downclocking. |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 789 | */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 790 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 791 | g4x_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 792 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 793 | int target, int refclk, struct dpll *match_clock, |
| 794 | struct dpll *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 795 | { |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 796 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 797 | struct dpll clock; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 798 | int max_n; |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 799 | bool found = false; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 800 | /* approximately equals target * 0.00585 */ |
| 801 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 802 | |
| 803 | memset(best_clock, 0, sizeof(*best_clock)); |
Ville Syrjälä | 3b1429d | 2015-06-18 13:47:22 +0300 | [diff] [blame] | 804 | |
| 805 | clock.p2 = i9xx_select_p2_div(limit, crtc_state, target); |
| 806 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 807 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 808 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 809 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 810 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 811 | for (clock.m1 = limit->m1.max; |
| 812 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 813 | for (clock.m2 = limit->m2.max; |
| 814 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 815 | for (clock.p1 = limit->p1.max; |
| 816 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 817 | int this_err; |
| 818 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 819 | i9xx_calc_dpll_params(refclk, &clock); |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 820 | if (!intel_PLL_is_valid(to_i915(dev), |
| 821 | limit, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 822 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 823 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 824 | |
| 825 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 826 | if (this_err < err_most) { |
| 827 | *best_clock = clock; |
| 828 | err_most = this_err; |
| 829 | max_n = clock.n; |
| 830 | found = true; |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 836 | return found; |
| 837 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 838 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 839 | /* |
| 840 | * Check if the calculated PLL configuration is more optimal compared to the |
| 841 | * best configuration and error found so far. Return the calculated error. |
| 842 | */ |
| 843 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 844 | const struct dpll *calculated_clock, |
| 845 | const struct dpll *best_clock, |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 846 | unsigned int best_error_ppm, |
| 847 | unsigned int *error_ppm) |
| 848 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 849 | /* |
| 850 | * For CHV ignore the error and consider only the P value. |
| 851 | * Prefer a bigger P value based on HW requirements. |
| 852 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 853 | if (IS_CHERRYVIEW(to_i915(dev))) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 854 | *error_ppm = 0; |
| 855 | |
| 856 | return calculated_clock->p > best_clock->p; |
| 857 | } |
| 858 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 859 | if (WARN_ON_ONCE(!target_freq)) |
| 860 | return false; |
| 861 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 862 | *error_ppm = div_u64(1000000ULL * |
| 863 | abs(target_freq - calculated_clock->dot), |
| 864 | target_freq); |
| 865 | /* |
| 866 | * Prefer a better P value over a better (smaller) error if the error |
| 867 | * is small. Ensure this preference for future configurations too by |
| 868 | * setting the error to 0. |
| 869 | */ |
| 870 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 871 | *error_ppm = 0; |
| 872 | |
| 873 | return true; |
| 874 | } |
| 875 | |
| 876 | return *error_ppm + 10 < best_error_ppm; |
| 877 | } |
| 878 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 879 | /* |
| 880 | * Returns a set of divisors for the desired target clock with the given |
| 881 | * refclk, or FALSE. The returned values represent the clock equation: |
| 882 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 883 | */ |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 884 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 885 | vlv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 886 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 887 | int target, int refclk, struct dpll *match_clock, |
| 888 | struct dpll *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 889 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 890 | 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] | 891 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 892 | struct dpll clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 893 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 894 | /* min update 19.2 MHz */ |
| 895 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 896 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 897 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 898 | target *= 5; /* fast clock */ |
| 899 | |
| 900 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 901 | |
| 902 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 903 | 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] | 904 | 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] | 905 | 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] | 906 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 907 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 908 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 909 | 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] | 910 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 911 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 912 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 913 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 914 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 915 | vlv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 916 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 917 | if (!intel_PLL_is_valid(to_i915(dev), |
| 918 | limit, |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 919 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 920 | continue; |
| 921 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 922 | if (!vlv_PLL_is_optimal(dev, target, |
| 923 | &clock, |
| 924 | best_clock, |
| 925 | bestppm, &ppm)) |
| 926 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 927 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 928 | *best_clock = clock; |
| 929 | bestppm = ppm; |
| 930 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 931 | } |
| 932 | } |
| 933 | } |
| 934 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 935 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 936 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 937 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 938 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 939 | /* |
| 940 | * Returns a set of divisors for the desired target clock with the given |
| 941 | * refclk, or FALSE. The returned values represent the clock equation: |
| 942 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 943 | */ |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 944 | static bool |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 945 | chv_find_best_dpll(const struct intel_limit *limit, |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 946 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 947 | int target, int refclk, struct dpll *match_clock, |
| 948 | struct dpll *best_clock) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 949 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 950 | 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] | 951 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 952 | unsigned int best_error_ppm; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 953 | struct dpll clock; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 954 | uint64_t m2; |
| 955 | int found = false; |
| 956 | |
| 957 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 958 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 959 | |
| 960 | /* |
| 961 | * Based on hardware doc, the n always set to 1, and m1 always |
| 962 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 963 | * revisit this because n may not 1 anymore. |
| 964 | */ |
| 965 | clock.n = 1, clock.m1 = 2; |
| 966 | target *= 5; /* fast clock */ |
| 967 | |
| 968 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 969 | for (clock.p2 = limit->p2.p2_fast; |
| 970 | clock.p2 >= limit->p2.p2_slow; |
| 971 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 972 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 973 | |
| 974 | clock.p = clock.p1 * clock.p2; |
| 975 | |
| 976 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 977 | clock.n) << 22, refclk * clock.m1); |
| 978 | |
| 979 | if (m2 > INT_MAX/clock.m1) |
| 980 | continue; |
| 981 | |
| 982 | clock.m2 = m2; |
| 983 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 984 | chv_calc_dpll_params(refclk, &clock); |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 985 | |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 986 | if (!intel_PLL_is_valid(to_i915(dev), limit, &clock)) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 987 | continue; |
| 988 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 989 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 990 | best_error_ppm, &error_ppm)) |
| 991 | continue; |
| 992 | |
| 993 | *best_clock = clock; |
| 994 | best_error_ppm = error_ppm; |
| 995 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
| 999 | return found; |
| 1000 | } |
| 1001 | |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1002 | bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 1003 | struct dpll *best_clock) |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1004 | { |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1005 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 1006 | const struct intel_limit *limit = &intel_limits_bxt; |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1007 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 1008 | return chv_find_best_dpll(limit, crtc_state, |
Imre Deak | 5ab7b0b | 2015-03-06 03:29:25 +0200 | [diff] [blame] | 1009 | target_clock, refclk, NULL, best_clock); |
| 1010 | } |
| 1011 | |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 1012 | bool intel_crtc_active(struct intel_crtc *crtc) |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1013 | { |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1014 | /* Be paranoid as we can arrive here with only partial |
| 1015 | * state retrieved from the hardware during setup. |
| 1016 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 1017 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1018 | * as Haswell has gained clock readout/fastboot support. |
| 1019 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 1020 | * 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] | 1021 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 1022 | * |
| 1023 | * FIXME: The intel_crtc->active here should be switched to |
| 1024 | * crtc->state->active once we have proper CRTC states wired up |
| 1025 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1026 | */ |
Ville Syrjälä | 525b931 | 2016-10-31 22:37:02 +0200 | [diff] [blame] | 1027 | return crtc->active && crtc->base.primary->state->fb && |
| 1028 | crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 1029 | } |
| 1030 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1031 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 1032 | enum pipe pipe) |
| 1033 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 1034 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1035 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 1036 | return crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 1037 | } |
| 1038 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1039 | static bool pipe_dsl_stopped(struct drm_i915_private *dev_priv, enum pipe pipe) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1040 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1041 | i915_reg_t reg = PIPEDSL(pipe); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1042 | u32 line1, line2; |
| 1043 | u32 line_mask; |
| 1044 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 1045 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1046 | line_mask = DSL_LINEMASK_GEN2; |
| 1047 | else |
| 1048 | line_mask = DSL_LINEMASK_GEN3; |
| 1049 | |
| 1050 | line1 = I915_READ(reg) & line_mask; |
Daniel Vetter | 6adfb1e | 2015-07-07 09:10:40 +0200 | [diff] [blame] | 1051 | msleep(5); |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1052 | line2 = I915_READ(reg) & line_mask; |
| 1053 | |
| 1054 | return line1 == line2; |
| 1055 | } |
| 1056 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1057 | /* |
| 1058 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1059 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1060 | * |
| 1061 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1062 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1063 | * see an interrupt when the pipe is disabled. |
| 1064 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1065 | * On Gen4 and above: |
| 1066 | * wait for the pipe register state bit to turn off |
| 1067 | * |
| 1068 | * Otherwise: |
| 1069 | * wait for the display line value to settle (it usually |
| 1070 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1071 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1072 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1073 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1074 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1075 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1076 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1077 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1078 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1079 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1080 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1081 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1082 | /* Wait for the Pipe State to go off */ |
Chris Wilson | b8511f5 | 2016-06-30 15:32:53 +0100 | [diff] [blame] | 1083 | if (intel_wait_for_register(dev_priv, |
| 1084 | reg, I965_PIPECONF_ACTIVE, 0, |
| 1085 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1086 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1087 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1088 | /* Wait for the display line to settle */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1089 | if (wait_for(pipe_dsl_stopped(dev_priv, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1090 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1091 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1094 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1095 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1096 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1097 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1098 | u32 val; |
| 1099 | bool cur_state; |
| 1100 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1101 | val = I915_READ(DPLL(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1102 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1103 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1104 | "PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1105 | onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1106 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1107 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1108 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 1109 | void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1110 | { |
| 1111 | u32 val; |
| 1112 | bool cur_state; |
| 1113 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1114 | mutex_lock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1115 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1116 | mutex_unlock(&dev_priv->sb_lock); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1117 | |
| 1118 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1119 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1120 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1121 | onoff(state), onoff(cur_state)); |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1122 | } |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1123 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1124 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1125 | enum pipe pipe, bool state) |
| 1126 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1127 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1128 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1129 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1130 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1131 | if (HAS_DDI(dev_priv)) { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1132 | /* DDI does not have a specific FDI_TX register */ |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1133 | u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder)); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1134 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1135 | } else { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1136 | u32 val = I915_READ(FDI_TX_CTL(pipe)); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1137 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1138 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1139 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1140 | "FDI TX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1141 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1142 | } |
| 1143 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1144 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1145 | |
| 1146 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1147 | enum pipe pipe, bool state) |
| 1148 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1149 | u32 val; |
| 1150 | bool cur_state; |
| 1151 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1152 | val = I915_READ(FDI_RX_CTL(pipe)); |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1153 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1154 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1155 | "FDI RX state assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1156 | onoff(state), onoff(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1157 | } |
| 1158 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1159 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1160 | |
| 1161 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1162 | enum pipe pipe) |
| 1163 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1164 | u32 val; |
| 1165 | |
| 1166 | /* ILK FDI PLL is always enabled */ |
Tvrtko Ursulin | 7e22dbb | 2016-05-10 10:57:06 +0100 | [diff] [blame] | 1167 | if (IS_GEN5(dev_priv)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1168 | return; |
| 1169 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1170 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1171 | if (HAS_DDI(dev_priv)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1172 | return; |
| 1173 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1174 | val = I915_READ(FDI_TX_CTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1175 | 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] | 1176 | } |
| 1177 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1178 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1179 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1180 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1181 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1182 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1183 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1184 | val = I915_READ(FDI_RX_CTL(pipe)); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1185 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1186 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1187 | "FDI RX PLL 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 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1191 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1192 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1193 | i915_reg_t pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1194 | u32 val; |
| 1195 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1196 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1197 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1198 | if (WARN_ON(HAS_DDI(dev_priv))) |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1199 | return; |
| 1200 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1201 | if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1202 | u32 port_sel; |
| 1203 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1204 | pp_reg = PP_CONTROL(0); |
| 1205 | port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1206 | |
| 1207 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1208 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1209 | panel_pipe = PIPE_B; |
| 1210 | /* XXX: else fix for eDP */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 1211 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1212 | /* presumably write lock depends on pipe, not port select */ |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1213 | pp_reg = PP_CONTROL(pipe); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1214 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1215 | } else { |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 1216 | pp_reg = PP_CONTROL(0); |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1217 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1218 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | val = I915_READ(pp_reg); |
| 1222 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1223 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1224 | locked = false; |
| 1225 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1226 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1227 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1228 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1231 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1232 | enum pipe pipe, bool state) |
| 1233 | { |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1234 | bool cur_state; |
| 1235 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 1236 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 1237 | cur_state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1238 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1239 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1240 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1241 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1242 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1243 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1244 | } |
| 1245 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1246 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1247 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1248 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1249 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1250 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1251 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1252 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1253 | pipe); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1254 | enum intel_display_power_domain power_domain; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1255 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1256 | /* if we need the pipe quirk it must be always on */ |
| 1257 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1258 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1259 | state = true; |
| 1260 | |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1261 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 1262 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1263 | u32 val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1264 | cur_state = !!(val & PIPECONF_ENABLE); |
Imre Deak | 4feed0e | 2016-02-12 18:55:14 +0200 | [diff] [blame] | 1265 | |
| 1266 | intel_display_power_put(dev_priv, power_domain); |
| 1267 | } else { |
| 1268 | cur_state = false; |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1269 | } |
| 1270 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1271 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1272 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1273 | pipe_name(pipe), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1276 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1277 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1278 | { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1279 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1280 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1281 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1282 | val = I915_READ(DSPCNTR(plane)); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1283 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1284 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1285 | "plane %c assertion failure (expected %s, current %s)\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 1286 | plane_name(plane), onoff(state), onoff(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1287 | } |
| 1288 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1289 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1290 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1291 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1292 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1293 | enum pipe pipe) |
| 1294 | { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1295 | int i; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1296 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1297 | /* Primary planes are fixed to pipes on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1298 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1299 | u32 val = I915_READ(DSPCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1300 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1301 | "plane %c assertion failure, should be disabled but not\n", |
| 1302 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1303 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1304 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1305 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1306 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1307 | for_each_pipe(dev_priv, i) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1308 | u32 val = I915_READ(DSPCNTR(i)); |
| 1309 | enum pipe cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1310 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1311 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1312 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1313 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1314 | } |
| 1315 | } |
| 1316 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1317 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1318 | enum pipe pipe) |
| 1319 | { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1320 | int sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1321 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1322 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1323 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1324 | u32 val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1325 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1326 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1327 | sprite, pipe_name(pipe)); |
| 1328 | } |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 1329 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1330 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | 83c04a6 | 2016-11-22 18:02:00 +0200 | [diff] [blame] | 1331 | u32 val = I915_READ(SPCNTR(pipe, PLANE_SPRITE0 + sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1332 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1333 | "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] | 1334 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1335 | } |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1336 | } else if (INTEL_GEN(dev_priv) >= 7) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1337 | u32 val = I915_READ(SPRCTL(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1338 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1339 | "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] | 1340 | plane_name(pipe), pipe_name(pipe)); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1341 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1342 | u32 val = I915_READ(DVSCNTR(pipe)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1343 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1344 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1345 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1346 | } |
| 1347 | } |
| 1348 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1349 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1350 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1351 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1352 | drm_crtc_vblank_put(crtc); |
| 1353 | } |
| 1354 | |
Ander Conselvan de Oliveira | 7abd4b3 | 2016-03-08 17:46:15 +0200 | [diff] [blame] | 1355 | void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1356 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1357 | { |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1358 | u32 val; |
| 1359 | bool enabled; |
| 1360 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1361 | val = I915_READ(PCH_TRANSCONF(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1362 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1363 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1364 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1365 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1368 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1369 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1370 | { |
| 1371 | if ((val & DP_PORT_EN) == 0) |
| 1372 | return false; |
| 1373 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1374 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1375 | u32 trans_dp_ctl = I915_READ(TRANS_DP_CTL(pipe)); |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1376 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1377 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1378 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1379 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1380 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1381 | } else { |
| 1382 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1383 | return false; |
| 1384 | } |
| 1385 | return true; |
| 1386 | } |
| 1387 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1388 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1389 | enum pipe pipe, u32 val) |
| 1390 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1391 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1392 | return false; |
| 1393 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1394 | if (HAS_PCH_CPT(dev_priv)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1395 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1396 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1397 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1398 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1399 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1400 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1401 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1402 | return false; |
| 1403 | } |
| 1404 | return true; |
| 1405 | } |
| 1406 | |
| 1407 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1408 | enum pipe pipe, u32 val) |
| 1409 | { |
| 1410 | if ((val & LVDS_PORT_EN) == 0) |
| 1411 | return false; |
| 1412 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1413 | if (HAS_PCH_CPT(dev_priv)) { |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1414 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1415 | return false; |
| 1416 | } else { |
| 1417 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1418 | return false; |
| 1419 | } |
| 1420 | return true; |
| 1421 | } |
| 1422 | |
| 1423 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1424 | enum pipe pipe, u32 val) |
| 1425 | { |
| 1426 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1427 | return false; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1428 | if (HAS_PCH_CPT(dev_priv)) { |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1429 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1430 | return false; |
| 1431 | } else { |
| 1432 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1433 | return false; |
| 1434 | } |
| 1435 | return true; |
| 1436 | } |
| 1437 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1438 | 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] | 1439 | enum pipe pipe, i915_reg_t reg, |
| 1440 | u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1441 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1442 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1443 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1444 | "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] | 1445 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1446 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1447 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1448 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1449 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | 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] | 1453 | enum pipe pipe, i915_reg_t reg) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1454 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1455 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1456 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1457 | "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] | 1458 | i915_mmio_reg_offset(reg), pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1459 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1460 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1461 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1462 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1466 | enum pipe pipe) |
| 1467 | { |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1468 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1469 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1470 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1471 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1472 | 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] | 1473 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1474 | val = I915_READ(PCH_ADPA); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1475 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1476 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1477 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1478 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 1479 | val = I915_READ(PCH_LVDS); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1480 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1481 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1482 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1483 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1484 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1485 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1486 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1487 | } |
| 1488 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1489 | static void _vlv_enable_pll(struct intel_crtc *crtc, |
| 1490 | const struct intel_crtc_state *pipe_config) |
| 1491 | { |
| 1492 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1493 | enum pipe pipe = crtc->pipe; |
| 1494 | |
| 1495 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
| 1496 | POSTING_READ(DPLL(pipe)); |
| 1497 | udelay(150); |
| 1498 | |
Chris Wilson | 2c30b43 | 2016-06-30 15:32:54 +0100 | [diff] [blame] | 1499 | if (intel_wait_for_register(dev_priv, |
| 1500 | DPLL(pipe), |
| 1501 | DPLL_LOCK_VLV, |
| 1502 | DPLL_LOCK_VLV, |
| 1503 | 1)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1504 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 1505 | } |
| 1506 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1507 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1508 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1509 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1510 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1511 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1512 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1513 | assert_pipe_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1514 | |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1515 | /* PLL is protected by panel, make sure we can write it */ |
Ville Syrjälä | 7d1a83c | 2016-03-15 16:39:58 +0200 | [diff] [blame] | 1516 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1517 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1518 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1519 | _vlv_enable_pll(crtc, pipe_config); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1520 | |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1521 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1522 | POSTING_READ(DPLL_MD(pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1525 | |
| 1526 | static void _chv_enable_pll(struct intel_crtc *crtc, |
| 1527 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1528 | { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1529 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 8bd3f30 | 2016-03-15 16:39:57 +0200 | [diff] [blame] | 1530 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1531 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1532 | u32 tmp; |
| 1533 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1534 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1535 | |
| 1536 | /* Enable back the 10bit clock to display controller */ |
| 1537 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1538 | tmp |= DPIO_DCLKP_EN; |
| 1539 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1540 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 1541 | mutex_unlock(&dev_priv->sb_lock); |
| 1542 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1543 | /* |
| 1544 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1545 | */ |
| 1546 | udelay(1); |
| 1547 | |
| 1548 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1549 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1550 | |
| 1551 | /* Check PLL is locked */ |
Chris Wilson | 6b18826 | 2016-06-30 15:32:55 +0100 | [diff] [blame] | 1552 | if (intel_wait_for_register(dev_priv, |
| 1553 | DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV, |
| 1554 | 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1555 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | static void chv_enable_pll(struct intel_crtc *crtc, |
| 1559 | const struct intel_crtc_state *pipe_config) |
| 1560 | { |
| 1561 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1562 | enum pipe pipe = crtc->pipe; |
| 1563 | |
| 1564 | assert_pipe_disabled(dev_priv, pipe); |
| 1565 | |
| 1566 | /* PLL is protected by panel, make sure we can write it */ |
| 1567 | assert_panel_unlocked(dev_priv, pipe); |
| 1568 | |
| 1569 | if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) |
| 1570 | _chv_enable_pll(crtc, pipe_config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1571 | |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 1572 | if (pipe != PIPE_A) { |
| 1573 | /* |
| 1574 | * WaPixelRepeatModeFixForC0:chv |
| 1575 | * |
| 1576 | * DPLLCMD is AWOL. Use chicken bits to propagate |
| 1577 | * the value from DPLLBMD to either pipe B or C. |
| 1578 | */ |
| 1579 | I915_WRITE(CBR4_VLV, pipe == PIPE_B ? CBR_DPLLBMD_PIPE_B : CBR_DPLLBMD_PIPE_C); |
| 1580 | I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md); |
| 1581 | I915_WRITE(CBR4_VLV, 0); |
| 1582 | dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md; |
| 1583 | |
| 1584 | /* |
| 1585 | * DPLLB VGA mode also seems to cause problems. |
| 1586 | * We should always have it disabled. |
| 1587 | */ |
| 1588 | WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0); |
| 1589 | } else { |
| 1590 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
| 1591 | POSTING_READ(DPLL_MD(pipe)); |
| 1592 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1593 | } |
| 1594 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1595 | static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1596 | { |
| 1597 | struct intel_crtc *crtc; |
| 1598 | int count = 0; |
| 1599 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1600 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Maarten Lankhorst | 3538b9d | 2015-06-01 12:50:10 +0200 | [diff] [blame] | 1601 | count += crtc->base.state->active && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1602 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO); |
| 1603 | } |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1604 | |
| 1605 | return count; |
| 1606 | } |
| 1607 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1608 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1609 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1610 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1611 | i915_reg_t reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1612 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1613 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1614 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1615 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1616 | /* PLL is protected by panel, make sure we can write it */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1617 | if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv)) |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1618 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1619 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1620 | /* Enable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1621 | if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1622 | /* |
| 1623 | * It appears to be important that we don't enable this |
| 1624 | * for the current pipe before otherwise configuring the |
| 1625 | * PLL. No idea how this should be handled if multiple |
| 1626 | * DVO outputs are enabled simultaneosly. |
| 1627 | */ |
| 1628 | dpll |= DPLL_DVO_2X_MODE; |
| 1629 | I915_WRITE(DPLL(!crtc->pipe), |
| 1630 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1631 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1632 | |
Ville Syrjälä | c2b6337 | 2015-10-07 22:08:25 +0300 | [diff] [blame] | 1633 | /* |
| 1634 | * Apparently we need to have VGA mode enabled prior to changing |
| 1635 | * the P1/P2 dividers. Otherwise the DPLL will keep using the old |
| 1636 | * dividers, even though the register value does change. |
| 1637 | */ |
| 1638 | I915_WRITE(reg, 0); |
| 1639 | |
Ville Syrjälä | 8e7a65a | 2015-10-07 22:08:24 +0300 | [diff] [blame] | 1640 | I915_WRITE(reg, dpll); |
| 1641 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1642 | /* Wait for the clocks to stabilize. */ |
| 1643 | POSTING_READ(reg); |
| 1644 | udelay(150); |
| 1645 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1646 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1647 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1648 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1649 | } else { |
| 1650 | /* The pixel multiplier can only be updated once the |
| 1651 | * DPLL is enabled and the clocks are stable. |
| 1652 | * |
| 1653 | * So write it again. |
| 1654 | */ |
| 1655 | I915_WRITE(reg, dpll); |
| 1656 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1657 | |
| 1658 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1659 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1660 | POSTING_READ(reg); |
| 1661 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1662 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1663 | POSTING_READ(reg); |
| 1664 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1665 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1666 | POSTING_READ(reg); |
| 1667 | udelay(150); /* wait for warmup */ |
| 1668 | } |
| 1669 | |
| 1670 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1671 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1672 | * @dev_priv: i915 private structure |
| 1673 | * @pipe: pipe PLL to disable |
| 1674 | * |
| 1675 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1676 | * |
| 1677 | * Note! This is for pre-ILK only. |
| 1678 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1679 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1680 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1681 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1682 | enum pipe pipe = crtc->pipe; |
| 1683 | |
| 1684 | /* Disable DVO 2x clock on both PLLs if necessary */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 1685 | if (IS_I830(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1686 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 1687 | !intel_num_dvo_pipes(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1688 | I915_WRITE(DPLL(PIPE_B), |
| 1689 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1690 | I915_WRITE(DPLL(PIPE_A), |
| 1691 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1692 | } |
| 1693 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1694 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1695 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1696 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1697 | return; |
| 1698 | |
| 1699 | /* Make sure the pipe isn't still relying on us */ |
| 1700 | assert_pipe_disabled(dev_priv, pipe); |
| 1701 | |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1702 | I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS); |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1703 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1704 | } |
| 1705 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1706 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1707 | { |
Ville Syrjälä | b8afb91 | 2015-06-29 15:25:48 +0300 | [diff] [blame] | 1708 | u32 val; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* Make sure the pipe isn't still relying on us */ |
| 1711 | assert_pipe_disabled(dev_priv, pipe); |
| 1712 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1713 | val = DPLL_INTEGRATED_REF_CLK_VLV | |
| 1714 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
| 1715 | if (pipe != PIPE_A) |
| 1716 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1717 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1718 | I915_WRITE(DPLL(pipe), val); |
| 1719 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1723 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1724 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1725 | u32 val; |
| 1726 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1727 | /* Make sure the pipe isn't still relying on us */ |
| 1728 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1729 | |
Ville Syrjälä | 60bfe44 | 2015-06-29 15:25:49 +0300 | [diff] [blame] | 1730 | val = DPLL_SSC_REF_CLK_CHV | |
| 1731 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1732 | if (pipe != PIPE_A) |
| 1733 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 1734 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1735 | I915_WRITE(DPLL(pipe), val); |
| 1736 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1737 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1738 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1739 | |
| 1740 | /* Disable 10bit clock to display controller */ |
| 1741 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1742 | val &= ~DPIO_DCLKP_EN; |
| 1743 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1744 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 1745 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1748 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1749 | struct intel_digital_port *dport, |
| 1750 | unsigned int expected_mask) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1751 | { |
| 1752 | u32 port_mask; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1753 | i915_reg_t dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1754 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1755 | switch (dport->port) { |
| 1756 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1757 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1758 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1759 | break; |
| 1760 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1761 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1762 | dpll_reg = DPLL(0); |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1763 | expected_mask <<= 4; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1764 | break; |
| 1765 | case PORT_D: |
| 1766 | port_mask = DPLL_PORTD_READY_MASK; |
| 1767 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1768 | break; |
| 1769 | default: |
| 1770 | BUG(); |
| 1771 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1772 | |
Chris Wilson | 370004d | 2016-06-30 15:32:56 +0100 | [diff] [blame] | 1773 | if (intel_wait_for_register(dev_priv, |
| 1774 | dpll_reg, port_mask, expected_mask, |
| 1775 | 1000)) |
Ville Syrjälä | 9b6de0a | 2015-04-10 18:21:31 +0300 | [diff] [blame] | 1776 | WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n", |
| 1777 | port_name(dport->port), I915_READ(dpll_reg) & port_mask, expected_mask); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1780 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1781 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1782 | { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 1783 | struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv, |
| 1784 | pipe); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1785 | i915_reg_t reg; |
| 1786 | uint32_t val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1787 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1788 | /* Make sure PCH DPLL is enabled */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 1789 | assert_shared_dpll_enabled(dev_priv, intel_crtc->config->shared_dpll); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1790 | |
| 1791 | /* FDI must be feeding us bits for PCH ports */ |
| 1792 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1793 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1794 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1795 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1796 | /* Workaround: Set the timing override bit before enabling the |
| 1797 | * pch transcoder. */ |
| 1798 | reg = TRANS_CHICKEN2(pipe); |
| 1799 | val = I915_READ(reg); |
| 1800 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1801 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1802 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1803 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1804 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1805 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1806 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1807 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1808 | if (HAS_PCH_IBX(dev_priv)) { |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1809 | /* |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1810 | * Make the BPC in transcoder be consistent with |
| 1811 | * that in pipeconf reg. For HDMI we must use 8bpc |
| 1812 | * here for both 8bpc and 12bpc. |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1813 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1814 | val &= ~PIPECONF_BPC_MASK; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1815 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | c5de7c6 | 2015-05-05 17:06:22 +0300 | [diff] [blame] | 1816 | val |= PIPECONF_8BPC; |
| 1817 | else |
| 1818 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1819 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1820 | |
| 1821 | val &= ~TRANS_INTERLACE_MASK; |
| 1822 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 1823 | if (HAS_PCH_IBX(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 1824 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1825 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1826 | else |
| 1827 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1828 | else |
| 1829 | val |= TRANS_PROGRESSIVE; |
| 1830 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1831 | I915_WRITE(reg, val | TRANS_ENABLE); |
Chris Wilson | 650fbd8 | 2016-06-30 15:32:57 +0100 | [diff] [blame] | 1832 | if (intel_wait_for_register(dev_priv, |
| 1833 | reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE, |
| 1834 | 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1835 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1836 | } |
| 1837 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1838 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1839 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1840 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1841 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1842 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1843 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1844 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1845 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1846 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1847 | /* Workaround: set timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1848 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1849 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1850 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1851 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1852 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1853 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1854 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1855 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1856 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1857 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1858 | else |
| 1859 | val |= TRANS_PROGRESSIVE; |
| 1860 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1861 | I915_WRITE(LPT_TRANSCONF, val); |
Chris Wilson | d9f9624 | 2016-06-30 15:32:58 +0100 | [diff] [blame] | 1862 | if (intel_wait_for_register(dev_priv, |
| 1863 | LPT_TRANSCONF, |
| 1864 | TRANS_STATE_ENABLE, |
| 1865 | TRANS_STATE_ENABLE, |
| 1866 | 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1867 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1870 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1871 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1872 | { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1873 | i915_reg_t reg; |
| 1874 | uint32_t val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1875 | |
| 1876 | /* FDI relies on the transcoder */ |
| 1877 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1878 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1879 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1880 | /* Ports must be off as well */ |
| 1881 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1882 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1883 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1884 | val = I915_READ(reg); |
| 1885 | val &= ~TRANS_ENABLE; |
| 1886 | I915_WRITE(reg, val); |
| 1887 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | a7d0466 | 2016-06-30 15:32:59 +0100 | [diff] [blame] | 1888 | if (intel_wait_for_register(dev_priv, |
| 1889 | reg, TRANS_STATE_ENABLE, 0, |
| 1890 | 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1891 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1892 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 1893 | if (HAS_PCH_CPT(dev_priv)) { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1894 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1895 | reg = TRANS_CHICKEN2(pipe); |
| 1896 | val = I915_READ(reg); |
| 1897 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1898 | I915_WRITE(reg, val); |
| 1899 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1900 | } |
| 1901 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 1902 | void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1903 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1904 | u32 val; |
| 1905 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1906 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1907 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1908 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1909 | /* wait for PCH transcoder off, transcoder state */ |
Chris Wilson | dfdb474 | 2016-06-30 15:33:00 +0100 | [diff] [blame] | 1910 | if (intel_wait_for_register(dev_priv, |
| 1911 | LPT_TRANSCONF, TRANS_STATE_ENABLE, 0, |
| 1912 | 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1913 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1914 | |
| 1915 | /* Workaround: clear timing override bit. */ |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1916 | val = I915_READ(TRANS_CHICKEN2(PIPE_A)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1917 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Ville Syrjälä | 36c0d0c | 2015-09-18 20:03:31 +0300 | [diff] [blame] | 1918 | I915_WRITE(TRANS_CHICKEN2(PIPE_A), val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1919 | } |
| 1920 | |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1921 | enum transcoder intel_crtc_pch_transcoder(struct intel_crtc *crtc) |
| 1922 | { |
| 1923 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 1924 | |
| 1925 | WARN_ON(!crtc->config->has_pch_encoder); |
| 1926 | |
| 1927 | if (HAS_PCH_LPT(dev_priv)) |
| 1928 | return TRANSCODER_A; |
| 1929 | else |
| 1930 | return (enum transcoder) crtc->pipe; |
| 1931 | } |
| 1932 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1933 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1934 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1935 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1936 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1937 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1938 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1939 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1940 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1941 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1942 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 1943 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1944 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | 1a70a728 | 2015-10-29 21:25:50 +0200 | [diff] [blame] | 1945 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 1946 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1947 | u32 val; |
| 1948 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 1949 | DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe)); |
| 1950 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1951 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1952 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1953 | assert_sprites_disabled(dev_priv, pipe); |
| 1954 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1955 | /* |
| 1956 | * A pipe without a PLL won't actually be able to drive bits from |
| 1957 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1958 | * need the check. |
| 1959 | */ |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1960 | if (HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 1961 | if (intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1962 | assert_dsi_pll_enabled(dev_priv); |
| 1963 | else |
| 1964 | assert_pll_enabled(dev_priv, pipe); |
Ville Syrjälä | 09fa8bb | 2016-08-05 20:41:34 +0300 | [diff] [blame] | 1965 | } else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1966 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1967 | /* if driving the PCH, we need FDI enabled */ |
Ville Syrjälä | 65f2130 | 2016-10-14 20:02:53 +0300 | [diff] [blame] | 1968 | assert_fdi_rx_pll_enabled(dev_priv, |
| 1969 | (enum pipe) intel_crtc_pch_transcoder(crtc)); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1970 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1971 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1972 | } |
| 1973 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1974 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1975 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1976 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1977 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1978 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1979 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1980 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1981 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 1982 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1983 | |
| 1984 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 1985 | POSTING_READ(reg); |
Ville Syrjälä | b7792d8 | 2015-12-14 18:23:43 +0200 | [diff] [blame] | 1986 | |
| 1987 | /* |
| 1988 | * Until the pipe starts DSL will read as 0, which would cause |
| 1989 | * an apparent vblank timestamp jump, which messes up also the |
| 1990 | * frame count when it's derived from the timestamps. So let's |
| 1991 | * wait for the pipe to start properly before we call |
| 1992 | * drm_crtc_vblank_on() |
| 1993 | */ |
| 1994 | if (dev->max_vblank_count == 0 && |
| 1995 | wait_for(intel_get_crtc_scanline(crtc) != crtc->scanline_offset, 50)) |
| 1996 | DRM_ERROR("pipe %c didn't start\n", pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
| 1999 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2000 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2001 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2002 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2003 | * Disable the pipe of @crtc, making sure that various hardware |
| 2004 | * specific requirements are met, if applicable, e.g. plane |
| 2005 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2006 | * |
| 2007 | * Will wait until the pipe has shut down before returning. |
| 2008 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2009 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2010 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2011 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2012 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2013 | enum pipe pipe = crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 2014 | i915_reg_t reg; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2015 | u32 val; |
| 2016 | |
Ville Syrjälä | 9e2ee2d | 2015-06-24 21:59:35 +0300 | [diff] [blame] | 2017 | DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe)); |
| 2018 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2019 | /* |
| 2020 | * Make sure planes won't keep trying to pump pixels to us, |
| 2021 | * or we might hang the display. |
| 2022 | */ |
| 2023 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2024 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2025 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2026 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2027 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2028 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2029 | if ((val & PIPECONF_ENABLE) == 0) |
| 2030 | return; |
| 2031 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2032 | /* |
| 2033 | * Double wide has implications for planes |
| 2034 | * so best keep it disabled when not needed. |
| 2035 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2036 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2037 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2038 | |
| 2039 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2040 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2041 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2042 | val &= ~PIPECONF_ENABLE; |
| 2043 | |
| 2044 | I915_WRITE(reg, val); |
| 2045 | if ((val & PIPECONF_ENABLE) == 0) |
| 2046 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2047 | } |
| 2048 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2049 | static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv) |
| 2050 | { |
| 2051 | return IS_GEN2(dev_priv) ? 2048 : 4096; |
| 2052 | } |
| 2053 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2054 | static unsigned int intel_tile_width_bytes(const struct drm_i915_private *dev_priv, |
| 2055 | uint64_t fb_modifier, unsigned int cpp) |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 2056 | { |
| 2057 | switch (fb_modifier) { |
| 2058 | case DRM_FORMAT_MOD_NONE: |
| 2059 | return cpp; |
| 2060 | case I915_FORMAT_MOD_X_TILED: |
| 2061 | if (IS_GEN2(dev_priv)) |
| 2062 | return 128; |
| 2063 | else |
| 2064 | return 512; |
| 2065 | case I915_FORMAT_MOD_Y_TILED: |
| 2066 | if (IS_GEN2(dev_priv) || HAS_128_BYTE_Y_TILING(dev_priv)) |
| 2067 | return 128; |
| 2068 | else |
| 2069 | return 512; |
| 2070 | case I915_FORMAT_MOD_Yf_TILED: |
| 2071 | switch (cpp) { |
| 2072 | case 1: |
| 2073 | return 64; |
| 2074 | case 2: |
| 2075 | case 4: |
| 2076 | return 128; |
| 2077 | case 8: |
| 2078 | case 16: |
| 2079 | return 256; |
| 2080 | default: |
| 2081 | MISSING_CASE(cpp); |
| 2082 | return cpp; |
| 2083 | } |
| 2084 | break; |
| 2085 | default: |
| 2086 | MISSING_CASE(fb_modifier); |
| 2087 | return cpp; |
| 2088 | } |
| 2089 | } |
| 2090 | |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2091 | unsigned int intel_tile_height(const struct drm_i915_private *dev_priv, |
| 2092 | uint64_t fb_modifier, unsigned int cpp) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2093 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2094 | if (fb_modifier == DRM_FORMAT_MOD_NONE) |
| 2095 | return 1; |
| 2096 | else |
| 2097 | return intel_tile_size(dev_priv) / |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 2098 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2101 | /* Return the tile dimensions in pixel units */ |
| 2102 | static void intel_tile_dims(const struct drm_i915_private *dev_priv, |
| 2103 | unsigned int *tile_width, |
| 2104 | unsigned int *tile_height, |
| 2105 | uint64_t fb_modifier, |
| 2106 | unsigned int cpp) |
| 2107 | { |
| 2108 | unsigned int tile_width_bytes = |
| 2109 | intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
| 2110 | |
| 2111 | *tile_width = tile_width_bytes / cpp; |
| 2112 | *tile_height = intel_tile_size(dev_priv) / tile_width_bytes; |
| 2113 | } |
| 2114 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2115 | unsigned int |
| 2116 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2117 | uint32_t pixel_format, uint64_t fb_modifier) |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2118 | { |
Ville Syrjälä | 832be82 | 2016-01-12 21:08:33 +0200 | [diff] [blame] | 2119 | unsigned int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 2120 | unsigned int tile_height = intel_tile_height(to_i915(dev), fb_modifier, cpp); |
| 2121 | |
| 2122 | return ALIGN(height, tile_height); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2123 | } |
| 2124 | |
Ville Syrjälä | 1663b9d | 2016-02-15 22:54:45 +0200 | [diff] [blame] | 2125 | unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info) |
| 2126 | { |
| 2127 | unsigned int size = 0; |
| 2128 | int i; |
| 2129 | |
| 2130 | for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) |
| 2131 | size += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2132 | |
| 2133 | return size; |
| 2134 | } |
| 2135 | |
Daniel Vetter | 75c82a5 | 2015-10-14 16:51:04 +0200 | [diff] [blame] | 2136 | static void |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2137 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, |
| 2138 | const struct drm_framebuffer *fb, |
| 2139 | unsigned int rotation) |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2140 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2141 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 2142 | *view = i915_ggtt_view_rotated; |
| 2143 | view->params.rotated = to_intel_framebuffer(fb)->rot_info; |
| 2144 | } else { |
| 2145 | *view = i915_ggtt_view_normal; |
| 2146 | } |
| 2147 | } |
| 2148 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2149 | 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] | 2150 | { |
| 2151 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2152 | return 256 * 1024; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 2153 | else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) || |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 2154 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2155 | return 128 * 1024; |
| 2156 | else if (INTEL_INFO(dev_priv)->gen >= 4) |
| 2157 | return 4 * 1024; |
| 2158 | else |
Ville Syrjälä | 44c5905 | 2015-06-11 16:31:16 +0300 | [diff] [blame] | 2159 | return 0; |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2160 | } |
| 2161 | |
Ville Syrjälä | 603525d | 2016-01-12 21:08:37 +0200 | [diff] [blame] | 2162 | static unsigned int intel_surf_alignment(const struct drm_i915_private *dev_priv, |
| 2163 | uint64_t fb_modifier) |
| 2164 | { |
| 2165 | switch (fb_modifier) { |
| 2166 | case DRM_FORMAT_MOD_NONE: |
| 2167 | return intel_linear_alignment(dev_priv); |
| 2168 | case I915_FORMAT_MOD_X_TILED: |
| 2169 | if (INTEL_INFO(dev_priv)->gen >= 9) |
| 2170 | return 256 * 1024; |
| 2171 | return 0; |
| 2172 | case I915_FORMAT_MOD_Y_TILED: |
| 2173 | case I915_FORMAT_MOD_Yf_TILED: |
| 2174 | return 1 * 1024 * 1024; |
| 2175 | default: |
| 2176 | MISSING_CASE(fb_modifier); |
| 2177 | return 0; |
| 2178 | } |
| 2179 | } |
| 2180 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2181 | struct i915_vma * |
| 2182 | intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2183 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2184 | struct drm_device *dev = fb->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2185 | struct drm_i915_private *dev_priv = to_i915(dev); |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2186 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2187 | struct i915_ggtt_view view; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2188 | struct i915_vma *vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2189 | u32 alignment; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2190 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2191 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2192 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2193 | alignment = intel_surf_alignment(dev_priv, fb->modifier); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2194 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2195 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2196 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2197 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2198 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2199 | * we should always have valid PTE following the scanout preventing |
| 2200 | * the VT-d warning. |
| 2201 | */ |
Chris Wilson | 48f112f | 2016-06-24 14:07:14 +0100 | [diff] [blame] | 2202 | if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024) |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2203 | alignment = 256 * 1024; |
| 2204 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2205 | /* |
| 2206 | * Global gtt pte registers are special registers which actually forward |
| 2207 | * writes to a chunk of system memory. Which means that there is no risk |
| 2208 | * that the register values disappear as soon as we call |
| 2209 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2210 | * pin/unpin/fence and not more. |
| 2211 | */ |
| 2212 | intel_runtime_pm_get(dev_priv); |
| 2213 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2214 | vma = i915_gem_object_pin_to_display_plane(obj, alignment, &view); |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2215 | if (IS_ERR(vma)) |
| 2216 | goto err; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2217 | |
Chris Wilson | 05a20d0 | 2016-08-18 17:16:55 +0100 | [diff] [blame] | 2218 | if (i915_vma_is_map_and_fenceable(vma)) { |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2219 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2220 | * fence, whereas 965+ only requires a fence if using |
| 2221 | * framebuffer compression. For simplicity, we always, when |
| 2222 | * possible, install a fence as the cost is not that onerous. |
| 2223 | * |
| 2224 | * If we fail to fence the tiled scanout, then either the |
| 2225 | * modeset will reject the change (which is highly unlikely as |
| 2226 | * the affected systems, all but one, do not have unmappable |
| 2227 | * space) or we will not be able to enable full powersaving |
| 2228 | * techniques (also likely not to apply due to various limits |
| 2229 | * FBC and the like impose on the size of the buffer, which |
| 2230 | * presumably we violated anyway with this unmappable buffer). |
| 2231 | * Anyway, it is presumably better to stumble onwards with |
| 2232 | * something and try to run the system in a "less than optimal" |
| 2233 | * mode that matches the user configuration. |
| 2234 | */ |
| 2235 | if (i915_vma_get_fence(vma) == 0) |
| 2236 | i915_vma_pin_fence(vma); |
Vivek Kasireddy | 9807216 | 2015-10-29 18:54:38 -0700 | [diff] [blame] | 2237 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2238 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2239 | err: |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2240 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2241 | return vma; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2242 | } |
| 2243 | |
Chris Wilson | fb4b8ce | 2016-04-28 09:56:35 +0100 | [diff] [blame] | 2244 | void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2245 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2246 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2247 | struct i915_ggtt_view view; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2248 | struct i915_vma *vma; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2249 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2250 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2251 | |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 2252 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Chris Wilson | 05a20d0 | 2016-08-18 17:16:55 +0100 | [diff] [blame] | 2253 | vma = i915_gem_object_to_ggtt(obj, &view); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2254 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame] | 2255 | i915_vma_unpin_fence(vma); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2256 | i915_gem_object_unpin_from_display_plane(vma); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2257 | } |
| 2258 | |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2259 | static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane, |
| 2260 | unsigned int rotation) |
| 2261 | { |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2262 | if (drm_rotation_90_or_270(rotation)) |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2263 | return to_intel_framebuffer(fb)->rotated[plane].pitch; |
| 2264 | else |
| 2265 | return fb->pitches[plane]; |
| 2266 | } |
| 2267 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2268 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2269 | * Convert the x/y offsets into a linear offset. |
| 2270 | * Only valid with 0/180 degree rotation, which is fine since linear |
| 2271 | * offset is only used with linear buffers on pre-hsw and tiled buffers |
| 2272 | * with gen2/3, and 90/270 degree rotations isn't supported on any of them. |
| 2273 | */ |
| 2274 | u32 intel_fb_xy_to_linear(int x, int y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2275 | const struct intel_plane_state *state, |
| 2276 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2277 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2278 | const struct drm_framebuffer *fb = state->base.fb; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2279 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
| 2280 | unsigned int pitch = fb->pitches[plane]; |
| 2281 | |
| 2282 | return y * pitch + x * cpp; |
| 2283 | } |
| 2284 | |
| 2285 | /* |
| 2286 | * Add the x/y offsets derived from fb->offsets[] to the user |
| 2287 | * specified plane src x/y offsets. The resulting x/y offsets |
| 2288 | * specify the start of scanout from the beginning of the gtt mapping. |
| 2289 | */ |
| 2290 | void intel_add_fb_offsets(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2291 | const struct intel_plane_state *state, |
| 2292 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2293 | |
| 2294 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2295 | const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb); |
| 2296 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2297 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2298 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2299 | *x += intel_fb->rotated[plane].x; |
| 2300 | *y += intel_fb->rotated[plane].y; |
| 2301 | } else { |
| 2302 | *x += intel_fb->normal[plane].x; |
| 2303 | *y += intel_fb->normal[plane].y; |
| 2304 | } |
| 2305 | } |
| 2306 | |
| 2307 | /* |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2308 | * Input tile dimensions and pitch must already be |
| 2309 | * rotated to match x and y, and in pixel units. |
| 2310 | */ |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2311 | static u32 _intel_adjust_tile_offset(int *x, int *y, |
| 2312 | unsigned int tile_width, |
| 2313 | unsigned int tile_height, |
| 2314 | unsigned int tile_size, |
| 2315 | unsigned int pitch_tiles, |
| 2316 | u32 old_offset, |
| 2317 | u32 new_offset) |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2318 | { |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2319 | unsigned int pitch_pixels = pitch_tiles * tile_width; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2320 | unsigned int tiles; |
| 2321 | |
| 2322 | WARN_ON(old_offset & (tile_size - 1)); |
| 2323 | WARN_ON(new_offset & (tile_size - 1)); |
| 2324 | WARN_ON(new_offset > old_offset); |
| 2325 | |
| 2326 | tiles = (old_offset - new_offset) / tile_size; |
| 2327 | |
| 2328 | *y += tiles / pitch_tiles * tile_height; |
| 2329 | *x += tiles % pitch_tiles * tile_width; |
| 2330 | |
Ville Syrjälä | b9b2403 | 2016-02-08 18:28:00 +0200 | [diff] [blame] | 2331 | /* minimize x in case it got needlessly big */ |
| 2332 | *y += *x / pitch_pixels * tile_height; |
| 2333 | *x %= pitch_pixels; |
| 2334 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2335 | return new_offset; |
| 2336 | } |
| 2337 | |
| 2338 | /* |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2339 | * Adjust the tile offset by moving the difference into |
| 2340 | * the x/y offsets. |
| 2341 | */ |
| 2342 | static u32 intel_adjust_tile_offset(int *x, int *y, |
| 2343 | const struct intel_plane_state *state, int plane, |
| 2344 | u32 old_offset, u32 new_offset) |
| 2345 | { |
| 2346 | const struct drm_i915_private *dev_priv = to_i915(state->base.plane->dev); |
| 2347 | const struct drm_framebuffer *fb = state->base.fb; |
| 2348 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
| 2349 | unsigned int rotation = state->base.rotation; |
| 2350 | unsigned int pitch = intel_fb_pitch(fb, plane, rotation); |
| 2351 | |
| 2352 | WARN_ON(new_offset > old_offset); |
| 2353 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2354 | if (fb->modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2355 | unsigned int tile_size, tile_width, tile_height; |
| 2356 | unsigned int pitch_tiles; |
| 2357 | |
| 2358 | tile_size = intel_tile_size(dev_priv); |
| 2359 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2360 | fb->modifier, cpp); |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2361 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2362 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2363 | pitch_tiles = pitch / tile_height; |
| 2364 | swap(tile_width, tile_height); |
| 2365 | } else { |
| 2366 | pitch_tiles = pitch / (tile_width * cpp); |
| 2367 | } |
| 2368 | |
| 2369 | _intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2370 | tile_size, pitch_tiles, |
| 2371 | old_offset, new_offset); |
| 2372 | } else { |
| 2373 | old_offset += *y * pitch + *x * cpp; |
| 2374 | |
| 2375 | *y = (old_offset - new_offset) / pitch; |
| 2376 | *x = ((old_offset - new_offset) - *y * pitch) / cpp; |
| 2377 | } |
| 2378 | |
| 2379 | return new_offset; |
| 2380 | } |
| 2381 | |
| 2382 | /* |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2383 | * Computes the linear offset to the base tile and adjusts |
| 2384 | * x, y. bytes per pixel is assumed to be a power-of-two. |
| 2385 | * |
| 2386 | * In the 90/270 rotated case, x and y are assumed |
| 2387 | * to be already rotated to match the rotated GTT view, and |
| 2388 | * pitch is the tile_height aligned framebuffer height. |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2389 | * |
| 2390 | * This function is used when computing the derived information |
| 2391 | * under intel_framebuffer, so using any of that information |
| 2392 | * here is not allowed. Anything under drm_framebuffer can be |
| 2393 | * used. This is why the user has to pass in the pitch since it |
| 2394 | * is specified in the rotated orientation. |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2395 | */ |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2396 | static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv, |
| 2397 | int *x, int *y, |
| 2398 | const struct drm_framebuffer *fb, int plane, |
| 2399 | unsigned int pitch, |
| 2400 | unsigned int rotation, |
| 2401 | u32 alignment) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2402 | { |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2403 | uint64_t fb_modifier = fb->modifier; |
Ville Syrjälä | 4f2d993 | 2016-02-15 22:54:44 +0200 | [diff] [blame] | 2404 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2405 | u32 offset, offset_aligned; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2406 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2407 | if (alignment) |
| 2408 | alignment--; |
| 2409 | |
Ville Syrjälä | b5c6533 | 2016-01-12 21:08:31 +0200 | [diff] [blame] | 2410 | if (fb_modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2411 | unsigned int tile_size, tile_width, tile_height; |
| 2412 | unsigned int tile_rows, tiles, pitch_tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2413 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2414 | tile_size = intel_tile_size(dev_priv); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2415 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
| 2416 | fb_modifier, cpp); |
| 2417 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2418 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2419 | pitch_tiles = pitch / tile_height; |
| 2420 | swap(tile_width, tile_height); |
| 2421 | } else { |
| 2422 | pitch_tiles = pitch / (tile_width * cpp); |
| 2423 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2424 | |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2425 | tile_rows = *y / tile_height; |
| 2426 | *y %= tile_height; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2427 | |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 2428 | tiles = *x / tile_width; |
| 2429 | *x %= tile_width; |
Ville Syrjälä | d843310 | 2016-01-12 21:08:35 +0200 | [diff] [blame] | 2430 | |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2431 | offset = (tile_rows * pitch_tiles + tiles) * tile_size; |
| 2432 | offset_aligned = offset & ~alignment; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2433 | |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2434 | _intel_adjust_tile_offset(x, y, tile_width, tile_height, |
| 2435 | tile_size, pitch_tiles, |
| 2436 | offset, offset_aligned); |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2437 | } else { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2438 | offset = *y * pitch + *x * cpp; |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2439 | offset_aligned = offset & ~alignment; |
| 2440 | |
Ville Syrjälä | 4e9a86b | 2015-06-11 16:31:14 +0300 | [diff] [blame] | 2441 | *y = (offset & alignment) / pitch; |
| 2442 | *x = ((offset & alignment) - *y * pitch) / cpp; |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2443 | } |
Ville Syrjälä | 29cf949 | 2016-02-15 22:54:42 +0200 | [diff] [blame] | 2444 | |
| 2445 | return offset_aligned; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2446 | } |
| 2447 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2448 | u32 intel_compute_tile_offset(int *x, int *y, |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2449 | const struct intel_plane_state *state, |
| 2450 | int plane) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2451 | { |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 2452 | const struct drm_i915_private *dev_priv = to_i915(state->base.plane->dev); |
| 2453 | const struct drm_framebuffer *fb = state->base.fb; |
| 2454 | unsigned int rotation = state->base.rotation; |
Ville Syrjälä | ef78ec9 | 2015-10-13 22:48:39 +0300 | [diff] [blame] | 2455 | int pitch = intel_fb_pitch(fb, plane, rotation); |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2456 | u32 alignment; |
| 2457 | |
| 2458 | /* AUX_DIST needs only 4K alignment */ |
| 2459 | if (fb->pixel_format == DRM_FORMAT_NV12 && plane == 1) |
| 2460 | alignment = 4096; |
| 2461 | else |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2462 | alignment = intel_surf_alignment(dev_priv, fb->modifier); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2463 | |
| 2464 | return _intel_compute_tile_offset(dev_priv, x, y, fb, plane, pitch, |
| 2465 | rotation, alignment); |
| 2466 | } |
| 2467 | |
| 2468 | /* Convert the fb->offset[] linear offset into x/y offsets */ |
| 2469 | static void intel_fb_offset_to_xy(int *x, int *y, |
| 2470 | const struct drm_framebuffer *fb, int plane) |
| 2471 | { |
| 2472 | unsigned int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
| 2473 | unsigned int pitch = fb->pitches[plane]; |
| 2474 | u32 linear_offset = fb->offsets[plane]; |
| 2475 | |
| 2476 | *y = linear_offset / pitch; |
| 2477 | *x = linear_offset % pitch / cpp; |
| 2478 | } |
| 2479 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 2480 | static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier) |
| 2481 | { |
| 2482 | switch (fb_modifier) { |
| 2483 | case I915_FORMAT_MOD_X_TILED: |
| 2484 | return I915_TILING_X; |
| 2485 | case I915_FORMAT_MOD_Y_TILED: |
| 2486 | return I915_TILING_Y; |
| 2487 | default: |
| 2488 | return I915_TILING_NONE; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2492 | static int |
| 2493 | intel_fill_fb_info(struct drm_i915_private *dev_priv, |
| 2494 | struct drm_framebuffer *fb) |
| 2495 | { |
| 2496 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 2497 | struct intel_rotation_info *rot_info = &intel_fb->rot_info; |
| 2498 | u32 gtt_offset_rotated = 0; |
| 2499 | unsigned int max_size = 0; |
| 2500 | uint32_t format = fb->pixel_format; |
| 2501 | int i, num_planes = drm_format_num_planes(format); |
| 2502 | unsigned int tile_size = intel_tile_size(dev_priv); |
| 2503 | |
| 2504 | for (i = 0; i < num_planes; i++) { |
| 2505 | unsigned int width, height; |
| 2506 | unsigned int cpp, size; |
| 2507 | u32 offset; |
| 2508 | int x, y; |
| 2509 | |
| 2510 | cpp = drm_format_plane_cpp(format, i); |
| 2511 | width = drm_format_plane_width(fb->width, format, i); |
| 2512 | height = drm_format_plane_height(fb->height, format, i); |
| 2513 | |
| 2514 | intel_fb_offset_to_xy(&x, &y, fb, i); |
| 2515 | |
| 2516 | /* |
Ville Syrjälä | 60d5f2a | 2016-01-22 18:41:24 +0200 | [diff] [blame] | 2517 | * The fence (if used) is aligned to the start of the object |
| 2518 | * so having the framebuffer wrap around across the edge of the |
| 2519 | * fenced region doesn't really work. We have no API to configure |
| 2520 | * the fence start offset within the object (nor could we probably |
| 2521 | * on gen2/3). So it's just easier if we just require that the |
| 2522 | * fb layout agrees with the fence layout. We already check that the |
| 2523 | * fb stride matches the fence stride elsewhere. |
| 2524 | */ |
| 2525 | if (i915_gem_object_is_tiled(intel_fb->obj) && |
| 2526 | (x + width) * cpp > fb->pitches[i]) { |
| 2527 | DRM_DEBUG("bad fb plane %d offset: 0x%x\n", |
| 2528 | i, fb->offsets[i]); |
| 2529 | return -EINVAL; |
| 2530 | } |
| 2531 | |
| 2532 | /* |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2533 | * First pixel of the framebuffer from |
| 2534 | * the start of the normal gtt mapping. |
| 2535 | */ |
| 2536 | intel_fb->normal[i].x = x; |
| 2537 | intel_fb->normal[i].y = y; |
| 2538 | |
| 2539 | offset = _intel_compute_tile_offset(dev_priv, &x, &y, |
| 2540 | fb, 0, fb->pitches[i], |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2541 | DRM_ROTATE_0, tile_size); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2542 | offset /= tile_size; |
| 2543 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2544 | if (fb->modifier != DRM_FORMAT_MOD_NONE) { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2545 | unsigned int tile_width, tile_height; |
| 2546 | unsigned int pitch_tiles; |
| 2547 | struct drm_rect r; |
| 2548 | |
| 2549 | intel_tile_dims(dev_priv, &tile_width, &tile_height, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2550 | fb->modifier, cpp); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2551 | |
| 2552 | rot_info->plane[i].offset = offset; |
| 2553 | rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp); |
| 2554 | rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width); |
| 2555 | rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height); |
| 2556 | |
| 2557 | intel_fb->rotated[i].pitch = |
| 2558 | rot_info->plane[i].height * tile_height; |
| 2559 | |
| 2560 | /* how many tiles does this plane need */ |
| 2561 | size = rot_info->plane[i].stride * rot_info->plane[i].height; |
| 2562 | /* |
| 2563 | * If the plane isn't horizontally tile aligned, |
| 2564 | * we need one more tile. |
| 2565 | */ |
| 2566 | if (x != 0) |
| 2567 | size++; |
| 2568 | |
| 2569 | /* rotate the x/y offsets to match the GTT view */ |
| 2570 | r.x1 = x; |
| 2571 | r.y1 = y; |
| 2572 | r.x2 = x + width; |
| 2573 | r.y2 = y + height; |
| 2574 | drm_rect_rotate(&r, |
| 2575 | rot_info->plane[i].width * tile_width, |
| 2576 | rot_info->plane[i].height * tile_height, |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2577 | DRM_ROTATE_270); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2578 | x = r.x1; |
| 2579 | y = r.y1; |
| 2580 | |
| 2581 | /* rotate the tile dimensions to match the GTT view */ |
| 2582 | pitch_tiles = intel_fb->rotated[i].pitch / tile_height; |
| 2583 | swap(tile_width, tile_height); |
| 2584 | |
| 2585 | /* |
| 2586 | * We only keep the x/y offsets, so push all of the |
| 2587 | * gtt offset into the x/y offsets. |
| 2588 | */ |
Ville Syrjälä | 66a2d92 | 2016-02-05 18:44:05 +0200 | [diff] [blame] | 2589 | _intel_adjust_tile_offset(&x, &y, tile_size, |
| 2590 | tile_width, tile_height, pitch_tiles, |
| 2591 | gtt_offset_rotated * tile_size, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 2592 | |
| 2593 | gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height; |
| 2594 | |
| 2595 | /* |
| 2596 | * First pixel of the framebuffer from |
| 2597 | * the start of the rotated gtt mapping. |
| 2598 | */ |
| 2599 | intel_fb->rotated[i].x = x; |
| 2600 | intel_fb->rotated[i].y = y; |
| 2601 | } else { |
| 2602 | size = DIV_ROUND_UP((y + height) * fb->pitches[i] + |
| 2603 | x * cpp, tile_size); |
| 2604 | } |
| 2605 | |
| 2606 | /* how many tiles in total needed in the bo */ |
| 2607 | max_size = max(max_size, offset + size); |
| 2608 | } |
| 2609 | |
| 2610 | if (max_size * tile_size > to_intel_framebuffer(fb)->obj->base.size) { |
| 2611 | DRM_DEBUG("fb too big for bo (need %u bytes, have %zu bytes)\n", |
| 2612 | max_size * tile_size, to_intel_framebuffer(fb)->obj->base.size); |
| 2613 | return -EINVAL; |
| 2614 | } |
| 2615 | |
| 2616 | return 0; |
| 2617 | } |
| 2618 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2619 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2620 | { |
| 2621 | switch (format) { |
| 2622 | case DISPPLANE_8BPP: |
| 2623 | return DRM_FORMAT_C8; |
| 2624 | case DISPPLANE_BGRX555: |
| 2625 | return DRM_FORMAT_XRGB1555; |
| 2626 | case DISPPLANE_BGRX565: |
| 2627 | return DRM_FORMAT_RGB565; |
| 2628 | default: |
| 2629 | case DISPPLANE_BGRX888: |
| 2630 | return DRM_FORMAT_XRGB8888; |
| 2631 | case DISPPLANE_RGBX888: |
| 2632 | return DRM_FORMAT_XBGR8888; |
| 2633 | case DISPPLANE_BGRX101010: |
| 2634 | return DRM_FORMAT_XRGB2101010; |
| 2635 | case DISPPLANE_RGBX101010: |
| 2636 | return DRM_FORMAT_XBGR2101010; |
| 2637 | } |
| 2638 | } |
| 2639 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2640 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2641 | { |
| 2642 | switch (format) { |
| 2643 | case PLANE_CTL_FORMAT_RGB_565: |
| 2644 | return DRM_FORMAT_RGB565; |
| 2645 | default: |
| 2646 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2647 | if (rgb_order) { |
| 2648 | if (alpha) |
| 2649 | return DRM_FORMAT_ABGR8888; |
| 2650 | else |
| 2651 | return DRM_FORMAT_XBGR8888; |
| 2652 | } else { |
| 2653 | if (alpha) |
| 2654 | return DRM_FORMAT_ARGB8888; |
| 2655 | else |
| 2656 | return DRM_FORMAT_XRGB8888; |
| 2657 | } |
| 2658 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2659 | if (rgb_order) |
| 2660 | return DRM_FORMAT_XBGR2101010; |
| 2661 | else |
| 2662 | return DRM_FORMAT_XRGB2101010; |
| 2663 | } |
| 2664 | } |
| 2665 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2666 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2667 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2668 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2669 | { |
| 2670 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2671 | struct drm_i915_private *dev_priv = to_i915(dev); |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2672 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2673 | struct drm_i915_gem_object *obj = NULL; |
| 2674 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2675 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2676 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2677 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2678 | PAGE_SIZE); |
| 2679 | |
| 2680 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2681 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2682 | if (plane_config->size == 0) |
| 2683 | return false; |
| 2684 | |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2685 | /* If the FB is too big, just don't use it since fbdev is not very |
| 2686 | * important and we should probably use that space with FBC or other |
| 2687 | * features. */ |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 2688 | if (size_aligned * 2 > ggtt->stolen_usable_size) |
Paulo Zanoni | 3badb49 | 2015-09-23 12:52:23 -0300 | [diff] [blame] | 2689 | return false; |
| 2690 | |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2691 | mutex_lock(&dev->struct_mutex); |
| 2692 | |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 2693 | obj = i915_gem_object_create_stolen_for_preallocated(dev_priv, |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2694 | base_aligned, |
| 2695 | base_aligned, |
| 2696 | size_aligned); |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2697 | if (!obj) { |
| 2698 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2699 | return false; |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2700 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2701 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2702 | if (plane_config->tiling == I915_TILING_X) |
| 2703 | obj->tiling_and_stride = fb->pitches[0] | I915_TILING_X; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2704 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2705 | mode_cmd.pixel_format = fb->pixel_format; |
| 2706 | mode_cmd.width = fb->width; |
| 2707 | mode_cmd.height = fb->height; |
| 2708 | mode_cmd.pitches[0] = fb->pitches[0]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2709 | mode_cmd.modifier[0] = fb->modifier; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2710 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2711 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2712 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2713 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2714 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2715 | goto out_unref_obj; |
| 2716 | } |
Tvrtko Ursulin | 12c83d9 | 2016-02-11 10:27:29 +0000 | [diff] [blame] | 2717 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2718 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2719 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2720 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2721 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2722 | |
| 2723 | out_unref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2724 | i915_gem_object_put(obj); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2725 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2726 | return false; |
| 2727 | } |
| 2728 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 2729 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2730 | static void |
| 2731 | update_state_fb(struct drm_plane *plane) |
| 2732 | { |
| 2733 | if (plane->fb == plane->state->fb) |
| 2734 | return; |
| 2735 | |
| 2736 | if (plane->state->fb) |
| 2737 | drm_framebuffer_unreference(plane->state->fb); |
| 2738 | plane->state->fb = plane->fb; |
| 2739 | if (plane->state->fb) |
| 2740 | drm_framebuffer_reference(plane->state->fb); |
| 2741 | } |
| 2742 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2743 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2744 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2745 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2746 | { |
| 2747 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 2748 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2749 | struct drm_crtc *c; |
| 2750 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2751 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2752 | struct drm_plane *primary = intel_crtc->base.primary; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2753 | struct drm_plane_state *plane_state = primary->state; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2754 | struct drm_crtc_state *crtc_state = intel_crtc->base.state; |
| 2755 | struct intel_plane *intel_plane = to_intel_plane(primary); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2756 | struct intel_plane_state *intel_state = |
| 2757 | to_intel_plane_state(plane_state); |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2758 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2759 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2760 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2761 | return; |
| 2762 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2763 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2764 | fb = &plane_config->fb->base; |
| 2765 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2766 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2767 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2768 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2769 | |
| 2770 | /* |
| 2771 | * Failed to alloc the obj, check to see if we should share |
| 2772 | * an fb with another CRTC instead |
| 2773 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2774 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2775 | i = to_intel_crtc(c); |
| 2776 | |
| 2777 | if (c == &intel_crtc->base) |
| 2778 | continue; |
| 2779 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2780 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2781 | continue; |
| 2782 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2783 | fb = c->primary->fb; |
| 2784 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2785 | continue; |
| 2786 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2787 | obj = intel_fb_obj(fb); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 2788 | if (i915_gem_object_ggtt_offset(obj, NULL) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2789 | drm_framebuffer_reference(fb); |
| 2790 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2791 | } |
| 2792 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2793 | |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2794 | /* |
| 2795 | * We've failed to reconstruct the BIOS FB. Current display state |
| 2796 | * indicates that the primary plane is visible, but has a NULL FB, |
| 2797 | * which will lead to problems later if we don't fix it up. The |
| 2798 | * simplest solution is to just disable the primary plane now and |
| 2799 | * pretend the BIOS never had it enabled. |
| 2800 | */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 2801 | to_intel_plane_state(plane_state)->base.visible = false; |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2802 | crtc_state->plane_mask &= ~(1 << drm_plane_index(primary)); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 2803 | intel_pre_disable_primary_noatomic(&intel_crtc->base); |
Matt Roper | 200757f | 2015-12-03 11:37:36 -0800 | [diff] [blame] | 2804 | intel_plane->disable_plane(primary, &intel_crtc->base); |
| 2805 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2806 | return; |
| 2807 | |
| 2808 | valid_fb: |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2809 | plane_state->src_x = 0; |
| 2810 | plane_state->src_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2811 | plane_state->src_w = fb->width << 16; |
| 2812 | plane_state->src_h = fb->height << 16; |
| 2813 | |
Ville Syrjälä | f44e265 | 2015-11-13 19:16:13 +0200 | [diff] [blame] | 2814 | plane_state->crtc_x = 0; |
| 2815 | plane_state->crtc_y = 0; |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2816 | plane_state->crtc_w = fb->width; |
| 2817 | plane_state->crtc_h = fb->height; |
| 2818 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 2819 | intel_state->base.src = drm_plane_state_src(plane_state); |
| 2820 | intel_state->base.dst = drm_plane_state_dest(plane_state); |
Matt Roper | 0a8d8a8 | 2015-12-03 11:37:38 -0800 | [diff] [blame] | 2821 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2822 | obj = intel_fb_obj(fb); |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 2823 | if (i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2824 | dev_priv->preserve_bios_swizzle = true; |
| 2825 | |
Maarten Lankhorst | be5651f | 2015-07-13 16:30:18 +0200 | [diff] [blame] | 2826 | drm_framebuffer_reference(fb); |
| 2827 | primary->fb = primary->state->fb = fb; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2828 | primary->crtc = primary->state->crtc = &intel_crtc->base; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 2829 | intel_crtc->base.state->plane_mask |= (1 << drm_plane_index(primary)); |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 2830 | atomic_or(to_intel_plane(primary)->frontbuffer_bit, |
| 2831 | &obj->frontbuffer_bits); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2832 | } |
| 2833 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2834 | static int skl_max_plane_width(const struct drm_framebuffer *fb, int plane, |
| 2835 | unsigned int rotation) |
| 2836 | { |
| 2837 | int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
| 2838 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2839 | switch (fb->modifier) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2840 | case DRM_FORMAT_MOD_NONE: |
| 2841 | case I915_FORMAT_MOD_X_TILED: |
| 2842 | switch (cpp) { |
| 2843 | case 8: |
| 2844 | return 4096; |
| 2845 | case 4: |
| 2846 | case 2: |
| 2847 | case 1: |
| 2848 | return 8192; |
| 2849 | default: |
| 2850 | MISSING_CASE(cpp); |
| 2851 | break; |
| 2852 | } |
| 2853 | break; |
| 2854 | case I915_FORMAT_MOD_Y_TILED: |
| 2855 | case I915_FORMAT_MOD_Yf_TILED: |
| 2856 | switch (cpp) { |
| 2857 | case 8: |
| 2858 | return 2048; |
| 2859 | case 4: |
| 2860 | return 4096; |
| 2861 | case 2: |
| 2862 | case 1: |
| 2863 | return 8192; |
| 2864 | default: |
| 2865 | MISSING_CASE(cpp); |
| 2866 | break; |
| 2867 | } |
| 2868 | break; |
| 2869 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2870 | MISSING_CASE(fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | return 2048; |
| 2874 | } |
| 2875 | |
| 2876 | static int skl_check_main_surface(struct intel_plane_state *plane_state) |
| 2877 | { |
| 2878 | const struct drm_i915_private *dev_priv = to_i915(plane_state->base.plane->dev); |
| 2879 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2880 | unsigned int rotation = plane_state->base.rotation; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2881 | int x = plane_state->base.src.x1 >> 16; |
| 2882 | int y = plane_state->base.src.y1 >> 16; |
| 2883 | int w = drm_rect_width(&plane_state->base.src) >> 16; |
| 2884 | int h = drm_rect_height(&plane_state->base.src) >> 16; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2885 | int max_width = skl_max_plane_width(fb, 0, rotation); |
| 2886 | int max_height = 4096; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2887 | u32 alignment, offset, aux_offset = plane_state->aux.offset; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2888 | |
| 2889 | if (w > max_width || h > max_height) { |
| 2890 | DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n", |
| 2891 | w, h, max_width, max_height); |
| 2892 | return -EINVAL; |
| 2893 | } |
| 2894 | |
| 2895 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
| 2896 | offset = intel_compute_tile_offset(&x, &y, plane_state, 0); |
| 2897 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2898 | alignment = intel_surf_alignment(dev_priv, fb->modifier); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2899 | |
| 2900 | /* |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2901 | * AUX surface offset is specified as the distance from the |
| 2902 | * main surface offset, and it must be non-negative. Make |
| 2903 | * sure that is what we will get. |
| 2904 | */ |
| 2905 | if (offset > aux_offset) |
| 2906 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, |
| 2907 | offset, aux_offset & ~(alignment - 1)); |
| 2908 | |
| 2909 | /* |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2910 | * When using an X-tiled surface, the plane blows up |
| 2911 | * if the x offset + width exceed the stride. |
| 2912 | * |
| 2913 | * TODO: linear and Y-tiled seem fine, Yf untested, |
| 2914 | */ |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 2915 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2916 | int cpp = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2917 | |
| 2918 | while ((x + w) * cpp > fb->pitches[0]) { |
| 2919 | if (offset == 0) { |
| 2920 | DRM_DEBUG_KMS("Unable to find suitable display surface offset\n"); |
| 2921 | return -EINVAL; |
| 2922 | } |
| 2923 | |
| 2924 | offset = intel_adjust_tile_offset(&x, &y, plane_state, 0, |
| 2925 | offset, offset - alignment); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | plane_state->main.offset = offset; |
| 2930 | plane_state->main.x = x; |
| 2931 | plane_state->main.y = y; |
| 2932 | |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2936 | static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state) |
| 2937 | { |
| 2938 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2939 | unsigned int rotation = plane_state->base.rotation; |
| 2940 | int max_width = skl_max_plane_width(fb, 1, rotation); |
| 2941 | int max_height = 4096; |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2942 | int x = plane_state->base.src.x1 >> 17; |
| 2943 | int y = plane_state->base.src.y1 >> 17; |
| 2944 | int w = drm_rect_width(&plane_state->base.src) >> 17; |
| 2945 | int h = drm_rect_height(&plane_state->base.src) >> 17; |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2946 | u32 offset; |
| 2947 | |
| 2948 | intel_add_fb_offsets(&x, &y, plane_state, 1); |
| 2949 | offset = intel_compute_tile_offset(&x, &y, plane_state, 1); |
| 2950 | |
| 2951 | /* FIXME not quite sure how/if these apply to the chroma plane */ |
| 2952 | if (w > max_width || h > max_height) { |
| 2953 | DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n", |
| 2954 | w, h, max_width, max_height); |
| 2955 | return -EINVAL; |
| 2956 | } |
| 2957 | |
| 2958 | plane_state->aux.offset = offset; |
| 2959 | plane_state->aux.x = x; |
| 2960 | plane_state->aux.y = y; |
| 2961 | |
| 2962 | return 0; |
| 2963 | } |
| 2964 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2965 | int skl_check_plane_surface(struct intel_plane_state *plane_state) |
| 2966 | { |
| 2967 | const struct drm_framebuffer *fb = plane_state->base.fb; |
| 2968 | unsigned int rotation = plane_state->base.rotation; |
| 2969 | int ret; |
| 2970 | |
| 2971 | /* Rotate src coordinates to match rotated GTT view */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2972 | if (drm_rotation_90_or_270(rotation)) |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 2973 | drm_rect_rotate(&plane_state->base.src, |
Ville Syrjälä | da064b4 | 2016-10-24 19:13:04 +0300 | [diff] [blame] | 2974 | fb->width << 16, fb->height << 16, |
| 2975 | DRM_ROTATE_270); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2976 | |
Ville Syrjälä | 8d97065 | 2016-01-28 16:30:28 +0200 | [diff] [blame] | 2977 | /* |
| 2978 | * Handle the AUX surface first since |
| 2979 | * the main surface setup depends on it. |
| 2980 | */ |
| 2981 | if (fb->pixel_format == DRM_FORMAT_NV12) { |
| 2982 | ret = skl_check_nv12_aux_surface(plane_state); |
| 2983 | if (ret) |
| 2984 | return ret; |
| 2985 | } else { |
| 2986 | plane_state->aux.offset = ~0xfff; |
| 2987 | plane_state->aux.x = 0; |
| 2988 | plane_state->aux.y = 0; |
| 2989 | } |
| 2990 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 2991 | ret = skl_check_main_surface(plane_state); |
| 2992 | if (ret) |
| 2993 | return ret; |
| 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 2998 | static void i9xx_update_primary_plane(struct drm_plane *primary, |
| 2999 | const struct intel_crtc_state *crtc_state, |
| 3000 | const struct intel_plane_state *plane_state) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3001 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3002 | struct drm_i915_private *dev_priv = to_i915(primary->dev); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3003 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3004 | struct drm_framebuffer *fb = plane_state->base.fb; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3005 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 3006 | u32 linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3007 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3008 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3009 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3010 | int x = plane_state->base.src.x1 >> 16; |
| 3011 | int y = plane_state->base.src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3012 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3013 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 3014 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 3015 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3016 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3017 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3018 | if (intel_crtc->pipe == PIPE_B) |
| 3019 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 3020 | |
| 3021 | /* pipesrc and dspsize control the size that is scaled from, |
| 3022 | * which should always be the user's requested size. |
| 3023 | */ |
| 3024 | I915_WRITE(DSPSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3025 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3026 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3027 | I915_WRITE(DSPPOS(plane), 0); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 3028 | } else if (IS_CHERRYVIEW(dev_priv) && plane == PLANE_B) { |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 3029 | I915_WRITE(PRIMSIZE(plane), |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3030 | ((crtc_state->pipe_src_h - 1) << 16) | |
| 3031 | (crtc_state->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 3032 | I915_WRITE(PRIMPOS(plane), 0); |
| 3033 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3034 | } |
| 3035 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3036 | switch (fb->pixel_format) { |
| 3037 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3038 | dspcntr |= DISPPLANE_8BPP; |
| 3039 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3040 | case DRM_FORMAT_XRGB1555: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3041 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3042 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3043 | case DRM_FORMAT_RGB565: |
| 3044 | dspcntr |= DISPPLANE_BGRX565; |
| 3045 | break; |
| 3046 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3047 | dspcntr |= DISPPLANE_BGRX888; |
| 3048 | break; |
| 3049 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3050 | dspcntr |= DISPPLANE_RGBX888; |
| 3051 | break; |
| 3052 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3053 | dspcntr |= DISPPLANE_BGRX101010; |
| 3054 | break; |
| 3055 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3056 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3057 | break; |
| 3058 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 3059 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3060 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3061 | |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 3062 | if (INTEL_GEN(dev_priv) >= 4 && |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3063 | fb->modifier == I915_FORMAT_MOD_X_TILED) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3064 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3065 | |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3066 | if (rotation & DRM_ROTATE_180) |
| 3067 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3068 | |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3069 | if (rotation & DRM_REFLECT_X) |
| 3070 | dspcntr |= DISPPLANE_MIRROR; |
| 3071 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 3072 | if (IS_G4X(dev_priv)) |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 3073 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 3074 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3075 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3076 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3077 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 3078 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3079 | intel_compute_tile_offset(&x, &y, plane_state, 0); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3080 | |
Ville Syrjälä | f22aa14 | 2016-11-14 18:53:58 +0200 | [diff] [blame] | 3081 | if (rotation & DRM_ROTATE_180) { |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3082 | x += crtc_state->pipe_src_w - 1; |
| 3083 | y += crtc_state->pipe_src_h - 1; |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 3084 | } else if (rotation & DRM_REFLECT_X) { |
| 3085 | x += crtc_state->pipe_src_w - 1; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3086 | } |
| 3087 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3088 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3089 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3090 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3091 | intel_crtc->dspaddr_offset = linear_offset; |
| 3092 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3093 | intel_crtc->adjusted_x = x; |
| 3094 | intel_crtc->adjusted_y = y; |
| 3095 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3096 | I915_WRITE(reg, dspcntr); |
| 3097 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 3098 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3099 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 3100 | I915_WRITE(DSPSURF(plane), |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3101 | intel_fb_gtt_offset(fb, rotation) + |
| 3102 | intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3103 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 3104 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Ville Syrjälä | bfb8104 | 2016-11-07 22:20:57 +0200 | [diff] [blame] | 3105 | } else { |
| 3106 | I915_WRITE(DSPADDR(plane), |
| 3107 | intel_fb_gtt_offset(fb, rotation) + |
| 3108 | intel_crtc->dspaddr_offset); |
| 3109 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3110 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3111 | } |
| 3112 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3113 | static void i9xx_disable_primary_plane(struct drm_plane *primary, |
| 3114 | struct drm_crtc *crtc) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3115 | { |
| 3116 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3117 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3118 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3119 | int plane = intel_crtc->plane; |
| 3120 | |
| 3121 | I915_WRITE(DSPCNTR(plane), 0); |
| 3122 | if (INTEL_INFO(dev_priv)->gen >= 4) |
| 3123 | I915_WRITE(DSPSURF(plane), 0); |
| 3124 | else |
| 3125 | I915_WRITE(DSPADDR(plane), 0); |
| 3126 | POSTING_READ(DSPCNTR(plane)); |
| 3127 | } |
| 3128 | |
| 3129 | static void ironlake_update_primary_plane(struct drm_plane *primary, |
| 3130 | const struct intel_crtc_state *crtc_state, |
| 3131 | const struct intel_plane_state *plane_state) |
| 3132 | { |
| 3133 | struct drm_device *dev = primary->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3134 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3135 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3136 | struct drm_framebuffer *fb = plane_state->base.fb; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3137 | int plane = intel_crtc->plane; |
Ville Syrjälä | 54ea9da | 2016-01-20 21:05:25 +0200 | [diff] [blame] | 3138 | u32 linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3139 | u32 dspcntr; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3140 | i915_reg_t reg = DSPCNTR(plane); |
Ville Syrjälä | 8d0deca | 2016-02-15 22:54:41 +0200 | [diff] [blame] | 3141 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3142 | int x = plane_state->base.src.x1 >> 16; |
| 3143 | int y = plane_state->base.src.y1 >> 16; |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 3144 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3145 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 3146 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3147 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3148 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 3149 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 3150 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3151 | switch (fb->pixel_format) { |
| 3152 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3153 | dspcntr |= DISPPLANE_8BPP; |
| 3154 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3155 | case DRM_FORMAT_RGB565: |
| 3156 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3157 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3158 | case DRM_FORMAT_XRGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3159 | dspcntr |= DISPPLANE_BGRX888; |
| 3160 | break; |
| 3161 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3162 | dspcntr |= DISPPLANE_RGBX888; |
| 3163 | break; |
| 3164 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3165 | dspcntr |= DISPPLANE_BGRX101010; |
| 3166 | break; |
| 3167 | case DRM_FORMAT_XBGR2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 3168 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3169 | break; |
| 3170 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 3171 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3172 | } |
| 3173 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3174 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3175 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3176 | |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3177 | if (rotation & DRM_ROTATE_180) |
| 3178 | dspcntr |= DISPPLANE_ROTATE_180; |
| 3179 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3180 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 3181 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3182 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3183 | intel_add_fb_offsets(&x, &y, plane_state, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3184 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 3185 | intel_crtc->dspaddr_offset = |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3186 | intel_compute_tile_offset(&x, &y, plane_state, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3187 | |
Ville Syrjälä | df0cd45 | 2016-11-14 18:53:59 +0200 | [diff] [blame] | 3188 | /* HSW+ does this automagically in hardware */ |
| 3189 | if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv) && |
| 3190 | rotation & DRM_ROTATE_180) { |
| 3191 | x += crtc_state->pipe_src_w - 1; |
| 3192 | y += crtc_state->pipe_src_h - 1; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3193 | } |
| 3194 | |
Ville Syrjälä | 2949056 | 2016-01-20 18:02:50 +0200 | [diff] [blame] | 3195 | linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0); |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3196 | |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3197 | intel_crtc->adjusted_x = x; |
| 3198 | intel_crtc->adjusted_y = y; |
| 3199 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 3200 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3201 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 3202 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 3203 | I915_WRITE(DSPSURF(plane), |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3204 | intel_fb_gtt_offset(fb, rotation) + |
| 3205 | intel_crtc->dspaddr_offset); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 3206 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 3207 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 3208 | } else { |
| 3209 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 3210 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 3211 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3212 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3213 | } |
| 3214 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3215 | u32 intel_fb_stride_alignment(const struct drm_i915_private *dev_priv, |
| 3216 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3217 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 3218 | if (fb_modifier == DRM_FORMAT_MOD_NONE) { |
| 3219 | return 64; |
| 3220 | } else { |
| 3221 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3222 | |
Ville Syrjälä | 27ba391 | 2016-02-15 22:54:40 +0200 | [diff] [blame] | 3223 | return intel_tile_width_bytes(dev_priv, fb_modifier, cpp); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3227 | u32 intel_fb_gtt_offset(struct drm_framebuffer *fb, |
| 3228 | unsigned int rotation) |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3229 | { |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3230 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Daniel Vetter | ce7f172 | 2015-10-14 16:51:06 +0200 | [diff] [blame] | 3231 | struct i915_ggtt_view view; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 3232 | struct i915_vma *vma; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3233 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3234 | intel_fill_fb_ggtt_view(&view, fb, rotation); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3235 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 3236 | vma = i915_gem_object_to_ggtt(obj, &view); |
| 3237 | if (WARN(!vma, "ggtt vma for display object not found! (view=%u)\n", |
| 3238 | view.type)) |
| 3239 | return -1; |
| 3240 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 3241 | return i915_ggtt_offset(vma); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3244 | static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id) |
| 3245 | { |
| 3246 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3247 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3248 | |
| 3249 | I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0); |
| 3250 | I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0); |
| 3251 | I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0); |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3254 | /* |
| 3255 | * This function detaches (aka. unbinds) unused scalers in hardware |
| 3256 | */ |
Maarten Lankhorst | 0583236 | 2015-06-15 12:33:48 +0200 | [diff] [blame] | 3257 | static void skl_detach_scalers(struct intel_crtc *intel_crtc) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3258 | { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3259 | struct intel_crtc_scaler_state *scaler_state; |
| 3260 | int i; |
| 3261 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3262 | scaler_state = &intel_crtc->config->scaler_state; |
| 3263 | |
| 3264 | /* loop through and disable scalers that aren't in use */ |
| 3265 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 3266 | if (!scaler_state->scalers[i].in_use) |
| 3267 | skl_detach_scaler(intel_crtc, i); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 3268 | } |
| 3269 | } |
| 3270 | |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3271 | u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane, |
| 3272 | unsigned int rotation) |
| 3273 | { |
| 3274 | const struct drm_i915_private *dev_priv = to_i915(fb->dev); |
| 3275 | u32 stride = intel_fb_pitch(fb, plane, rotation); |
| 3276 | |
| 3277 | /* |
| 3278 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 3279 | * linear buffers or in number of tiles for tiled buffers. |
| 3280 | */ |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3281 | if (drm_rotation_90_or_270(rotation)) { |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3282 | int cpp = drm_format_plane_cpp(fb->pixel_format, plane); |
| 3283 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3284 | stride /= intel_tile_height(dev_priv, fb->modifier, cpp); |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3285 | } else { |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3286 | stride /= intel_fb_stride_alignment(dev_priv, fb->modifier, |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3287 | fb->pixel_format); |
| 3288 | } |
| 3289 | |
| 3290 | return stride; |
| 3291 | } |
| 3292 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3293 | u32 skl_plane_ctl_format(uint32_t pixel_format) |
| 3294 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3295 | switch (pixel_format) { |
Damien Lespiau | d161cf7 | 2015-05-12 16:13:17 +0100 | [diff] [blame] | 3296 | case DRM_FORMAT_C8: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3297 | return PLANE_CTL_FORMAT_INDEXED; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3298 | case DRM_FORMAT_RGB565: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3299 | return PLANE_CTL_FORMAT_RGB_565; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3300 | case DRM_FORMAT_XBGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3301 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3302 | case DRM_FORMAT_XRGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3303 | return PLANE_CTL_FORMAT_XRGB_8888; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3304 | /* |
| 3305 | * XXX: For ARBG/ABGR formats we default to expecting scanout buffers |
| 3306 | * to be already pre-multiplied. We need to add a knob (or a different |
| 3307 | * DRM_FORMAT) for user-space to configure that. |
| 3308 | */ |
| 3309 | case DRM_FORMAT_ABGR8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3310 | return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3311 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3312 | case DRM_FORMAT_ARGB8888: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3313 | return PLANE_CTL_FORMAT_XRGB_8888 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3314 | PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3315 | case DRM_FORMAT_XRGB2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3316 | return PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3317 | case DRM_FORMAT_XBGR2101010: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3318 | return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3319 | case DRM_FORMAT_YUYV: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3320 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3321 | case DRM_FORMAT_YVYU: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3322 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3323 | case DRM_FORMAT_UYVY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3324 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3325 | case DRM_FORMAT_VYUY: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3326 | return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3327 | default: |
Damien Lespiau | 4249eee | 2015-05-12 16:13:16 +0100 | [diff] [blame] | 3328 | MISSING_CASE(pixel_format); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3329 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3330 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3331 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | u32 skl_plane_ctl_tiling(uint64_t fb_modifier) |
| 3335 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3336 | switch (fb_modifier) { |
| 3337 | case DRM_FORMAT_MOD_NONE: |
| 3338 | break; |
| 3339 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3340 | return PLANE_CTL_TILED_X; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3341 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3342 | return PLANE_CTL_TILED_Y; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3343 | case I915_FORMAT_MOD_Yf_TILED: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3344 | return PLANE_CTL_TILED_YF; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3345 | default: |
| 3346 | MISSING_CASE(fb_modifier); |
| 3347 | } |
Damien Lespiau | 8cfcba4 | 2015-05-12 16:13:14 +0100 | [diff] [blame] | 3348 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3349 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | u32 skl_plane_ctl_rotation(unsigned int rotation) |
| 3353 | { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3354 | switch (rotation) { |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 3355 | case DRM_ROTATE_0: |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3356 | break; |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3357 | /* |
| 3358 | * DRM_ROTATE_ is counter clockwise to stay compatible with Xrandr |
| 3359 | * while i915 HW rotation is clockwise, thats why this swapping. |
| 3360 | */ |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 3361 | case DRM_ROTATE_90: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3362 | return PLANE_CTL_ROTATE_270; |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 3363 | case DRM_ROTATE_180: |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3364 | return PLANE_CTL_ROTATE_180; |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 3365 | case DRM_ROTATE_270: |
Sonika Jindal | 1e8df16 | 2015-05-20 13:40:48 +0530 | [diff] [blame] | 3366 | return PLANE_CTL_ROTATE_90; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3367 | default: |
| 3368 | MISSING_CASE(rotation); |
| 3369 | } |
| 3370 | |
Damien Lespiau | c34ce3d | 2015-05-15 15:07:02 +0100 | [diff] [blame] | 3371 | return 0; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3374 | static void skylake_update_primary_plane(struct drm_plane *plane, |
| 3375 | const struct intel_crtc_state *crtc_state, |
| 3376 | const struct intel_plane_state *plane_state) |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3377 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3378 | struct drm_device *dev = plane->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3379 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3380 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc); |
| 3381 | struct drm_framebuffer *fb = plane_state->base.fb; |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3382 | enum plane_id plane_id = to_intel_plane(plane)->id; |
| 3383 | enum pipe pipe = to_intel_plane(plane)->pipe; |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3384 | u32 plane_ctl; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3385 | unsigned int rotation = plane_state->base.rotation; |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 3386 | u32 stride = skl_plane_stride(fb, 0, rotation); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3387 | u32 surf_addr = plane_state->main.offset; |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3388 | int scaler_id = plane_state->scaler_id; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 3389 | int src_x = plane_state->main.x; |
| 3390 | int src_y = plane_state->main.y; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3391 | int src_w = drm_rect_width(&plane_state->base.src) >> 16; |
| 3392 | int src_h = drm_rect_height(&plane_state->base.src) >> 16; |
| 3393 | int dst_x = plane_state->base.dst.x1; |
| 3394 | int dst_y = plane_state->base.dst.y1; |
| 3395 | int dst_w = drm_rect_width(&plane_state->base.dst); |
| 3396 | int dst_h = drm_rect_height(&plane_state->base.dst); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3397 | |
| 3398 | plane_ctl = PLANE_CTL_ENABLE | |
| 3399 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 3400 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 3401 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3402 | plane_ctl |= skl_plane_ctl_format(fb->pixel_format); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 3403 | plane_ctl |= skl_plane_ctl_tiling(fb->modifier); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3404 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3405 | plane_ctl |= skl_plane_ctl_rotation(rotation); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3406 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3407 | /* Sizes are 0 based */ |
| 3408 | src_w--; |
| 3409 | src_h--; |
| 3410 | dst_w--; |
| 3411 | dst_h--; |
| 3412 | |
Paulo Zanoni | 4c0b8a8 | 2016-08-19 19:03:23 -0300 | [diff] [blame] | 3413 | intel_crtc->dspaddr_offset = surf_addr; |
| 3414 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3415 | intel_crtc->adjusted_x = src_x; |
| 3416 | intel_crtc->adjusted_y = src_y; |
Paulo Zanoni | 2db3366 | 2015-09-14 15:20:03 -0300 | [diff] [blame] | 3417 | |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3418 | I915_WRITE(PLANE_CTL(pipe, plane_id), plane_ctl); |
| 3419 | I915_WRITE(PLANE_OFFSET(pipe, plane_id), (src_y << 16) | src_x); |
| 3420 | I915_WRITE(PLANE_STRIDE(pipe, plane_id), stride); |
| 3421 | I915_WRITE(PLANE_SIZE(pipe, plane_id), (src_h << 16) | src_w); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3422 | |
| 3423 | if (scaler_id >= 0) { |
| 3424 | uint32_t ps_ctrl = 0; |
| 3425 | |
| 3426 | WARN_ON(!dst_w || !dst_h); |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3427 | ps_ctrl = PS_SCALER_EN | PS_PLANE_SEL(plane_id) | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3428 | crtc_state->scaler_state.scalers[scaler_id].mode; |
| 3429 | I915_WRITE(SKL_PS_CTRL(pipe, scaler_id), ps_ctrl); |
| 3430 | I915_WRITE(SKL_PS_PWR_GATE(pipe, scaler_id), 0); |
| 3431 | I915_WRITE(SKL_PS_WIN_POS(pipe, scaler_id), (dst_x << 16) | dst_y); |
| 3432 | I915_WRITE(SKL_PS_WIN_SZ(pipe, scaler_id), (dst_w << 16) | dst_h); |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3433 | I915_WRITE(PLANE_POS(pipe, plane_id), 0); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3434 | } else { |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3435 | I915_WRITE(PLANE_POS(pipe, plane_id), (dst_y << 16) | dst_x); |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3438 | I915_WRITE(PLANE_SURF(pipe, plane_id), |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 3439 | intel_fb_gtt_offset(fb, rotation) + surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3440 | |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3441 | POSTING_READ(PLANE_SURF(pipe, plane_id)); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3442 | } |
| 3443 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3444 | static void skylake_disable_primary_plane(struct drm_plane *primary, |
| 3445 | struct drm_crtc *crtc) |
| 3446 | { |
| 3447 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3448 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3449 | enum plane_id plane_id = to_intel_plane(primary)->id; |
| 3450 | enum pipe pipe = to_intel_plane(primary)->pipe; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 3451 | |
Ville Syrjälä | 8e816bb | 2016-11-22 18:01:59 +0200 | [diff] [blame] | 3452 | I915_WRITE(PLANE_CTL(pipe, plane_id), 0); |
| 3453 | I915_WRITE(PLANE_SURF(pipe, plane_id), 0); |
| 3454 | POSTING_READ(PLANE_SURF(pipe, plane_id)); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3455 | } |
| 3456 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3457 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3458 | static int |
| 3459 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3460 | int x, int y, enum mode_set_atomic state) |
| 3461 | { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3462 | /* Support for kgdboc is disabled, this needs a major rework. */ |
| 3463 | DRM_ERROR("legacy panic handler not supported any more.\n"); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3464 | |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3465 | return -ENODEV; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3468 | static void intel_complete_page_flips(struct drm_i915_private *dev_priv) |
| 3469 | { |
| 3470 | struct intel_crtc *crtc; |
| 3471 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 3472 | for_each_intel_crtc(&dev_priv->drm, crtc) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3473 | intel_finish_page_flip_cs(dev_priv, crtc->pipe); |
| 3474 | } |
| 3475 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3476 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3477 | { |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3478 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3479 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3480 | for_each_crtc(dev, crtc) { |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3481 | struct intel_plane *plane = to_intel_plane(crtc->primary); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3482 | struct intel_plane_state *plane_state = |
| 3483 | to_intel_plane_state(plane->base.state); |
Maarten Lankhorst | 11c22da | 2015-09-10 16:07:58 +0200 | [diff] [blame] | 3484 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 3485 | if (plane_state->base.visible) |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 3486 | plane->update_plane(&plane->base, |
| 3487 | to_intel_crtc_state(crtc->state), |
| 3488 | plane_state); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3489 | } |
| 3490 | } |
| 3491 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3492 | static int |
| 3493 | __intel_display_resume(struct drm_device *dev, |
| 3494 | struct drm_atomic_state *state) |
| 3495 | { |
| 3496 | struct drm_crtc_state *crtc_state; |
| 3497 | struct drm_crtc *crtc; |
| 3498 | int i, ret; |
| 3499 | |
| 3500 | intel_modeset_setup_hw_state(dev); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 3501 | i915_redisable_vga(to_i915(dev)); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3502 | |
| 3503 | if (!state) |
| 3504 | return 0; |
| 3505 | |
| 3506 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 3507 | /* |
| 3508 | * Force recalculation even if we restore |
| 3509 | * current state. With fast modeset this may not result |
| 3510 | * in a modeset when the state is compatible. |
| 3511 | */ |
| 3512 | crtc_state->mode_changed = true; |
| 3513 | } |
| 3514 | |
| 3515 | /* ignore any reset values/BIOS leftovers in the WM registers */ |
| 3516 | to_intel_atomic_state(state)->skip_intermediate_wm = true; |
| 3517 | |
| 3518 | ret = drm_atomic_commit(state); |
| 3519 | |
| 3520 | WARN_ON(ret == -EDEADLK); |
| 3521 | return ret; |
| 3522 | } |
| 3523 | |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3524 | static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv) |
| 3525 | { |
Ville Syrjälä | ae98104 | 2016-08-05 23:28:30 +0300 | [diff] [blame] | 3526 | return intel_has_gpu_reset(dev_priv) && |
| 3527 | INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv); |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3528 | } |
| 3529 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3530 | void intel_prepare_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3531 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3532 | struct drm_device *dev = &dev_priv->drm; |
| 3533 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3534 | struct drm_atomic_state *state; |
| 3535 | int ret; |
| 3536 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3537 | /* |
| 3538 | * Need mode_config.mutex so that we don't |
| 3539 | * trample ongoing ->detect() and whatnot. |
| 3540 | */ |
| 3541 | mutex_lock(&dev->mode_config.mutex); |
| 3542 | drm_modeset_acquire_init(ctx, 0); |
| 3543 | while (1) { |
| 3544 | ret = drm_modeset_lock_all_ctx(dev, ctx); |
| 3545 | if (ret != -EDEADLK) |
| 3546 | break; |
| 3547 | |
| 3548 | drm_modeset_backoff(ctx); |
| 3549 | } |
| 3550 | |
| 3551 | /* reset doesn't touch the display, but flips might get nuked anyway, */ |
Maarten Lankhorst | 522a63d | 2016-08-05 23:28:28 +0300 | [diff] [blame] | 3552 | if (!i915.force_reset_modeset_test && |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3553 | !gpu_reset_clobbers_display(dev_priv)) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3554 | return; |
| 3555 | |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3556 | /* |
| 3557 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3558 | * g33 docs say we should at least disable all the planes. |
| 3559 | */ |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3560 | state = drm_atomic_helper_duplicate_state(dev, ctx); |
| 3561 | if (IS_ERR(state)) { |
| 3562 | ret = PTR_ERR(state); |
| 3563 | state = NULL; |
| 3564 | DRM_ERROR("Duplicating state failed with %i\n", ret); |
| 3565 | goto err; |
| 3566 | } |
| 3567 | |
| 3568 | ret = drm_atomic_helper_disable_all(dev, ctx); |
| 3569 | if (ret) { |
| 3570 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
| 3571 | goto err; |
| 3572 | } |
| 3573 | |
| 3574 | dev_priv->modeset_restore_state = state; |
| 3575 | state->acquire_ctx = ctx; |
| 3576 | return; |
| 3577 | |
| 3578 | err: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3579 | drm_atomic_state_put(state); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3580 | } |
| 3581 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 3582 | void intel_finish_reset(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3583 | { |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3584 | struct drm_device *dev = &dev_priv->drm; |
| 3585 | struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx; |
| 3586 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 3587 | int ret; |
| 3588 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3589 | /* |
| 3590 | * Flips in the rings will be nuked by the reset, |
| 3591 | * so complete all pending flips so that user space |
| 3592 | * will get its events and not get stuck. |
| 3593 | */ |
| 3594 | intel_complete_page_flips(dev_priv); |
| 3595 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3596 | dev_priv->modeset_restore_state = NULL; |
| 3597 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3598 | /* reset doesn't touch the display */ |
Ville Syrjälä | 4ac2ba2 | 2016-08-05 23:28:29 +0300 | [diff] [blame] | 3599 | if (!gpu_reset_clobbers_display(dev_priv)) { |
Maarten Lankhorst | 522a63d | 2016-08-05 23:28:28 +0300 | [diff] [blame] | 3600 | if (!state) { |
| 3601 | /* |
| 3602 | * Flips in the rings have been nuked by the reset, |
| 3603 | * so update the base address of all primary |
| 3604 | * planes to the the last fb to make sure we're |
| 3605 | * showing the correct fb after a reset. |
| 3606 | * |
| 3607 | * FIXME: Atomic will make this obsolete since we won't schedule |
| 3608 | * CS-based flips (which might get lost in gpu resets) any more. |
| 3609 | */ |
| 3610 | intel_update_primary_planes(dev); |
| 3611 | } else { |
| 3612 | ret = __intel_display_resume(dev, state); |
| 3613 | if (ret) |
| 3614 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3615 | } |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3616 | } else { |
| 3617 | /* |
| 3618 | * The display has been reset as well, |
| 3619 | * so need a full re-initialization. |
| 3620 | */ |
| 3621 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3622 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3623 | |
Imre Deak | 51f5920 | 2016-09-14 13:04:13 +0300 | [diff] [blame] | 3624 | intel_pps_unlock_regs_wa(dev_priv); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3625 | intel_modeset_init_hw(dev); |
| 3626 | |
| 3627 | spin_lock_irq(&dev_priv->irq_lock); |
| 3628 | if (dev_priv->display.hpd_irq_setup) |
| 3629 | dev_priv->display.hpd_irq_setup(dev_priv); |
| 3630 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3631 | |
| 3632 | ret = __intel_display_resume(dev, state); |
| 3633 | if (ret) |
| 3634 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
| 3635 | |
| 3636 | intel_hpd_init(dev_priv); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3637 | } |
| 3638 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3639 | if (state) |
| 3640 | drm_atomic_state_put(state); |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 3641 | drm_modeset_drop_locks(ctx); |
| 3642 | drm_modeset_acquire_fini(ctx); |
| 3643 | mutex_unlock(&dev->mode_config.mutex); |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3644 | } |
| 3645 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 3646 | static bool abort_flip_on_reset(struct intel_crtc *crtc) |
| 3647 | { |
| 3648 | struct i915_gpu_error *error = &to_i915(crtc->base.dev)->gpu_error; |
| 3649 | |
| 3650 | if (i915_reset_in_progress(error)) |
| 3651 | return true; |
| 3652 | |
| 3653 | if (crtc->reset_count != i915_reset_count(error)) |
| 3654 | return true; |
| 3655 | |
| 3656 | return false; |
| 3657 | } |
| 3658 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3659 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3660 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3661 | struct drm_device *dev = crtc->dev; |
| 3662 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3663 | bool pending; |
| 3664 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 3665 | if (abort_flip_on_reset(intel_crtc)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 3666 | return false; |
| 3667 | |
| 3668 | spin_lock_irq(&dev->event_lock); |
| 3669 | pending = to_intel_crtc(crtc)->flip_work != NULL; |
| 3670 | spin_unlock_irq(&dev->event_lock); |
| 3671 | |
| 3672 | return pending; |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3675 | static void intel_update_pipe_config(struct intel_crtc *crtc, |
| 3676 | struct intel_crtc_state *old_crtc_state) |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3677 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3678 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3679 | struct intel_crtc_state *pipe_config = |
| 3680 | to_intel_crtc_state(crtc->base.state); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3681 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3682 | /* drm_atomic_helper_update_legacy_modeset_state might not be called. */ |
| 3683 | crtc->base.mode = crtc->base.state->mode; |
| 3684 | |
| 3685 | DRM_DEBUG_KMS("Updating pipe size %ix%i -> %ix%i\n", |
| 3686 | old_crtc_state->pipe_src_w, old_crtc_state->pipe_src_h, |
| 3687 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3688 | |
| 3689 | /* |
| 3690 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3691 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3692 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3693 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3694 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3695 | * sized surface. |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3696 | */ |
| 3697 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3698 | I915_WRITE(PIPESRC(crtc->pipe), |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3699 | ((pipe_config->pipe_src_w - 1) << 16) | |
| 3700 | (pipe_config->pipe_src_h - 1)); |
| 3701 | |
| 3702 | /* on skylake this is done by detaching scalers */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 3703 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3704 | skl_detach_scalers(crtc); |
| 3705 | |
| 3706 | if (pipe_config->pch_pfit.enabled) |
| 3707 | skylake_pfit_enable(crtc); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3708 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 3709 | if (pipe_config->pch_pfit.enabled) |
| 3710 | ironlake_pfit_enable(crtc); |
| 3711 | else if (old_crtc_state->pch_pfit.enabled) |
| 3712 | ironlake_pfit_disable(crtc, true); |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3713 | } |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3714 | } |
| 3715 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3716 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3717 | { |
| 3718 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3719 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3720 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3721 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3722 | i915_reg_t reg; |
| 3723 | u32 temp; |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3724 | |
| 3725 | /* enable normal train */ |
| 3726 | reg = FDI_TX_CTL(pipe); |
| 3727 | temp = I915_READ(reg); |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3728 | if (IS_IVYBRIDGE(dev_priv)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3729 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3730 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3731 | } else { |
| 3732 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3733 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3734 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3735 | I915_WRITE(reg, temp); |
| 3736 | |
| 3737 | reg = FDI_RX_CTL(pipe); |
| 3738 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3739 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3740 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3741 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3742 | } else { |
| 3743 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3744 | temp |= FDI_LINK_TRAIN_NONE; |
| 3745 | } |
| 3746 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3747 | |
| 3748 | /* wait one idle pattern time */ |
| 3749 | POSTING_READ(reg); |
| 3750 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3751 | |
| 3752 | /* IVB wants error correction enabled */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 3753 | if (IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3754 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3755 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3756 | } |
| 3757 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3758 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3759 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3760 | { |
| 3761 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3762 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3763 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3764 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3765 | i915_reg_t reg; |
| 3766 | u32 temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3767 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3768 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3769 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3770 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3771 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3772 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3773 | reg = FDI_RX_IMR(pipe); |
| 3774 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3775 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3776 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3777 | I915_WRITE(reg, temp); |
| 3778 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3779 | udelay(150); |
| 3780 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3781 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3782 | reg = FDI_TX_CTL(pipe); |
| 3783 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3784 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3785 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3786 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3787 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3788 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3789 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3790 | reg = FDI_RX_CTL(pipe); |
| 3791 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3792 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3793 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3794 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3795 | |
| 3796 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3797 | udelay(150); |
| 3798 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3799 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3800 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3801 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3802 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3803 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3804 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3805 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3806 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3807 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3808 | |
| 3809 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3810 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3811 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3812 | break; |
| 3813 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3814 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3815 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3816 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3817 | |
| 3818 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3819 | reg = FDI_TX_CTL(pipe); |
| 3820 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3821 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3822 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3823 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3824 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3825 | reg = FDI_RX_CTL(pipe); |
| 3826 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3827 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3828 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3829 | I915_WRITE(reg, temp); |
| 3830 | |
| 3831 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3832 | udelay(150); |
| 3833 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3834 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3835 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3836 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3837 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3838 | |
| 3839 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3840 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3841 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3842 | break; |
| 3843 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3844 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3845 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3846 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3847 | |
| 3848 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3849 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3850 | } |
| 3851 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3852 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3853 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3854 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3855 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3856 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3857 | }; |
| 3858 | |
| 3859 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3860 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3861 | { |
| 3862 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3863 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3864 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3865 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3866 | i915_reg_t reg; |
| 3867 | u32 temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3868 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3869 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3870 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3871 | reg = FDI_RX_IMR(pipe); |
| 3872 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3873 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3874 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3875 | I915_WRITE(reg, temp); |
| 3876 | |
| 3877 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3878 | udelay(150); |
| 3879 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3880 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3881 | reg = FDI_TX_CTL(pipe); |
| 3882 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3883 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3884 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3885 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3886 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3887 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3888 | /* SNB-B */ |
| 3889 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3890 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3891 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3892 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3893 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3894 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3895 | reg = FDI_RX_CTL(pipe); |
| 3896 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3897 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3898 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3899 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3900 | } else { |
| 3901 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3902 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3903 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3904 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3905 | |
| 3906 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3907 | udelay(150); |
| 3908 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3909 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3910 | reg = FDI_TX_CTL(pipe); |
| 3911 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3912 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3913 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3914 | I915_WRITE(reg, temp); |
| 3915 | |
| 3916 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3917 | udelay(500); |
| 3918 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3919 | for (retry = 0; retry < 5; retry++) { |
| 3920 | reg = FDI_RX_IIR(pipe); |
| 3921 | temp = I915_READ(reg); |
| 3922 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3923 | if (temp & FDI_RX_BIT_LOCK) { |
| 3924 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3925 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3926 | break; |
| 3927 | } |
| 3928 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3929 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3930 | if (retry < 5) |
| 3931 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3932 | } |
| 3933 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3934 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3935 | |
| 3936 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3937 | reg = FDI_TX_CTL(pipe); |
| 3938 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3939 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3940 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 3941 | if (IS_GEN6(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3942 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3943 | /* SNB-B */ |
| 3944 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3945 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3946 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3947 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3948 | reg = FDI_RX_CTL(pipe); |
| 3949 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 3950 | if (HAS_PCH_CPT(dev_priv)) { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3951 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3952 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3953 | } else { |
| 3954 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3955 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3956 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3957 | I915_WRITE(reg, temp); |
| 3958 | |
| 3959 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3960 | udelay(150); |
| 3961 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3962 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3963 | reg = FDI_TX_CTL(pipe); |
| 3964 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3965 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3966 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3967 | I915_WRITE(reg, temp); |
| 3968 | |
| 3969 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3970 | udelay(500); |
| 3971 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3972 | for (retry = 0; retry < 5; retry++) { |
| 3973 | reg = FDI_RX_IIR(pipe); |
| 3974 | temp = I915_READ(reg); |
| 3975 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3976 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3977 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3978 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3979 | break; |
| 3980 | } |
| 3981 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3982 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3983 | if (retry < 5) |
| 3984 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3985 | } |
| 3986 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3987 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3988 | |
| 3989 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3990 | } |
| 3991 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3992 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3993 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3994 | { |
| 3995 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 3996 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3997 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3998 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 3999 | i915_reg_t reg; |
| 4000 | u32 temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4001 | |
| 4002 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 4003 | for train result */ |
| 4004 | reg = FDI_RX_IMR(pipe); |
| 4005 | temp = I915_READ(reg); |
| 4006 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 4007 | temp &= ~FDI_RX_BIT_LOCK; |
| 4008 | I915_WRITE(reg, temp); |
| 4009 | |
| 4010 | POSTING_READ(reg); |
| 4011 | udelay(150); |
| 4012 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 4013 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 4014 | I915_READ(FDI_RX_IIR(pipe))); |
| 4015 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4016 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 4017 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 4018 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4019 | reg = FDI_TX_CTL(pipe); |
| 4020 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4021 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 4022 | temp &= ~FDI_TX_ENABLE; |
| 4023 | I915_WRITE(reg, temp); |
| 4024 | |
| 4025 | reg = FDI_RX_CTL(pipe); |
| 4026 | temp = I915_READ(reg); |
| 4027 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 4028 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4029 | temp &= ~FDI_RX_ENABLE; |
| 4030 | I915_WRITE(reg, temp); |
| 4031 | |
| 4032 | /* enable CPU FDI TX and PCH FDI RX */ |
| 4033 | reg = FDI_TX_CTL(pipe); |
| 4034 | temp = I915_READ(reg); |
| 4035 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4036 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4037 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4038 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4039 | temp |= snb_b_fdi_train_param[j/2]; |
| 4040 | temp |= FDI_COMPOSITE_SYNC; |
| 4041 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 4042 | |
| 4043 | I915_WRITE(FDI_RX_MISC(pipe), |
| 4044 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 4045 | |
| 4046 | reg = FDI_RX_CTL(pipe); |
| 4047 | temp = I915_READ(reg); |
| 4048 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4049 | temp |= FDI_COMPOSITE_SYNC; |
| 4050 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 4051 | |
| 4052 | POSTING_READ(reg); |
| 4053 | udelay(1); /* should be 0.5us */ |
| 4054 | |
| 4055 | for (i = 0; i < 4; i++) { |
| 4056 | reg = FDI_RX_IIR(pipe); |
| 4057 | temp = I915_READ(reg); |
| 4058 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 4059 | |
| 4060 | if (temp & FDI_RX_BIT_LOCK || |
| 4061 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 4062 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 4063 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 4064 | i); |
| 4065 | break; |
| 4066 | } |
| 4067 | udelay(1); /* should be 0.5us */ |
| 4068 | } |
| 4069 | if (i == 4) { |
| 4070 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 4071 | continue; |
| 4072 | } |
| 4073 | |
| 4074 | /* Train 2 */ |
| 4075 | reg = FDI_TX_CTL(pipe); |
| 4076 | temp = I915_READ(reg); |
| 4077 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 4078 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 4079 | I915_WRITE(reg, temp); |
| 4080 | |
| 4081 | reg = FDI_RX_CTL(pipe); |
| 4082 | temp = I915_READ(reg); |
| 4083 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4084 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4085 | I915_WRITE(reg, temp); |
| 4086 | |
| 4087 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4088 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4089 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4090 | for (i = 0; i < 4; i++) { |
| 4091 | reg = FDI_RX_IIR(pipe); |
| 4092 | temp = I915_READ(reg); |
| 4093 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4094 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4095 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 4096 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 4097 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 4098 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 4099 | i); |
| 4100 | goto train_done; |
| 4101 | } |
| 4102 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4103 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4104 | if (i == 4) |
| 4105 | 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] | 4106 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4107 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 4108 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 4109 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 4110 | } |
| 4111 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4112 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4113 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4114 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4115 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4116 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4117 | i915_reg_t reg; |
| 4118 | u32 temp; |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 4119 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4120 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4121 | reg = FDI_RX_CTL(pipe); |
| 4122 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 4123 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4124 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4125 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4126 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 4127 | |
| 4128 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4129 | udelay(200); |
| 4130 | |
| 4131 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4132 | temp = I915_READ(reg); |
| 4133 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 4134 | |
| 4135 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4136 | udelay(200); |
| 4137 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4138 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 4139 | reg = FDI_TX_CTL(pipe); |
| 4140 | temp = I915_READ(reg); |
| 4141 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 4142 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4143 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 4144 | POSTING_READ(reg); |
| 4145 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 4146 | } |
| 4147 | } |
| 4148 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4149 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 4150 | { |
| 4151 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4152 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4153 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4154 | i915_reg_t reg; |
| 4155 | u32 temp; |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4156 | |
| 4157 | /* Switch from PCDclk to Rawclk */ |
| 4158 | reg = FDI_RX_CTL(pipe); |
| 4159 | temp = I915_READ(reg); |
| 4160 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 4161 | |
| 4162 | /* Disable CPU FDI TX PLL */ |
| 4163 | reg = FDI_TX_CTL(pipe); |
| 4164 | temp = I915_READ(reg); |
| 4165 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 4166 | |
| 4167 | POSTING_READ(reg); |
| 4168 | udelay(100); |
| 4169 | |
| 4170 | reg = FDI_RX_CTL(pipe); |
| 4171 | temp = I915_READ(reg); |
| 4172 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 4173 | |
| 4174 | /* Wait for the clocks to turn off. */ |
| 4175 | POSTING_READ(reg); |
| 4176 | udelay(100); |
| 4177 | } |
| 4178 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4179 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 4180 | { |
| 4181 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4182 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4183 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4184 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4185 | i915_reg_t reg; |
| 4186 | u32 temp; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4187 | |
| 4188 | /* disable CPU FDI tx and PCH FDI rx */ |
| 4189 | reg = FDI_TX_CTL(pipe); |
| 4190 | temp = I915_READ(reg); |
| 4191 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 4192 | POSTING_READ(reg); |
| 4193 | |
| 4194 | reg = FDI_RX_CTL(pipe); |
| 4195 | temp = I915_READ(reg); |
| 4196 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4197 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4198 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 4199 | |
| 4200 | POSTING_READ(reg); |
| 4201 | udelay(100); |
| 4202 | |
| 4203 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4204 | if (HAS_PCH_IBX(dev_priv)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 4205 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4206 | |
| 4207 | /* still set train pattern 1 */ |
| 4208 | reg = FDI_TX_CTL(pipe); |
| 4209 | temp = I915_READ(reg); |
| 4210 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4211 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4212 | I915_WRITE(reg, temp); |
| 4213 | |
| 4214 | reg = FDI_RX_CTL(pipe); |
| 4215 | temp = I915_READ(reg); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4216 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4217 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 4218 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 4219 | } else { |
| 4220 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 4221 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 4222 | } |
| 4223 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 4224 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4225 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 4226 | I915_WRITE(reg, temp); |
| 4227 | |
| 4228 | POSTING_READ(reg); |
| 4229 | udelay(100); |
| 4230 | } |
| 4231 | |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4232 | bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv) |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4233 | { |
| 4234 | struct intel_crtc *crtc; |
| 4235 | |
| 4236 | /* Note that we don't need to be called with mode_config.lock here |
| 4237 | * as our list of CRTC objects is static for the lifetime of the |
| 4238 | * device and so cannot disappear as we iterate. Similarly, we can |
| 4239 | * happily treat the predicates as racy, atomic checks as userspace |
| 4240 | * cannot claim and pin a new fb without at least acquring the |
| 4241 | * struct_mutex and so serialising with us. |
| 4242 | */ |
Chris Wilson | 49d7391 | 2016-11-29 09:50:08 +0000 | [diff] [blame] | 4243 | for_each_intel_crtc(&dev_priv->drm, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4244 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 4245 | continue; |
| 4246 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4247 | if (crtc->flip_work) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4248 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 4249 | |
| 4250 | return true; |
| 4251 | } |
| 4252 | |
| 4253 | return false; |
| 4254 | } |
| 4255 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4256 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 4257 | { |
| 4258 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4259 | struct intel_flip_work *work = intel_crtc->flip_work; |
| 4260 | |
| 4261 | intel_crtc->flip_work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 4262 | |
| 4263 | if (work->event) |
Gustavo Padovan | 560ce1d | 2016-04-14 10:48:15 -0700 | [diff] [blame] | 4264 | drm_crtc_send_vblank_event(&intel_crtc->base, work->event); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 4265 | |
| 4266 | drm_crtc_vblank_put(&intel_crtc->base); |
| 4267 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4268 | wake_up_all(&dev_priv->pending_flip_queue); |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 4269 | queue_work(dev_priv->wq, &work->unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4270 | |
| 4271 | trace_i915_flip_complete(intel_crtc->plane, |
| 4272 | work->pending_flip_obj); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 4273 | } |
| 4274 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 4275 | static int intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 4276 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 4277 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4278 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 4279 | long ret; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 4280 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 4281 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 4282 | |
| 4283 | ret = wait_event_interruptible_timeout( |
| 4284 | dev_priv->pending_flip_queue, |
| 4285 | !intel_crtc_has_pending_flip(crtc), |
| 4286 | 60*HZ); |
| 4287 | |
| 4288 | if (ret < 0) |
| 4289 | return ret; |
| 4290 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 4291 | if (ret == 0) { |
| 4292 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4293 | struct intel_flip_work *work; |
| 4294 | |
| 4295 | spin_lock_irq(&dev->event_lock); |
| 4296 | work = intel_crtc->flip_work; |
| 4297 | if (work && !is_mmio_work(work)) { |
| 4298 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 4299 | page_flip_completed(intel_crtc); |
| 4300 | } |
| 4301 | spin_unlock_irq(&dev->event_lock); |
| 4302 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 4303 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 4304 | return 0; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 4305 | } |
| 4306 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 4307 | void lpt_disable_iclkip(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4308 | { |
| 4309 | u32 temp; |
| 4310 | |
| 4311 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 4312 | |
| 4313 | mutex_lock(&dev_priv->sb_lock); |
| 4314 | |
| 4315 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4316 | temp |= SBI_SSCCTL_DISABLE; |
| 4317 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
| 4318 | |
| 4319 | mutex_unlock(&dev_priv->sb_lock); |
| 4320 | } |
| 4321 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4322 | /* Program iCLKIP clock to the desired frequency */ |
| 4323 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 4324 | { |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4325 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4326 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4327 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 4328 | u32 temp; |
| 4329 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4330 | lpt_disable_iclkip(dev_priv); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4331 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4332 | /* The iCLK virtual clock root frequency is in MHz, |
| 4333 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 4334 | * divisors, it is necessary to divide one by another, so we |
| 4335 | * convert the virtual clock precision to KHz here for higher |
| 4336 | * precision. |
| 4337 | */ |
| 4338 | for (auxdiv = 0; auxdiv < 2; auxdiv++) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4339 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4340 | u32 iclk_pi_range = 64; |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4341 | u32 desired_divisor; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4342 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4343 | desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4344 | clock << auxdiv); |
| 4345 | divsel = (desired_divisor / iclk_pi_range) - 2; |
| 4346 | phaseinc = desired_divisor % iclk_pi_range; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4347 | |
Ville Syrjälä | 64b46a0 | 2016-02-17 21:41:11 +0200 | [diff] [blame] | 4348 | /* |
| 4349 | * Near 20MHz is a corner case which is |
| 4350 | * out of range for the 7-bit divisor |
| 4351 | */ |
| 4352 | if (divsel <= 0x7f) |
| 4353 | break; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | /* This should not happen with any sane values */ |
| 4357 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 4358 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 4359 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 4360 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 4361 | |
| 4362 | 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] | 4363 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4364 | auxdiv, |
| 4365 | divsel, |
| 4366 | phasedir, |
| 4367 | phaseinc); |
| 4368 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4369 | mutex_lock(&dev_priv->sb_lock); |
| 4370 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4371 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4372 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4373 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 4374 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 4375 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 4376 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 4377 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 4378 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4379 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4380 | |
| 4381 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4382 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4383 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 4384 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4385 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4386 | |
| 4387 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4388 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4389 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 4390 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4391 | |
Ville Syrjälä | 060f02d | 2015-12-04 22:21:34 +0200 | [diff] [blame] | 4392 | mutex_unlock(&dev_priv->sb_lock); |
| 4393 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 4394 | /* Wait for initialization time */ |
| 4395 | udelay(24); |
| 4396 | |
| 4397 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
| 4398 | } |
| 4399 | |
Ville Syrjälä | 8802e5b | 2016-02-17 21:41:12 +0200 | [diff] [blame] | 4400 | int lpt_get_iclkip(struct drm_i915_private *dev_priv) |
| 4401 | { |
| 4402 | u32 divsel, phaseinc, auxdiv; |
| 4403 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 4404 | u32 iclk_pi_range = 64; |
| 4405 | u32 desired_divisor; |
| 4406 | u32 temp; |
| 4407 | |
| 4408 | if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0) |
| 4409 | return 0; |
| 4410 | |
| 4411 | mutex_lock(&dev_priv->sb_lock); |
| 4412 | |
| 4413 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
| 4414 | if (temp & SBI_SSCCTL_DISABLE) { |
| 4415 | mutex_unlock(&dev_priv->sb_lock); |
| 4416 | return 0; |
| 4417 | } |
| 4418 | |
| 4419 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
| 4420 | divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >> |
| 4421 | SBI_SSCDIVINTPHASE_DIVSEL_SHIFT; |
| 4422 | phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >> |
| 4423 | SBI_SSCDIVINTPHASE_INCVAL_SHIFT; |
| 4424 | |
| 4425 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
| 4426 | auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >> |
| 4427 | SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT; |
| 4428 | |
| 4429 | mutex_unlock(&dev_priv->sb_lock); |
| 4430 | |
| 4431 | desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc; |
| 4432 | |
| 4433 | return DIV_ROUND_CLOSEST(iclk_virtual_root_freq, |
| 4434 | desired_divisor << auxdiv); |
| 4435 | } |
| 4436 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4437 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 4438 | enum pipe pch_transcoder) |
| 4439 | { |
| 4440 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4441 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4442 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4443 | |
| 4444 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 4445 | I915_READ(HTOTAL(cpu_transcoder))); |
| 4446 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 4447 | I915_READ(HBLANK(cpu_transcoder))); |
| 4448 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 4449 | I915_READ(HSYNC(cpu_transcoder))); |
| 4450 | |
| 4451 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 4452 | I915_READ(VTOTAL(cpu_transcoder))); |
| 4453 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 4454 | I915_READ(VBLANK(cpu_transcoder))); |
| 4455 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 4456 | I915_READ(VSYNC(cpu_transcoder))); |
| 4457 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 4458 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 4459 | } |
| 4460 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4461 | 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] | 4462 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4463 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4464 | uint32_t temp; |
| 4465 | |
| 4466 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4467 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4468 | return; |
| 4469 | |
| 4470 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 4471 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 4472 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4473 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 4474 | if (enable) |
| 4475 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 4476 | |
| 4477 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4478 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 4479 | POSTING_READ(SOUTH_CHICKEN1); |
| 4480 | } |
| 4481 | |
| 4482 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 4483 | { |
| 4484 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4485 | |
| 4486 | switch (intel_crtc->pipe) { |
| 4487 | case PIPE_A: |
| 4488 | break; |
| 4489 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4490 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4491 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4492 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4493 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4494 | |
| 4495 | break; |
| 4496 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 4497 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4498 | |
| 4499 | break; |
| 4500 | default: |
| 4501 | BUG(); |
| 4502 | } |
| 4503 | } |
| 4504 | |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4505 | /* Return which DP Port should be selected for Transcoder DP control */ |
| 4506 | static enum port |
| 4507 | intel_trans_dp_port_sel(struct drm_crtc *crtc) |
| 4508 | { |
| 4509 | struct drm_device *dev = crtc->dev; |
| 4510 | struct intel_encoder *encoder; |
| 4511 | |
| 4512 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 4513 | if (encoder->type == INTEL_OUTPUT_DP || |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4514 | encoder->type == INTEL_OUTPUT_EDP) |
| 4515 | return enc_to_dig_port(&encoder->base)->port; |
| 4516 | } |
| 4517 | |
| 4518 | return -1; |
| 4519 | } |
| 4520 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4521 | /* |
| 4522 | * Enable PCH resources required for PCH ports: |
| 4523 | * - PCH PLLs |
| 4524 | * - FDI training & RX/TX |
| 4525 | * - update transcoder timings |
| 4526 | * - DP transcoding bits |
| 4527 | * - transcoder |
| 4528 | */ |
| 4529 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4530 | { |
| 4531 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4532 | struct drm_i915_private *dev_priv = to_i915(dev); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4533 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4534 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4535 | u32 temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4536 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4537 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4538 | |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4539 | if (IS_IVYBRIDGE(dev_priv)) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4540 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4541 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4542 | /* Write the TU size bits before fdi link training, so that error |
| 4543 | * detection works. */ |
| 4544 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4545 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4546 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4547 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4548 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4549 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4550 | /* We need to program the right clock selection before writing the pixel |
| 4551 | * mutliplier into the DPLL. */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4552 | if (HAS_PCH_CPT(dev_priv)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4553 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4554 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4555 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4556 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4557 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 4558 | if (intel_crtc->config->shared_dpll == |
| 4559 | 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] | 4560 | temp |= sel; |
| 4561 | else |
| 4562 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4563 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4564 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4565 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4566 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4567 | * transcoder, and we actually should do this to not upset any PCH |
| 4568 | * transcoder that already use the clock when we share it. |
| 4569 | * |
| 4570 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4571 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4572 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4573 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4574 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4575 | /* set transcoder timing, panel must allow it */ |
| 4576 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4577 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4578 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4579 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4580 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4581 | /* For PCH DP, enable TRANS_DP_CTL */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 4582 | if (HAS_PCH_CPT(dev_priv) && |
| 4583 | intel_crtc_has_dp_encoder(intel_crtc->config)) { |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4584 | const struct drm_display_mode *adjusted_mode = |
| 4585 | &intel_crtc->config->base.adjusted_mode; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4586 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4587 | i915_reg_t reg = TRANS_DP_CTL(pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4588 | temp = I915_READ(reg); |
| 4589 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4590 | TRANS_DP_SYNC_MASK | |
| 4591 | TRANS_DP_BPC_MASK); |
Ville Syrjälä | e3ef447 | 2015-05-05 17:17:31 +0300 | [diff] [blame] | 4592 | temp |= TRANS_DP_OUTPUT_ENABLE; |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4593 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4594 | |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4595 | if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4596 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Ville Syrjälä | 9c4edae | 2015-10-29 21:25:51 +0200 | [diff] [blame] | 4597 | if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4598 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4599 | |
| 4600 | switch (intel_trans_dp_port_sel(crtc)) { |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4601 | case PORT_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4602 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4603 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4604 | case PORT_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4605 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4606 | break; |
Ville Syrjälä | c48b530 | 2015-11-04 23:19:56 +0200 | [diff] [blame] | 4607 | case PORT_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4608 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4609 | break; |
| 4610 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4611 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4614 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4615 | } |
| 4616 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4617 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4618 | } |
| 4619 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4620 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4621 | { |
| 4622 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4623 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4624 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4625 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4626 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4627 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4628 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4629 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4630 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4631 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4632 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4633 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4634 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4635 | } |
| 4636 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4637 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4638 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4639 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 4640 | i915_reg_t dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4641 | u32 temp; |
| 4642 | |
| 4643 | temp = I915_READ(dslreg); |
| 4644 | udelay(500); |
| 4645 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4646 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4647 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4648 | } |
| 4649 | } |
| 4650 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4651 | static int |
| 4652 | skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, |
| 4653 | unsigned scaler_user, int *scaler_id, unsigned int rotation, |
| 4654 | int src_w, int src_h, int dst_w, int dst_h) |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4655 | { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4656 | struct intel_crtc_scaler_state *scaler_state = |
| 4657 | &crtc_state->scaler_state; |
| 4658 | struct intel_crtc *intel_crtc = |
| 4659 | to_intel_crtc(crtc_state->base.crtc); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4660 | int need_scaling; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4661 | |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 4662 | need_scaling = drm_rotation_90_or_270(rotation) ? |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 4663 | (src_h != dst_w || src_w != dst_h): |
| 4664 | (src_w != dst_w || src_h != dst_h); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4665 | |
| 4666 | /* |
| 4667 | * if plane is being disabled or scaler is no more required or force detach |
| 4668 | * - free scaler binded to this plane/crtc |
| 4669 | * - in order to do this, update crtc->scaler_usage |
| 4670 | * |
| 4671 | * Here scaler state in crtc_state is set free so that |
| 4672 | * scaler can be assigned to other user. Actual register |
| 4673 | * update to free the scaler is done in plane/panel-fit programming. |
| 4674 | * For this purpose crtc/plane_state->scaler_id isn't reset here. |
| 4675 | */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4676 | if (force_detach || !need_scaling) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4677 | if (*scaler_id >= 0) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4678 | scaler_state->scaler_users &= ~(1 << scaler_user); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4679 | scaler_state->scalers[*scaler_id].in_use = 0; |
| 4680 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4681 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4682 | "Staged freeing scaler id %d scaler_users = 0x%x\n", |
| 4683 | intel_crtc->pipe, scaler_user, *scaler_id, |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4684 | scaler_state->scaler_users); |
| 4685 | *scaler_id = -1; |
| 4686 | } |
| 4687 | return 0; |
| 4688 | } |
| 4689 | |
| 4690 | /* range checks */ |
| 4691 | if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H || |
| 4692 | dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H || |
| 4693 | |
| 4694 | src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H || |
| 4695 | dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H) { |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4696 | 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] | 4697 | "size is out of scaler range\n", |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4698 | 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] | 4699 | return -EINVAL; |
| 4700 | } |
| 4701 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4702 | /* mark this plane as a scaler user in crtc_state */ |
| 4703 | scaler_state->scaler_users |= (1 << scaler_user); |
| 4704 | DRM_DEBUG_KMS("scaler_user index %u.%u: " |
| 4705 | "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n", |
| 4706 | intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h, |
| 4707 | scaler_state->scaler_users); |
| 4708 | |
| 4709 | return 0; |
| 4710 | } |
| 4711 | |
| 4712 | /** |
| 4713 | * skl_update_scaler_crtc - Stages update to scaler state for a given crtc. |
| 4714 | * |
| 4715 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4716 | * |
| 4717 | * Return |
| 4718 | * 0 - scaler_usage updated successfully |
| 4719 | * error - requested scaling cannot be supported or other error condition |
| 4720 | */ |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4721 | int skl_update_scaler_crtc(struct intel_crtc_state *state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4722 | { |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 4723 | const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4724 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4725 | return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX, |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 4726 | &state->scaler_state.scaler_id, DRM_ROTATE_0, |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4727 | state->pipe_src_w, state->pipe_src_h, |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 4728 | adjusted_mode->crtc_hdisplay, adjusted_mode->crtc_vdisplay); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | /** |
| 4732 | * skl_update_scaler_plane - Stages update to scaler state for a given plane. |
| 4733 | * |
| 4734 | * @state: crtc's scaler state |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4735 | * @plane_state: atomic plane state to update |
| 4736 | * |
| 4737 | * Return |
| 4738 | * 0 - scaler_usage updated successfully |
| 4739 | * error - requested scaling cannot be supported or other error condition |
| 4740 | */ |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4741 | static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state, |
| 4742 | struct intel_plane_state *plane_state) |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4743 | { |
| 4744 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 4745 | struct intel_plane *intel_plane = |
| 4746 | to_intel_plane(plane_state->base.plane); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4747 | struct drm_framebuffer *fb = plane_state->base.fb; |
| 4748 | int ret; |
| 4749 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4750 | bool force_detach = !fb || !plane_state->base.visible; |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4751 | |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4752 | ret = skl_update_scaler(crtc_state, force_detach, |
| 4753 | drm_plane_index(&intel_plane->base), |
| 4754 | &plane_state->scaler_id, |
| 4755 | plane_state->base.rotation, |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 4756 | drm_rect_width(&plane_state->base.src) >> 16, |
| 4757 | drm_rect_height(&plane_state->base.src) >> 16, |
| 4758 | drm_rect_width(&plane_state->base.dst), |
| 4759 | drm_rect_height(&plane_state->base.dst)); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4760 | |
| 4761 | if (ret || plane_state->scaler_id < 0) |
| 4762 | return ret; |
| 4763 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4764 | /* check colorkey */ |
Maarten Lankhorst | 818ed96 | 2015-06-15 12:33:54 +0200 | [diff] [blame] | 4765 | if (plane_state->ckey.flags != I915_SET_COLORKEY_NONE) { |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4766 | DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed", |
| 4767 | intel_plane->base.base.id, |
| 4768 | intel_plane->base.name); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4769 | return -EINVAL; |
| 4770 | } |
| 4771 | |
| 4772 | /* Check src format */ |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4773 | switch (fb->pixel_format) { |
| 4774 | case DRM_FORMAT_RGB565: |
| 4775 | case DRM_FORMAT_XBGR8888: |
| 4776 | case DRM_FORMAT_XRGB8888: |
| 4777 | case DRM_FORMAT_ABGR8888: |
| 4778 | case DRM_FORMAT_ARGB8888: |
| 4779 | case DRM_FORMAT_XRGB2101010: |
| 4780 | case DRM_FORMAT_XBGR2101010: |
| 4781 | case DRM_FORMAT_YUYV: |
| 4782 | case DRM_FORMAT_YVYU: |
| 4783 | case DRM_FORMAT_UYVY: |
| 4784 | case DRM_FORMAT_VYUY: |
| 4785 | break; |
| 4786 | default: |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 4787 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n", |
| 4788 | intel_plane->base.base.id, intel_plane->base.name, |
| 4789 | fb->base.id, fb->pixel_format); |
Maarten Lankhorst | 86adf9d | 2015-06-22 09:50:32 +0200 | [diff] [blame] | 4790 | return -EINVAL; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4791 | } |
| 4792 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4793 | return 0; |
| 4794 | } |
| 4795 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 4796 | static void skylake_scaler_disable(struct intel_crtc *crtc) |
| 4797 | { |
| 4798 | int i; |
| 4799 | |
| 4800 | for (i = 0; i < crtc->num_scalers; i++) |
| 4801 | skl_detach_scaler(crtc, i); |
| 4802 | } |
| 4803 | |
| 4804 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4805 | { |
| 4806 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4807 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4808 | int pipe = crtc->pipe; |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4809 | struct intel_crtc_scaler_state *scaler_state = |
| 4810 | &crtc->config->scaler_state; |
| 4811 | |
| 4812 | DRM_DEBUG_KMS("for crtc_state = %p\n", crtc->config); |
| 4813 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4814 | if (crtc->config->pch_pfit.enabled) { |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 4815 | int id; |
| 4816 | |
| 4817 | if (WARN_ON(crtc->config->scaler_state.scaler_id < 0)) { |
| 4818 | DRM_ERROR("Requesting pfit without getting a scaler first\n"); |
| 4819 | return; |
| 4820 | } |
| 4821 | |
| 4822 | id = scaler_state->scaler_id; |
| 4823 | I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN | |
| 4824 | PS_FILTER_MEDIUM | scaler_state->scalers[id].mode); |
| 4825 | I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc->config->pch_pfit.pos); |
| 4826 | I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc->config->pch_pfit.size); |
| 4827 | |
| 4828 | 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] | 4829 | } |
| 4830 | } |
| 4831 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4832 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4833 | { |
| 4834 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4835 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4836 | int pipe = crtc->pipe; |
| 4837 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4838 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4839 | /* Force use of hard-coded filter coefficients |
| 4840 | * as some pre-programmed values are broken, |
| 4841 | * e.g. x201. |
| 4842 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 4843 | if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4844 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4845 | PF_PIPE_SEL_IVB(pipe)); |
| 4846 | else |
| 4847 | 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] | 4848 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4849 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4850 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4851 | } |
| 4852 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4853 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4854 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4855 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4856 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4857 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4858 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4859 | return; |
| 4860 | |
Maarten Lankhorst | 307e449 | 2016-03-23 14:33:28 +0100 | [diff] [blame] | 4861 | /* |
| 4862 | * We can only enable IPS after we enable a plane and wait for a vblank |
| 4863 | * This function is called from post_plane_update, which is run after |
| 4864 | * a vblank wait. |
| 4865 | */ |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4866 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4867 | assert_plane_enabled(dev_priv, crtc->plane); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 4868 | if (IS_BROADWELL(dev_priv)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4869 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4870 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4871 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4872 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4873 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4874 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4875 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4876 | */ |
| 4877 | } else { |
| 4878 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4879 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4880 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4881 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4882 | * the HW state readout code will complain that the expected |
| 4883 | * IPS_CTL value is not the one we read. */ |
Chris Wilson | 2ec9ba3 | 2016-06-30 15:33:01 +0100 | [diff] [blame] | 4884 | if (intel_wait_for_register(dev_priv, |
| 4885 | IPS_CTL, IPS_ENABLE, IPS_ENABLE, |
| 4886 | 50)) |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4887 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4888 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4889 | } |
| 4890 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4891 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4892 | { |
| 4893 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4894 | struct drm_i915_private *dev_priv = to_i915(dev); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4895 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4896 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4897 | return; |
| 4898 | |
| 4899 | assert_plane_enabled(dev_priv, crtc->plane); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 4900 | if (IS_BROADWELL(dev_priv)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4901 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4902 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4903 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4904 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
Chris Wilson | b85c1ec | 2016-06-30 15:33:02 +0100 | [diff] [blame] | 4905 | if (intel_wait_for_register(dev_priv, |
| 4906 | IPS_CTL, IPS_ENABLE, 0, |
| 4907 | 42)) |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4908 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4909 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4910 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4911 | POSTING_READ(IPS_CTL); |
| 4912 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4913 | |
| 4914 | /* We need to wait for a vblank before we can disable the plane. */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 4915 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4916 | } |
| 4917 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4918 | 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] | 4919 | { |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 4920 | if (intel_crtc->overlay) { |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4921 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4922 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4923 | |
| 4924 | mutex_lock(&dev->struct_mutex); |
| 4925 | dev_priv->mm.interruptible = false; |
| 4926 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4927 | dev_priv->mm.interruptible = true; |
| 4928 | mutex_unlock(&dev->struct_mutex); |
| 4929 | } |
| 4930 | |
| 4931 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4932 | * has to recompute where to put it anyway. |
| 4933 | */ |
| 4934 | } |
| 4935 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4936 | /** |
| 4937 | * intel_post_enable_primary - Perform operations after enabling primary plane |
| 4938 | * @crtc: the CRTC whose primary plane was just enabled |
| 4939 | * |
| 4940 | * Performs potentially sleeping operations that must be done after the primary |
| 4941 | * plane is enabled, such as updating FBC and IPS. Note that this may be |
| 4942 | * called due to an explicit primary plane update, or due to an implicit |
| 4943 | * re-enable that is caused when a sprite plane is updated to no longer |
| 4944 | * completely hide the primary plane. |
| 4945 | */ |
| 4946 | static void |
| 4947 | intel_post_enable_primary(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4948 | { |
| 4949 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4950 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4951 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4952 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4953 | |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4954 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4955 | * FIXME IPS should be fine as long as one plane is |
| 4956 | * enabled, but in practice it seems to have problems |
| 4957 | * when going from primary only to sprite only and vice |
| 4958 | * versa. |
| 4959 | */ |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4960 | hsw_enable_ips(intel_crtc); |
| 4961 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4962 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4963 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4964 | * So don't enable underrun reporting before at least some planes |
| 4965 | * are enabled. |
| 4966 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4967 | * but leave the pipe running. |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4968 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4969 | if (IS_GEN2(dev_priv)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4970 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4971 | |
Ville Syrjälä | aca7b68 | 2015-10-30 19:22:21 +0200 | [diff] [blame] | 4972 | /* Underruns don't always raise interrupts, so check manually. */ |
| 4973 | intel_check_cpu_fifo_underruns(dev_priv); |
| 4974 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4975 | } |
| 4976 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4977 | /* FIXME move all this to pre_plane_update() with proper state tracking */ |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4978 | static void |
| 4979 | intel_pre_disable_primary(struct drm_crtc *crtc) |
| 4980 | { |
| 4981 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 4982 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4983 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4984 | int pipe = intel_crtc->pipe; |
| 4985 | |
| 4986 | /* |
| 4987 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4988 | * So diasble underrun reporting before all the planes get disabled. |
| 4989 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4990 | * but leave the pipe running. |
| 4991 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 4992 | if (IS_GEN2(dev_priv)) |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 4993 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 4994 | |
| 4995 | /* |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 4996 | * FIXME IPS should be fine as long as one plane is |
| 4997 | * enabled, but in practice it seems to have problems |
| 4998 | * when going from primary only to sprite only and vice |
| 4999 | * versa. |
| 5000 | */ |
| 5001 | hsw_disable_ips(intel_crtc); |
| 5002 | } |
| 5003 | |
| 5004 | /* FIXME get rid of this and use pre_plane_update */ |
| 5005 | static void |
| 5006 | intel_pre_disable_primary_noatomic(struct drm_crtc *crtc) |
| 5007 | { |
| 5008 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5009 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5010 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5011 | int pipe = intel_crtc->pipe; |
| 5012 | |
| 5013 | intel_pre_disable_primary(crtc); |
| 5014 | |
| 5015 | /* |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5016 | * Vblank time updates from the shadow to live plane control register |
| 5017 | * are blocked if the memory self-refresh mode is active at that |
| 5018 | * moment. So to make sure the plane gets truly disabled, disable |
| 5019 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5020 | * will be checked/applied by the HW only at the next frame start |
| 5021 | * event which is after the vblank start event, so we need to have a |
| 5022 | * wait-for-vblank between disabling the plane and the pipe. |
| 5023 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5024 | if (HAS_GMCH_DISPLAY(dev_priv) && |
| 5025 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5026 | intel_wait_for_vblank(dev_priv, pipe); |
Maarten Lankhorst | 87d4300 | 2015-04-21 17:12:54 +0300 | [diff] [blame] | 5027 | } |
| 5028 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5029 | static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state) |
| 5030 | { |
| 5031 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
| 5032 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5033 | struct intel_crtc_state *pipe_config = |
| 5034 | to_intel_crtc_state(crtc->base.state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5035 | struct drm_plane *primary = crtc->base.primary; |
| 5036 | struct drm_plane_state *old_pri_state = |
| 5037 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 5038 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5039 | intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5040 | |
| 5041 | crtc->wm.cxsr_allowed = true; |
| 5042 | |
| 5043 | if (pipe_config->update_wm_post && pipe_config->base.active) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5044 | intel_update_watermarks(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5045 | |
| 5046 | if (old_pri_state) { |
| 5047 | struct intel_plane_state *primary_state = |
| 5048 | to_intel_plane_state(primary->state); |
| 5049 | struct intel_plane_state *old_primary_state = |
| 5050 | to_intel_plane_state(old_pri_state); |
| 5051 | |
| 5052 | intel_fbc_post_update(crtc); |
| 5053 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5054 | if (primary_state->base.visible && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5055 | (needs_modeset(&pipe_config->base) || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5056 | !old_primary_state->base.visible)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5057 | intel_post_enable_primary(&crtc->base); |
| 5058 | } |
| 5059 | } |
| 5060 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5061 | 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] | 5062 | { |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5063 | struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5064 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5065 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 5066 | struct intel_crtc_state *pipe_config = |
| 5067 | to_intel_crtc_state(crtc->base.state); |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5068 | struct drm_atomic_state *old_state = old_crtc_state->base.state; |
| 5069 | struct drm_plane *primary = crtc->base.primary; |
| 5070 | struct drm_plane_state *old_pri_state = |
| 5071 | drm_atomic_get_existing_plane_state(old_state, primary); |
| 5072 | bool modeset = needs_modeset(&pipe_config->base); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5073 | struct intel_atomic_state *old_intel_state = |
| 5074 | to_intel_atomic_state(old_state); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5075 | |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5076 | if (old_pri_state) { |
| 5077 | struct intel_plane_state *primary_state = |
| 5078 | to_intel_plane_state(primary->state); |
| 5079 | struct intel_plane_state *old_primary_state = |
| 5080 | to_intel_plane_state(old_pri_state); |
| 5081 | |
Maarten Lankhorst | faf68d9 | 2016-06-14 14:24:20 +0200 | [diff] [blame] | 5082 | intel_fbc_pre_update(crtc, pipe_config, primary_state); |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 5083 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 5084 | if (old_primary_state->base.visible && |
| 5085 | (modeset || !primary_state->base.visible)) |
Maarten Lankhorst | 5c74cd7 | 2016-02-03 16:53:24 +0100 | [diff] [blame] | 5086 | intel_pre_disable_primary(&crtc->base); |
| 5087 | } |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5088 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 5089 | if (pipe_config->disable_cxsr && HAS_GMCH_DISPLAY(dev_priv)) { |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5090 | crtc->wm.cxsr_allowed = false; |
Maarten Lankhorst | 2dfd178 | 2016-02-03 16:53:25 +0100 | [diff] [blame] | 5091 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 5092 | /* |
| 5093 | * Vblank time updates from the shadow to live plane control register |
| 5094 | * are blocked if the memory self-refresh mode is active at that |
| 5095 | * moment. So to make sure the plane gets truly disabled, disable |
| 5096 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5097 | * will be checked/applied by the HW only at the next frame start |
| 5098 | * event which is after the vblank start event, so we need to have a |
| 5099 | * wait-for-vblank between disabling the plane and the pipe. |
| 5100 | */ |
Ville Syrjälä | 11a85d6 | 2016-11-28 19:37:12 +0200 | [diff] [blame] | 5101 | if (old_crtc_state->base.active && |
| 5102 | intel_set_memory_cxsr(dev_priv, false)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5103 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 5104 | } |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 5105 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5106 | /* |
| 5107 | * IVB workaround: must disable low power watermarks for at least |
| 5108 | * one frame before enabling scaling. LP watermarks can be re-enabled |
| 5109 | * when scaling is disabled. |
| 5110 | * |
| 5111 | * WaCxSRDisabledForSpriteScaling:ivb |
| 5112 | */ |
Ville Syrjälä | ddd2b79 | 2016-11-28 19:37:04 +0200 | [diff] [blame] | 5113 | if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5114 | intel_wait_for_vblank(dev_priv, crtc->pipe); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 5115 | |
| 5116 | /* |
| 5117 | * If we're doing a modeset, we're done. No need to do any pre-vblank |
| 5118 | * watermark programming here. |
| 5119 | */ |
| 5120 | if (needs_modeset(&pipe_config->base)) |
| 5121 | return; |
| 5122 | |
| 5123 | /* |
| 5124 | * For platforms that support atomic watermarks, program the |
| 5125 | * 'intermediate' watermarks immediately. On pre-gen9 platforms, these |
| 5126 | * will be the intermediate values that are safe for both pre- and |
| 5127 | * post- vblank; when vblank happens, the 'active' values will be set |
| 5128 | * to the final 'target' values and we'll do this again to get the |
| 5129 | * optimal watermarks. For gen9+ platforms, the values we program here |
| 5130 | * will be the final target values which will get automatically latched |
| 5131 | * at vblank time; no further programming will be necessary. |
| 5132 | * |
| 5133 | * If a platform hasn't been transitioned to atomic watermarks yet, |
| 5134 | * we'll continue to update watermarks the old way, if flags tell |
| 5135 | * us to. |
| 5136 | */ |
| 5137 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5138 | dev_priv->display.initial_watermarks(old_intel_state, |
| 5139 | pipe_config); |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 5140 | else if (pipe_config->update_wm_pre) |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 5141 | intel_update_watermarks(crtc); |
Maarten Lankhorst | ac21b22 | 2015-06-15 12:33:49 +0200 | [diff] [blame] | 5142 | } |
| 5143 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5144 | 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] | 5145 | { |
| 5146 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5147 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5148 | struct drm_plane *p; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5149 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5150 | |
Maarten Lankhorst | 7cac945 | 2015-04-21 17:12:55 +0300 | [diff] [blame] | 5151 | intel_crtc_dpms_overlay_disable(intel_crtc); |
Maarten Lankhorst | 27321ae | 2015-04-21 17:12:52 +0300 | [diff] [blame] | 5152 | |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 5153 | drm_for_each_plane_mask(p, dev, plane_mask) |
| 5154 | to_intel_plane(p)->disable_plane(p, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 5155 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 5156 | /* |
| 5157 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 5158 | * to compute the mask of flip planes precisely. For the time being |
| 5159 | * consider this a flip to a NULL plane. |
| 5160 | */ |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 5161 | intel_frontbuffer_flip(to_i915(dev), INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 5162 | } |
| 5163 | |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5164 | static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5165 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5166 | struct drm_atomic_state *old_state) |
| 5167 | { |
| 5168 | struct drm_connector_state *old_conn_state; |
| 5169 | struct drm_connector *conn; |
| 5170 | int i; |
| 5171 | |
| 5172 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5173 | struct drm_connector_state *conn_state = conn->state; |
| 5174 | struct intel_encoder *encoder = |
| 5175 | to_intel_encoder(conn_state->best_encoder); |
| 5176 | |
| 5177 | if (conn_state->crtc != crtc) |
| 5178 | continue; |
| 5179 | |
| 5180 | if (encoder->pre_pll_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5181 | encoder->pre_pll_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5182 | } |
| 5183 | } |
| 5184 | |
| 5185 | static void intel_encoders_pre_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5186 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5187 | struct drm_atomic_state *old_state) |
| 5188 | { |
| 5189 | struct drm_connector_state *old_conn_state; |
| 5190 | struct drm_connector *conn; |
| 5191 | int i; |
| 5192 | |
| 5193 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5194 | struct drm_connector_state *conn_state = conn->state; |
| 5195 | struct intel_encoder *encoder = |
| 5196 | to_intel_encoder(conn_state->best_encoder); |
| 5197 | |
| 5198 | if (conn_state->crtc != crtc) |
| 5199 | continue; |
| 5200 | |
| 5201 | if (encoder->pre_enable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5202 | encoder->pre_enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5203 | } |
| 5204 | } |
| 5205 | |
| 5206 | static void intel_encoders_enable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5207 | struct intel_crtc_state *crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5208 | struct drm_atomic_state *old_state) |
| 5209 | { |
| 5210 | struct drm_connector_state *old_conn_state; |
| 5211 | struct drm_connector *conn; |
| 5212 | int i; |
| 5213 | |
| 5214 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5215 | struct drm_connector_state *conn_state = conn->state; |
| 5216 | struct intel_encoder *encoder = |
| 5217 | to_intel_encoder(conn_state->best_encoder); |
| 5218 | |
| 5219 | if (conn_state->crtc != crtc) |
| 5220 | continue; |
| 5221 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5222 | encoder->enable(encoder, crtc_state, conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5223 | intel_opregion_notify_encoder(encoder, true); |
| 5224 | } |
| 5225 | } |
| 5226 | |
| 5227 | static void intel_encoders_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5228 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5229 | struct drm_atomic_state *old_state) |
| 5230 | { |
| 5231 | struct drm_connector_state *old_conn_state; |
| 5232 | struct drm_connector *conn; |
| 5233 | int i; |
| 5234 | |
| 5235 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5236 | struct intel_encoder *encoder = |
| 5237 | to_intel_encoder(old_conn_state->best_encoder); |
| 5238 | |
| 5239 | if (old_conn_state->crtc != crtc) |
| 5240 | continue; |
| 5241 | |
| 5242 | intel_opregion_notify_encoder(encoder, false); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5243 | encoder->disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | static void intel_encoders_post_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5248 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5249 | struct drm_atomic_state *old_state) |
| 5250 | { |
| 5251 | struct drm_connector_state *old_conn_state; |
| 5252 | struct drm_connector *conn; |
| 5253 | int i; |
| 5254 | |
| 5255 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5256 | struct intel_encoder *encoder = |
| 5257 | to_intel_encoder(old_conn_state->best_encoder); |
| 5258 | |
| 5259 | if (old_conn_state->crtc != crtc) |
| 5260 | continue; |
| 5261 | |
| 5262 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5263 | encoder->post_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | static void intel_encoders_post_pll_disable(struct drm_crtc *crtc, |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5268 | struct intel_crtc_state *old_crtc_state, |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5269 | struct drm_atomic_state *old_state) |
| 5270 | { |
| 5271 | struct drm_connector_state *old_conn_state; |
| 5272 | struct drm_connector *conn; |
| 5273 | int i; |
| 5274 | |
| 5275 | for_each_connector_in_state(old_state, conn, old_conn_state, i) { |
| 5276 | struct intel_encoder *encoder = |
| 5277 | to_intel_encoder(old_conn_state->best_encoder); |
| 5278 | |
| 5279 | if (old_conn_state->crtc != crtc) |
| 5280 | continue; |
| 5281 | |
| 5282 | if (encoder->post_pll_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5283 | encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state); |
Maarten Lankhorst | fb1c98b | 2016-08-09 17:04:03 +0200 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5287 | static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5288 | struct drm_atomic_state *old_state) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5289 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5290 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5291 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5292 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5293 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5294 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5295 | struct intel_atomic_state *old_intel_state = |
| 5296 | to_intel_atomic_state(old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5297 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5298 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5299 | return; |
| 5300 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5301 | /* |
| 5302 | * Sometimes spurious CPU pipe underruns happen during FDI |
| 5303 | * training, at least with VGA+HDMI cloning. Suppress them. |
| 5304 | * |
| 5305 | * On ILK we get an occasional spurious CPU pipe underruns |
| 5306 | * between eDP port A enable and vdd enable. Also PCH port |
| 5307 | * enable seems to result in the occasional CPU pipe underrun. |
| 5308 | * |
| 5309 | * Spurious PCH underruns also occur during PCH enabling. |
| 5310 | */ |
| 5311 | if (intel_crtc->config->has_pch_encoder || IS_GEN5(dev_priv)) |
| 5312 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5313 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5314 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5315 | |
| 5316 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 5317 | intel_prepare_shared_dpll(intel_crtc); |
| 5318 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5319 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5320 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5321 | |
| 5322 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5323 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5324 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5325 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5326 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5327 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 5328 | } |
| 5329 | |
| 5330 | ironlake_set_pipeconf(crtc); |
| 5331 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5332 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5333 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5334 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5335 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5336 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 5337 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 5338 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 5339 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 5340 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 5341 | } else { |
| 5342 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 5343 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 5344 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5345 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5346 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5347 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5348 | /* |
| 5349 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5350 | * clocks enabled |
| 5351 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5352 | intel_color_load_luts(&pipe_config->base); |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 5353 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5354 | if (dev_priv->display.initial_watermarks != NULL) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5355 | dev_priv->display.initial_watermarks(old_intel_state, intel_crtc->config); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5356 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5357 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5358 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 5359 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5360 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5361 | assert_vblank_disabled(crtc); |
| 5362 | drm_crtc_vblank_on(crtc); |
| 5363 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5364 | intel_encoders_enable(crtc, pipe_config, old_state); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 5365 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5366 | if (HAS_PCH_CPT(dev_priv)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 5367 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5368 | |
| 5369 | /* Must wait for vblank to avoid spurious PCH FIFO underruns */ |
| 5370 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5371 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5372 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5373 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5376 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 5377 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 5378 | { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5379 | return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5380 | } |
| 5381 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5382 | static void haswell_crtc_enable(struct intel_crtc_state *pipe_config, |
| 5383 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5384 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5385 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5386 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5387 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5388 | int pipe = intel_crtc->pipe, hsw_workaround_pipe; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5389 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 5390 | struct intel_atomic_state *old_intel_state = |
| 5391 | to_intel_atomic_state(old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5392 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 5393 | if (WARN_ON(intel_crtc->active)) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5394 | return; |
| 5395 | |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5396 | if (intel_crtc->config->has_pch_encoder) |
| 5397 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5398 | false); |
| 5399 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5400 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 5401 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 5402 | if (intel_crtc->config->shared_dpll) |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 5403 | intel_enable_shared_dpll(intel_crtc); |
| 5404 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 5405 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5406 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5407 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5408 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5409 | intel_set_pipe_timings(intel_crtc); |
| 5410 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 5411 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5412 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5413 | if (cpu_transcoder != TRANSCODER_EDP && |
| 5414 | !transcoder_is_dsi(cpu_transcoder)) { |
| 5415 | I915_WRITE(PIPE_MULT(cpu_transcoder), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5416 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 5417 | } |
| 5418 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5419 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5420 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5421 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5422 | } |
| 5423 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5424 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5425 | haswell_set_pipeconf(crtc); |
| 5426 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 5427 | haswell_set_pipemisc(crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5428 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5429 | intel_color_set_csc(&pipe_config->base); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 5430 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5431 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 5432 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 5433 | if (intel_crtc->config->has_pch_encoder) |
| 5434 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
| 5435 | else |
| 5436 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 5437 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5438 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5439 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5440 | if (intel_crtc->config->has_pch_encoder) |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 5441 | dev_priv->display.fdi_link_train(crtc); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 5442 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5443 | if (!transcoder_is_dsi(cpu_transcoder)) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5444 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5445 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5446 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5447 | skylake_pfit_enable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5448 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 5449 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5450 | |
| 5451 | /* |
| 5452 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 5453 | * clocks enabled |
| 5454 | */ |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 5455 | intel_color_load_luts(&pipe_config->base); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5456 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 5457 | intel_ddi_set_pipe_settings(crtc); |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5458 | if (!transcoder_is_dsi(cpu_transcoder)) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5459 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5460 | |
Imre Deak | 1d5bf5d | 2016-02-29 22:10:33 +0200 | [diff] [blame] | 5461 | if (dev_priv->display.initial_watermarks != NULL) |
Ville Syrjälä | 3125d39 | 2016-11-28 19:37:03 +0200 | [diff] [blame] | 5462 | dev_priv->display.initial_watermarks(old_intel_state, pipe_config); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5463 | |
| 5464 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5465 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5466 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5467 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5468 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 5469 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5470 | |
Ville Syrjälä | 0037071 | 2016-11-14 19:44:06 +0200 | [diff] [blame] | 5471 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5472 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 5473 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5474 | assert_vblank_disabled(crtc); |
| 5475 | drm_crtc_vblank_on(crtc); |
| 5476 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5477 | intel_encoders_enable(crtc, pipe_config, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5478 | |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 5479 | if (intel_crtc->config->has_pch_encoder) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5480 | intel_wait_for_vblank(dev_priv, pipe); |
| 5481 | intel_wait_for_vblank(dev_priv, pipe); |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 5482 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5483 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5484 | true); |
Daniel Vetter | 6b69851 | 2015-11-28 11:05:39 +0100 | [diff] [blame] | 5485 | } |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5486 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 5487 | /* If we change the relative order between pipe/planes enabling, we need |
| 5488 | * to change the workaround. */ |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5489 | hsw_workaround_pipe = pipe_config->hsw_workaround_pipe; |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 5490 | if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 5491 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
| 5492 | intel_wait_for_vblank(dev_priv, hsw_workaround_pipe); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 5493 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5494 | } |
| 5495 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5496 | static void ironlake_pfit_disable(struct intel_crtc *crtc, bool force) |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5497 | { |
| 5498 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5499 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5500 | int pipe = crtc->pipe; |
| 5501 | |
| 5502 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 5503 | * 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] | 5504 | if (force || crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 5505 | I915_WRITE(PF_CTL(pipe), 0); |
| 5506 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 5507 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 5508 | } |
| 5509 | } |
| 5510 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5511 | static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5512 | struct drm_atomic_state *old_state) |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5513 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5514 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5515 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5516 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5517 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5518 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5519 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5520 | /* |
| 5521 | * Sometimes spurious CPU pipe underruns happen when the |
| 5522 | * pipe is already disabled, but FDI RX/TX is still enabled. |
| 5523 | * Happens at least with VGA+HDMI cloning. Suppress them. |
| 5524 | */ |
| 5525 | if (intel_crtc->config->has_pch_encoder) { |
| 5526 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5527 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5528 | } |
Ville Syrjälä | 37ca8d4 | 2015-10-30 19:20:27 +0200 | [diff] [blame] | 5529 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5530 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 5531 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5532 | drm_crtc_vblank_off(crtc); |
| 5533 | assert_vblank_disabled(crtc); |
| 5534 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5535 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5536 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5537 | ironlake_pfit_disable(intel_crtc, false); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5538 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5539 | if (intel_crtc->config->has_pch_encoder) |
Ville Syrjälä | 5a74f70 | 2015-05-05 17:17:38 +0300 | [diff] [blame] | 5540 | ironlake_fdi_disable(crtc); |
| 5541 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5542 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5543 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5544 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5545 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5546 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 5547 | if (HAS_PCH_CPT(dev_priv)) { |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 5548 | i915_reg_t reg; |
| 5549 | u32 temp; |
| 5550 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5551 | /* disable TRANS_DP_CTL */ |
| 5552 | reg = TRANS_DP_CTL(pipe); |
| 5553 | temp = I915_READ(reg); |
| 5554 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 5555 | TRANS_DP_PORT_SEL_MASK); |
| 5556 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 5557 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5558 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5559 | /* disable DPLL_SEL */ |
| 5560 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 5561 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5562 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5563 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5564 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 5565 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5566 | } |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5567 | |
Ville Syrjälä | b2c0593 | 2016-04-01 21:53:17 +0300 | [diff] [blame] | 5568 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5569 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 5570 | } |
| 5571 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5572 | static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 5573 | struct drm_atomic_state *old_state) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5574 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 5575 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5576 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5577 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5578 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5579 | |
Ville Syrjälä | d2d6540 | 2015-10-29 21:25:53 +0200 | [diff] [blame] | 5580 | if (intel_crtc->config->has_pch_encoder) |
| 5581 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5582 | false); |
| 5583 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5584 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5585 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5586 | drm_crtc_vblank_off(crtc); |
| 5587 | assert_vblank_disabled(crtc); |
| 5588 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5589 | /* XXX: Do the pipe assertions at the right place for BXT DSI. */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5590 | if (!transcoder_is_dsi(cpu_transcoder)) |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 5591 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5592 | |
Ville Syrjälä | 0037071 | 2016-11-14 19:44:06 +0200 | [diff] [blame] | 5593 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DP_MST)) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 5594 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 5595 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5596 | if (!transcoder_is_dsi(cpu_transcoder)) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5597 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5598 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 5599 | if (INTEL_GEN(dev_priv) >= 9) |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 5600 | skylake_scaler_disable(intel_crtc); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 5601 | else |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 5602 | ironlake_pfit_disable(intel_crtc, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5603 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 5604 | if (!transcoder_is_dsi(cpu_transcoder)) |
Shashank Sharma | 7d4aefd | 2015-10-01 22:23:49 +0530 | [diff] [blame] | 5605 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5606 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 5607 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5608 | |
Maarten Lankhorst | b707654 | 2016-08-23 16:18:08 +0200 | [diff] [blame] | 5609 | if (old_crtc_state->has_pch_encoder) |
Ville Syrjälä | 81b088c | 2015-10-30 19:21:31 +0200 | [diff] [blame] | 5610 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 5611 | true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 5612 | } |
| 5613 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5614 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 5615 | { |
| 5616 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5617 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5618 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5619 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 5620 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5621 | return; |
| 5622 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 5623 | /* |
| 5624 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 5625 | * according to register description and PRM. |
| 5626 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5627 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 5628 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5629 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 5630 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 5631 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 5632 | |
| 5633 | /* Border color in case we don't scale up to the full screen. Black by |
| 5634 | * default, change to something else for debugging. */ |
| 5635 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5636 | } |
| 5637 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5638 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 5639 | { |
| 5640 | switch (port) { |
| 5641 | case PORT_A: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5642 | return POWER_DOMAIN_PORT_DDI_A_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5643 | case PORT_B: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5644 | return POWER_DOMAIN_PORT_DDI_B_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5645 | case PORT_C: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5646 | return POWER_DOMAIN_PORT_DDI_C_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5647 | case PORT_D: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5648 | return POWER_DOMAIN_PORT_DDI_D_LANES; |
Xiong Zhang | d8e19f9 | 2015-08-13 18:00:12 +0800 | [diff] [blame] | 5649 | case PORT_E: |
Patrik Jakobsson | 6331a70 | 2015-11-09 16:48:21 +0100 | [diff] [blame] | 5650 | return POWER_DOMAIN_PORT_DDI_E_LANES; |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5651 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5652 | MISSING_CASE(port); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5653 | return POWER_DOMAIN_PORT_OTHER; |
| 5654 | } |
| 5655 | } |
| 5656 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5657 | static enum intel_display_power_domain port_to_aux_power_domain(enum port port) |
| 5658 | { |
| 5659 | switch (port) { |
| 5660 | case PORT_A: |
| 5661 | return POWER_DOMAIN_AUX_A; |
| 5662 | case PORT_B: |
| 5663 | return POWER_DOMAIN_AUX_B; |
| 5664 | case PORT_C: |
| 5665 | return POWER_DOMAIN_AUX_C; |
| 5666 | case PORT_D: |
| 5667 | return POWER_DOMAIN_AUX_D; |
| 5668 | case PORT_E: |
| 5669 | /* FIXME: Check VBT for actual wiring of PORT E */ |
| 5670 | return POWER_DOMAIN_AUX_D; |
| 5671 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5672 | MISSING_CASE(port); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5673 | return POWER_DOMAIN_AUX_A; |
| 5674 | } |
| 5675 | } |
| 5676 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5677 | enum intel_display_power_domain |
| 5678 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5679 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5680 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5681 | struct intel_digital_port *intel_dig_port; |
| 5682 | |
| 5683 | switch (intel_encoder->type) { |
| 5684 | case INTEL_OUTPUT_UNKNOWN: |
| 5685 | /* Only DDI platforms should ever use this output type */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5686 | WARN_ON_ONCE(!HAS_DDI(dev_priv)); |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5687 | case INTEL_OUTPUT_DP: |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5688 | case INTEL_OUTPUT_HDMI: |
| 5689 | case INTEL_OUTPUT_EDP: |
| 5690 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 5691 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5692 | case INTEL_OUTPUT_DP_MST: |
| 5693 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5694 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5695 | case INTEL_OUTPUT_ANALOG: |
| 5696 | return POWER_DOMAIN_PORT_CRT; |
| 5697 | case INTEL_OUTPUT_DSI: |
| 5698 | return POWER_DOMAIN_PORT_DSI; |
| 5699 | default: |
| 5700 | return POWER_DOMAIN_PORT_OTHER; |
| 5701 | } |
| 5702 | } |
| 5703 | |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5704 | enum intel_display_power_domain |
| 5705 | intel_display_port_aux_power_domain(struct intel_encoder *intel_encoder) |
| 5706 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5707 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5708 | struct intel_digital_port *intel_dig_port; |
| 5709 | |
| 5710 | switch (intel_encoder->type) { |
| 5711 | case INTEL_OUTPUT_UNKNOWN: |
Imre Deak | 651174a | 2015-11-18 15:57:24 +0200 | [diff] [blame] | 5712 | case INTEL_OUTPUT_HDMI: |
| 5713 | /* |
| 5714 | * Only DDI platforms should ever use these output types. |
| 5715 | * We can get here after the HDMI detect code has already set |
| 5716 | * the type of the shared encoder. Since we can't be sure |
| 5717 | * what's the status of the given connectors, play safe and |
| 5718 | * run the DP detection too. |
| 5719 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 5720 | WARN_ON_ONCE(!HAS_DDI(dev_priv)); |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 5721 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5722 | case INTEL_OUTPUT_EDP: |
| 5723 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 5724 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5725 | case INTEL_OUTPUT_DP_MST: |
| 5726 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 5727 | return port_to_aux_power_domain(intel_dig_port->port); |
| 5728 | default: |
Imre Deak | b9fec16 | 2015-11-18 15:57:25 +0200 | [diff] [blame] | 5729 | MISSING_CASE(intel_encoder->type); |
Ville Syrjälä | 25f78f5 | 2015-11-16 15:01:04 +0100 | [diff] [blame] | 5730 | return POWER_DOMAIN_AUX_A; |
| 5731 | } |
| 5732 | } |
| 5733 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5734 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc, |
| 5735 | struct intel_crtc_state *crtc_state) |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5736 | { |
| 5737 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5738 | struct drm_encoder *encoder; |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5739 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5740 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5741 | unsigned long mask; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5742 | enum transcoder transcoder = crtc_state->cpu_transcoder; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5743 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5744 | if (!crtc_state->base.active) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5745 | return 0; |
| 5746 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5747 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 5748 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5749 | if (crtc_state->pch_pfit.enabled || |
| 5750 | crtc_state->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5751 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 5752 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5753 | drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) { |
| 5754 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
| 5755 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5756 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5757 | } |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5758 | |
Maarten Lankhorst | 15e7ec2 | 2016-03-14 09:27:54 +0100 | [diff] [blame] | 5759 | if (crtc_state->shared_dpll) |
| 5760 | mask |= BIT(POWER_DOMAIN_PLLS); |
| 5761 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5762 | return mask; |
| 5763 | } |
| 5764 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5765 | static unsigned long |
| 5766 | modeset_get_crtc_power_domains(struct drm_crtc *crtc, |
| 5767 | struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5768 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 5769 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5770 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5771 | enum intel_display_power_domain domain; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5772 | unsigned long domains, new_domains, old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5773 | |
| 5774 | old_domains = intel_crtc->enabled_power_domains; |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 5775 | intel_crtc->enabled_power_domains = new_domains = |
| 5776 | get_crtc_power_domains(crtc, crtc_state); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5777 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5778 | domains = new_domains & ~old_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5779 | |
| 5780 | for_each_power_domain(domain, domains) |
| 5781 | intel_display_power_get(dev_priv, domain); |
| 5782 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 5783 | return old_domains & ~new_domains; |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | static void modeset_put_power_domains(struct drm_i915_private *dev_priv, |
| 5787 | unsigned long domains) |
| 5788 | { |
| 5789 | enum intel_display_power_domain domain; |
| 5790 | |
| 5791 | for_each_power_domain(domain, domains) |
| 5792 | intel_display_power_put(dev_priv, domain); |
| 5793 | } |
| 5794 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5795 | static int intel_compute_max_dotclk(struct drm_i915_private *dev_priv) |
| 5796 | { |
| 5797 | int max_cdclk_freq = dev_priv->max_cdclk_freq; |
| 5798 | |
Ander Conselvan de Oliveira | 09d0938 | 2016-12-02 10:23:55 +0200 | [diff] [blame] | 5799 | if (IS_GEMINILAKE(dev_priv)) |
| 5800 | return 2 * max_cdclk_freq; |
| 5801 | else if (INTEL_INFO(dev_priv)->gen >= 9 || |
| 5802 | IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5803 | return max_cdclk_freq; |
| 5804 | else if (IS_CHERRYVIEW(dev_priv)) |
| 5805 | return max_cdclk_freq*95/100; |
| 5806 | else if (INTEL_INFO(dev_priv)->gen < 4) |
| 5807 | return 2*max_cdclk_freq*90/100; |
| 5808 | else |
| 5809 | return max_cdclk_freq*90/100; |
| 5810 | } |
| 5811 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5812 | static int skl_calc_cdclk(int max_pixclk, int vco); |
| 5813 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 5814 | static void intel_update_max_cdclk(struct drm_i915_private *dev_priv) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5815 | { |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 5816 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5817 | u32 limit = I915_READ(SKL_DFSM) & SKL_DFSM_CDCLK_LIMIT_MASK; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5818 | int max_cdclk, vco; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5819 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5820 | vco = dev_priv->skl_preferred_vco_freq; |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 5821 | WARN_ON(vco != 8100000 && vco != 8640000); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5822 | |
| 5823 | /* |
| 5824 | * Use the lower (vco 8640) cdclk values as a |
| 5825 | * first guess. skl_calc_cdclk() will correct it |
| 5826 | * if the preferred vco is 8100 instead. |
| 5827 | */ |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5828 | if (limit == SKL_DFSM_CDCLK_LIMIT_675) |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5829 | max_cdclk = 617143; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5830 | else if (limit == SKL_DFSM_CDCLK_LIMIT_540) |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5831 | max_cdclk = 540000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5832 | else if (limit == SKL_DFSM_CDCLK_LIMIT_450) |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5833 | max_cdclk = 432000; |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5834 | else |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 5835 | max_cdclk = 308571; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 5836 | |
| 5837 | dev_priv->max_cdclk_freq = skl_calc_cdclk(max_cdclk, vco); |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 5838 | } else if (IS_GEMINILAKE(dev_priv)) { |
| 5839 | dev_priv->max_cdclk_freq = 316800; |
Tvrtko Ursulin | e2d214a | 2016-10-13 11:03:04 +0100 | [diff] [blame] | 5840 | } else if (IS_BROXTON(dev_priv)) { |
Matt Roper | 281c114 | 2016-04-05 14:37:19 -0700 | [diff] [blame] | 5841 | dev_priv->max_cdclk_freq = 624000; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 5842 | } else if (IS_BROADWELL(dev_priv)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5843 | /* |
| 5844 | * FIXME with extra cooling we can allow |
| 5845 | * 540 MHz for ULX and 675 Mhz for ULT. |
| 5846 | * How can we know if extra cooling is |
| 5847 | * available? PCI ID, VTB, something else? |
| 5848 | */ |
| 5849 | if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 5850 | dev_priv->max_cdclk_freq = 450000; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5851 | else if (IS_BDW_ULX(dev_priv)) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5852 | dev_priv->max_cdclk_freq = 450000; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 5853 | else if (IS_BDW_ULT(dev_priv)) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5854 | dev_priv->max_cdclk_freq = 540000; |
| 5855 | else |
| 5856 | dev_priv->max_cdclk_freq = 675000; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 5857 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Mika Kahola | 0904dea | 2015-06-12 10:11:32 +0300 | [diff] [blame] | 5858 | dev_priv->max_cdclk_freq = 320000; |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 5859 | } else if (IS_VALLEYVIEW(dev_priv)) { |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5860 | dev_priv->max_cdclk_freq = 400000; |
| 5861 | } else { |
| 5862 | /* otherwise assume cdclk is fixed */ |
| 5863 | dev_priv->max_cdclk_freq = dev_priv->cdclk_freq; |
| 5864 | } |
| 5865 | |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5866 | dev_priv->max_dotclk_freq = intel_compute_max_dotclk(dev_priv); |
| 5867 | |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5868 | DRM_DEBUG_DRIVER("Max CD clock rate: %d kHz\n", |
| 5869 | dev_priv->max_cdclk_freq); |
Mika Kahola | adafdc6 | 2015-08-18 14:36:59 +0300 | [diff] [blame] | 5870 | |
| 5871 | DRM_DEBUG_DRIVER("Max dotclock rate: %d kHz\n", |
| 5872 | dev_priv->max_dotclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5873 | } |
| 5874 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 5875 | static void intel_update_cdclk(struct drm_i915_private *dev_priv) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5876 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 5877 | dev_priv->cdclk_freq = dev_priv->display.get_display_clock_speed(dev_priv); |
Ville Syrjälä | 2f2a121 | 2016-05-13 23:41:25 +0300 | [diff] [blame] | 5878 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5879 | if (INTEL_GEN(dev_priv) >= 9) |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 5880 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz, VCO: %d kHz, ref: %d kHz\n", |
| 5881 | dev_priv->cdclk_freq, dev_priv->cdclk_pll.vco, |
| 5882 | dev_priv->cdclk_pll.ref); |
Ville Syrjälä | 2f2a121 | 2016-05-13 23:41:25 +0300 | [diff] [blame] | 5883 | else |
| 5884 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
| 5885 | dev_priv->cdclk_freq); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5886 | |
| 5887 | /* |
Ville Syrjälä | b5d99ff | 2016-04-26 19:46:34 +0300 | [diff] [blame] | 5888 | * 9:0 CMBUS [sic] CDCLK frequency (cdfreq): |
| 5889 | * Programmng [sic] note: bit[9:2] should be programmed to the number |
| 5890 | * of cdclk that generates 4MHz reference clock freq which is used to |
| 5891 | * generate GMBus clock. This will vary with the cdclk freq. |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5892 | */ |
Ville Syrjälä | b5d99ff | 2016-04-26 19:46:34 +0300 | [diff] [blame] | 5893 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5894 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->cdclk_freq, 1000)); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 5895 | } |
| 5896 | |
Ville Syrjälä | 92891e4 | 2016-05-11 22:44:45 +0300 | [diff] [blame] | 5897 | /* convert from kHz to .1 fixpoint MHz with -1MHz offset */ |
| 5898 | static int skl_cdclk_decimal(int cdclk) |
| 5899 | { |
| 5900 | return DIV_ROUND_CLOSEST(cdclk - 1000, 500); |
| 5901 | } |
| 5902 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5903 | static int bxt_de_pll_vco(struct drm_i915_private *dev_priv, int cdclk) |
| 5904 | { |
| 5905 | int ratio; |
| 5906 | |
| 5907 | if (cdclk == dev_priv->cdclk_pll.ref) |
| 5908 | return 0; |
| 5909 | |
| 5910 | switch (cdclk) { |
| 5911 | default: |
| 5912 | MISSING_CASE(cdclk); |
| 5913 | case 144000: |
| 5914 | case 288000: |
| 5915 | case 384000: |
| 5916 | case 576000: |
| 5917 | ratio = 60; |
| 5918 | break; |
| 5919 | case 624000: |
| 5920 | ratio = 65; |
| 5921 | break; |
| 5922 | } |
| 5923 | |
| 5924 | return dev_priv->cdclk_pll.ref * ratio; |
| 5925 | } |
| 5926 | |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 5927 | static int glk_de_pll_vco(struct drm_i915_private *dev_priv, int cdclk) |
| 5928 | { |
| 5929 | int ratio; |
| 5930 | |
| 5931 | if (cdclk == dev_priv->cdclk_pll.ref) |
| 5932 | return 0; |
| 5933 | |
| 5934 | switch (cdclk) { |
| 5935 | default: |
| 5936 | MISSING_CASE(cdclk); |
| 5937 | case 79200: |
| 5938 | case 158400: |
| 5939 | case 316800: |
| 5940 | ratio = 33; |
| 5941 | break; |
| 5942 | } |
| 5943 | |
| 5944 | return dev_priv->cdclk_pll.ref * ratio; |
| 5945 | } |
| 5946 | |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5947 | static void bxt_de_pll_disable(struct drm_i915_private *dev_priv) |
| 5948 | { |
| 5949 | I915_WRITE(BXT_DE_PLL_ENABLE, 0); |
| 5950 | |
| 5951 | /* Timeout 200us */ |
Chris Wilson | 95cac28 | 2016-06-30 15:33:03 +0100 | [diff] [blame] | 5952 | if (intel_wait_for_register(dev_priv, |
| 5953 | BXT_DE_PLL_ENABLE, BXT_DE_PLL_LOCK, 0, |
| 5954 | 1)) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5955 | DRM_ERROR("timeout waiting for DE PLL unlock\n"); |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5956 | |
| 5957 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5958 | } |
| 5959 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5960 | static void bxt_de_pll_enable(struct drm_i915_private *dev_priv, int vco) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5961 | { |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5962 | int ratio = DIV_ROUND_CLOSEST(vco, dev_priv->cdclk_pll.ref); |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5963 | u32 val; |
| 5964 | |
| 5965 | val = I915_READ(BXT_DE_PLL_CTL); |
| 5966 | val &= ~BXT_DE_PLL_RATIO_MASK; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5967 | val |= BXT_DE_PLL_RATIO(ratio); |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5968 | I915_WRITE(BXT_DE_PLL_CTL, val); |
| 5969 | |
| 5970 | I915_WRITE(BXT_DE_PLL_ENABLE, BXT_DE_PLL_PLL_ENABLE); |
| 5971 | |
| 5972 | /* Timeout 200us */ |
Chris Wilson | e084e1b | 2016-06-30 15:33:04 +0100 | [diff] [blame] | 5973 | if (intel_wait_for_register(dev_priv, |
| 5974 | BXT_DE_PLL_ENABLE, |
| 5975 | BXT_DE_PLL_LOCK, |
| 5976 | BXT_DE_PLL_LOCK, |
| 5977 | 1)) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5978 | DRM_ERROR("timeout waiting for DE PLL lock\n"); |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 5979 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5980 | dev_priv->cdclk_pll.vco = vco; |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 5981 | } |
| 5982 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 5983 | static void bxt_set_cdclk(struct drm_i915_private *dev_priv, int cdclk) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5984 | { |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5985 | u32 val, divider; |
| 5986 | int vco, ret; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5987 | |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 5988 | if (IS_GEMINILAKE(dev_priv)) |
| 5989 | vco = glk_de_pll_vco(dev_priv, cdclk); |
| 5990 | else |
| 5991 | vco = bxt_de_pll_vco(dev_priv, cdclk); |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 5992 | |
| 5993 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); |
| 5994 | |
| 5995 | /* cdclk = vco / 2 / div{1,1.5,2,4} */ |
| 5996 | switch (DIV_ROUND_CLOSEST(vco, cdclk)) { |
| 5997 | case 8: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5998 | divider = BXT_CDCLK_CD2X_DIV_SEL_4; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 5999 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6000 | case 4: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6001 | divider = BXT_CDCLK_CD2X_DIV_SEL_2; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6002 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6003 | case 3: |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6004 | WARN(IS_GEMINILAKE(dev_priv), "Unsupported divider\n"); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6005 | divider = BXT_CDCLK_CD2X_DIV_SEL_1_5; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6006 | break; |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6007 | case 2: |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6008 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6009 | break; |
| 6010 | default: |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6011 | WARN_ON(cdclk != dev_priv->cdclk_pll.ref); |
| 6012 | WARN_ON(vco != 0); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6013 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6014 | divider = BXT_CDCLK_CD2X_DIV_SEL_1; |
| 6015 | break; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6016 | } |
| 6017 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6018 | /* Inform power controller of upcoming frequency change */ |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6019 | mutex_lock(&dev_priv->rps.hw_lock); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6020 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
| 6021 | 0x80000000); |
| 6022 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6023 | |
| 6024 | if (ret) { |
| 6025 | DRM_ERROR("PCode CDCLK freq change notify failed (err %d, freq %d)\n", |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6026 | ret, cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6027 | return; |
| 6028 | } |
| 6029 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6030 | if (dev_priv->cdclk_pll.vco != 0 && |
| 6031 | dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 2b73001 | 2016-05-13 23:41:34 +0300 | [diff] [blame] | 6032 | bxt_de_pll_disable(dev_priv); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6033 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6034 | if (dev_priv->cdclk_pll.vco != vco) |
| 6035 | bxt_de_pll_enable(dev_priv, vco); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6036 | |
Ville Syrjälä | 5f199df | 2016-05-13 23:41:38 +0300 | [diff] [blame] | 6037 | val = divider | skl_cdclk_decimal(cdclk); |
| 6038 | /* |
| 6039 | * FIXME if only the cd2x divider needs changing, it could be done |
| 6040 | * without shutting off the pipe (if only one pipe is active). |
| 6041 | */ |
| 6042 | val |= BXT_CDCLK_CD2X_PIPE_NONE; |
| 6043 | /* |
| 6044 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 6045 | * enable otherwise. |
| 6046 | */ |
| 6047 | if (cdclk >= 500000) |
| 6048 | val |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 6049 | I915_WRITE(CDCLK_CTL, val); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6050 | |
| 6051 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6052 | ret = sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6053 | DIV_ROUND_UP(cdclk, 25000)); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6054 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6055 | |
| 6056 | if (ret) { |
| 6057 | DRM_ERROR("PCode CDCLK freq set failed, (err %d, freq %d)\n", |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6058 | ret, cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6059 | return; |
| 6060 | } |
| 6061 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6062 | intel_update_cdclk(dev_priv); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6063 | } |
| 6064 | |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 6065 | static void bxt_sanitize_cdclk(struct drm_i915_private *dev_priv) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6066 | { |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 6067 | u32 cdctl, expected; |
| 6068 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6069 | intel_update_cdclk(dev_priv); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6070 | |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 6071 | if (dev_priv->cdclk_pll.vco == 0 || |
| 6072 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) |
| 6073 | goto sanitize; |
| 6074 | |
| 6075 | /* DPLL okay; verify the cdclock |
| 6076 | * |
| 6077 | * Some BIOS versions leave an incorrect decimal frequency value and |
| 6078 | * set reserved MBZ bits in CDCLK_CTL at least during exiting from S4, |
| 6079 | * so sanitize this register. |
| 6080 | */ |
| 6081 | cdctl = I915_READ(CDCLK_CTL); |
| 6082 | /* |
| 6083 | * Let's ignore the pipe field, since BIOS could have configured the |
| 6084 | * dividers both synching to an active pipe, or asynchronously |
| 6085 | * (PIPE_NONE). |
| 6086 | */ |
| 6087 | cdctl &= ~BXT_CDCLK_CD2X_PIPE_NONE; |
| 6088 | |
| 6089 | expected = (cdctl & BXT_CDCLK_CD2X_DIV_SEL_MASK) | |
| 6090 | skl_cdclk_decimal(dev_priv->cdclk_freq); |
| 6091 | /* |
| 6092 | * Disable SSA Precharge when CD clock frequency < 500 MHz, |
| 6093 | * enable otherwise. |
| 6094 | */ |
| 6095 | if (dev_priv->cdclk_freq >= 500000) |
| 6096 | expected |= BXT_CDCLK_SSA_PRECHARGE_ENABLE; |
| 6097 | |
| 6098 | if (cdctl == expected) |
| 6099 | /* All well; nothing to sanitize */ |
| 6100 | return; |
| 6101 | |
| 6102 | sanitize: |
| 6103 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); |
| 6104 | |
| 6105 | /* force cdclk programming */ |
| 6106 | dev_priv->cdclk_freq = 0; |
| 6107 | |
| 6108 | /* force full PLL disable + enable */ |
| 6109 | dev_priv->cdclk_pll.vco = -1; |
| 6110 | } |
| 6111 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 6112 | void bxt_init_cdclk(struct drm_i915_private *dev_priv) |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 6113 | { |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6114 | int cdclk; |
| 6115 | |
Imre Deak | d66a219 | 2016-05-24 15:38:33 +0300 | [diff] [blame] | 6116 | bxt_sanitize_cdclk(dev_priv); |
| 6117 | |
| 6118 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) |
Ville Syrjälä | 089c6fd | 2016-05-13 23:41:36 +0300 | [diff] [blame] | 6119 | return; |
Imre Deak | c2e001e | 2016-04-01 16:02:43 +0300 | [diff] [blame] | 6120 | |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6121 | /* |
| 6122 | * FIXME: |
| 6123 | * - The initial CDCLK needs to be read from VBT. |
| 6124 | * Need to make this change after VBT has changes for BXT. |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6125 | */ |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6126 | if (IS_GEMINILAKE(dev_priv)) |
| 6127 | cdclk = glk_calc_cdclk(0); |
| 6128 | else |
| 6129 | cdclk = bxt_calc_cdclk(0); |
| 6130 | |
| 6131 | bxt_set_cdclk(dev_priv, cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6132 | } |
| 6133 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 6134 | void bxt_uninit_cdclk(struct drm_i915_private *dev_priv) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6135 | { |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 6136 | bxt_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6137 | } |
| 6138 | |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6139 | static int skl_calc_cdclk(int max_pixclk, int vco) |
| 6140 | { |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6141 | if (vco == 8640000) { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6142 | if (max_pixclk > 540000) |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6143 | return 617143; |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6144 | else if (max_pixclk > 432000) |
| 6145 | return 540000; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6146 | else if (max_pixclk > 308571) |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6147 | return 432000; |
| 6148 | else |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6149 | return 308571; |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6150 | } else { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6151 | if (max_pixclk > 540000) |
| 6152 | return 675000; |
| 6153 | else if (max_pixclk > 450000) |
| 6154 | return 540000; |
| 6155 | else if (max_pixclk > 337500) |
| 6156 | return 450000; |
| 6157 | else |
| 6158 | return 337500; |
| 6159 | } |
| 6160 | } |
| 6161 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6162 | static void |
| 6163 | skl_dpll0_update(struct drm_i915_private *dev_priv) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6164 | { |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6165 | u32 val; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6166 | |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 6167 | dev_priv->cdclk_pll.ref = 24000; |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6168 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 6169 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6170 | val = I915_READ(LCPLL1_CTL); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6171 | if ((val & LCPLL_PLL_ENABLE) == 0) |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6172 | return; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6173 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6174 | if (WARN_ON((val & LCPLL_PLL_LOCK) == 0)) |
| 6175 | return; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6176 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6177 | val = I915_READ(DPLL_CTRL1); |
| 6178 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6179 | if (WARN_ON((val & (DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | |
| 6180 | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 6181 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) != |
| 6182 | DPLL_CTRL1_OVERRIDE(SKL_DPLL0))) |
| 6183 | return; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6184 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6185 | switch (val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)) { |
| 6186 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, SKL_DPLL0): |
| 6187 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, SKL_DPLL0): |
| 6188 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, SKL_DPLL0): |
| 6189 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, SKL_DPLL0): |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6190 | dev_priv->cdclk_pll.vco = 8100000; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6191 | break; |
| 6192 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, SKL_DPLL0): |
| 6193 | case DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2160, SKL_DPLL0): |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6194 | dev_priv->cdclk_pll.vco = 8640000; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6195 | break; |
| 6196 | default: |
| 6197 | MISSING_CASE(val & DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 6198 | break; |
| 6199 | } |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6200 | } |
| 6201 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 6202 | void skl_set_preferred_cdclk_vco(struct drm_i915_private *dev_priv, int vco) |
| 6203 | { |
| 6204 | bool changed = dev_priv->skl_preferred_vco_freq != vco; |
| 6205 | |
| 6206 | dev_priv->skl_preferred_vco_freq = vco; |
| 6207 | |
| 6208 | if (changed) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6209 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 6210 | } |
| 6211 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6212 | static void |
Ville Syrjälä | 3861fc6 | 2016-05-11 22:44:50 +0300 | [diff] [blame] | 6213 | skl_dpll0_enable(struct drm_i915_private *dev_priv, int vco) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6214 | { |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6215 | int min_cdclk = skl_calc_cdclk(0, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6216 | u32 val; |
| 6217 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6218 | WARN_ON(vco != 8100000 && vco != 8640000); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 6219 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6220 | /* select the minimum CDCLK before enabling DPLL 0 */ |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6221 | val = CDCLK_FREQ_337_308 | skl_cdclk_decimal(min_cdclk); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6222 | I915_WRITE(CDCLK_CTL, val); |
| 6223 | POSTING_READ(CDCLK_CTL); |
| 6224 | |
| 6225 | /* |
| 6226 | * We always enable DPLL0 with the lowest link rate possible, but still |
| 6227 | * taking into account the VCO required to operate the eDP panel at the |
| 6228 | * desired frequency. The usual DP link rates operate with a VCO of |
| 6229 | * 8100 while the eDP 1.4 alternate link rates need a VCO of 8640. |
| 6230 | * The modeset code is responsible for the selection of the exact link |
| 6231 | * rate later on, with the constraint of choosing a frequency that |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 6232 | * works with vco. |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6233 | */ |
| 6234 | val = I915_READ(DPLL_CTRL1); |
| 6235 | |
| 6236 | val &= ~(DPLL_CTRL1_HDMI_MODE(SKL_DPLL0) | DPLL_CTRL1_SSC(SKL_DPLL0) | |
| 6237 | DPLL_CTRL1_LINK_RATE_MASK(SKL_DPLL0)); |
| 6238 | val |= DPLL_CTRL1_OVERRIDE(SKL_DPLL0); |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6239 | if (vco == 8640000) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6240 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1080, |
| 6241 | SKL_DPLL0); |
| 6242 | else |
| 6243 | val |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, |
| 6244 | SKL_DPLL0); |
| 6245 | |
| 6246 | I915_WRITE(DPLL_CTRL1, val); |
| 6247 | POSTING_READ(DPLL_CTRL1); |
| 6248 | |
| 6249 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) | LCPLL_PLL_ENABLE); |
| 6250 | |
Chris Wilson | e24ca05 | 2016-06-30 15:33:05 +0100 | [diff] [blame] | 6251 | if (intel_wait_for_register(dev_priv, |
| 6252 | LCPLL1_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 6253 | 5)) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6254 | DRM_ERROR("DPLL0 not locked\n"); |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6255 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6256 | dev_priv->cdclk_pll.vco = vco; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 6257 | |
| 6258 | /* We'll want to keep using the current vco from now on. */ |
| 6259 | skl_set_preferred_cdclk_vco(dev_priv, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6260 | } |
| 6261 | |
Ville Syrjälä | 430e05d | 2016-05-11 22:44:47 +0300 | [diff] [blame] | 6262 | static void |
| 6263 | skl_dpll0_disable(struct drm_i915_private *dev_priv) |
| 6264 | { |
| 6265 | I915_WRITE(LCPLL1_CTL, I915_READ(LCPLL1_CTL) & ~LCPLL_PLL_ENABLE); |
Chris Wilson | 8ad32a05 | 2016-06-30 15:33:06 +0100 | [diff] [blame] | 6266 | if (intel_wait_for_register(dev_priv, |
| 6267 | LCPLL1_CTL, LCPLL_PLL_LOCK, 0, |
| 6268 | 1)) |
Ville Syrjälä | 430e05d | 2016-05-11 22:44:47 +0300 | [diff] [blame] | 6269 | DRM_ERROR("Couldn't disable DPLL0\n"); |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6270 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6271 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 430e05d | 2016-05-11 22:44:47 +0300 | [diff] [blame] | 6272 | } |
| 6273 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6274 | static void skl_set_cdclk(struct drm_i915_private *dev_priv, int cdclk, int vco) |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6275 | { |
| 6276 | u32 freq_select, pcu_ack; |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 6277 | int ret; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6278 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6279 | WARN_ON((cdclk == 24000) != (vco == 0)); |
| 6280 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6281 | DRM_DEBUG_DRIVER("Changing CDCLK to %d kHz (VCO %d kHz)\n", cdclk, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6282 | |
Imre Deak | a0b8a1f | 2016-12-05 18:27:37 +0200 | [diff] [blame] | 6283 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6284 | ret = skl_pcode_request(dev_priv, SKL_PCODE_CDCLK_CONTROL, |
| 6285 | SKL_CDCLK_PREPARE_FOR_CHANGE, |
| 6286 | SKL_CDCLK_READY_FOR_CHANGE, |
| 6287 | SKL_CDCLK_READY_FOR_CHANGE, 3); |
| 6288 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6289 | if (ret) { |
| 6290 | DRM_ERROR("Failed to inform PCU about cdclk change (%d)\n", |
| 6291 | ret); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6292 | return; |
| 6293 | } |
| 6294 | |
| 6295 | /* set CDCLK_CTL */ |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6296 | switch (cdclk) { |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6297 | case 450000: |
| 6298 | case 432000: |
| 6299 | freq_select = CDCLK_FREQ_450_432; |
| 6300 | pcu_ack = 1; |
| 6301 | break; |
| 6302 | case 540000: |
| 6303 | freq_select = CDCLK_FREQ_540; |
| 6304 | pcu_ack = 2; |
| 6305 | break; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6306 | case 308571: |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6307 | case 337500: |
| 6308 | default: |
| 6309 | freq_select = CDCLK_FREQ_337_308; |
| 6310 | pcu_ack = 0; |
| 6311 | break; |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 6312 | case 617143: |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6313 | case 675000: |
| 6314 | freq_select = CDCLK_FREQ_675_617; |
| 6315 | pcu_ack = 3; |
| 6316 | break; |
| 6317 | } |
| 6318 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6319 | if (dev_priv->cdclk_pll.vco != 0 && |
| 6320 | dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6321 | skl_dpll0_disable(dev_priv); |
| 6322 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6323 | if (dev_priv->cdclk_pll.vco != vco) |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6324 | skl_dpll0_enable(dev_priv, vco); |
| 6325 | |
Ville Syrjälä | 9ef5615 | 2016-05-11 22:44:49 +0300 | [diff] [blame] | 6326 | I915_WRITE(CDCLK_CTL, freq_select | skl_cdclk_decimal(cdclk)); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6327 | POSTING_READ(CDCLK_CTL); |
| 6328 | |
| 6329 | /* inform PCU of the change */ |
| 6330 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6331 | sandybridge_pcode_write(dev_priv, SKL_PCODE_CDCLK_CONTROL, pcu_ack); |
| 6332 | mutex_unlock(&dev_priv->rps.hw_lock); |
Damien Lespiau | 560a7ae | 2015-06-04 18:21:33 +0100 | [diff] [blame] | 6333 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6334 | intel_update_cdclk(dev_priv); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6335 | } |
| 6336 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6337 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv); |
| 6338 | |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6339 | void skl_uninit_cdclk(struct drm_i915_private *dev_priv) |
| 6340 | { |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 6341 | skl_set_cdclk(dev_priv, dev_priv->cdclk_pll.ref, 0); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6342 | } |
| 6343 | |
| 6344 | void skl_init_cdclk(struct drm_i915_private *dev_priv) |
| 6345 | { |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6346 | int cdclk, vco; |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6347 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6348 | skl_sanitize_cdclk(dev_priv); |
| 6349 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6350 | if (dev_priv->cdclk_freq != 0 && dev_priv->cdclk_pll.vco != 0) { |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6351 | /* |
| 6352 | * Use the current vco as our initial |
| 6353 | * guess as to what the preferred vco is. |
| 6354 | */ |
| 6355 | if (dev_priv->skl_preferred_vco_freq == 0) |
| 6356 | skl_set_preferred_cdclk_vco(dev_priv, |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6357 | dev_priv->cdclk_pll.vco); |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 6358 | return; |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 6359 | } |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6360 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 6361 | vco = dev_priv->skl_preferred_vco_freq; |
| 6362 | if (vco == 0) |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6363 | vco = 8100000; |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 6364 | cdclk = skl_calc_cdclk(0, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6365 | |
Ville Syrjälä | 70c2c18 | 2016-05-13 23:41:30 +0300 | [diff] [blame] | 6366 | skl_set_cdclk(dev_priv, cdclk, vco); |
Damien Lespiau | 5d96d8a | 2015-05-21 16:37:48 +0100 | [diff] [blame] | 6367 | } |
| 6368 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6369 | static void skl_sanitize_cdclk(struct drm_i915_private *dev_priv) |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6370 | { |
Ville Syrjälä | 0949249 | 2016-05-13 23:41:28 +0300 | [diff] [blame] | 6371 | uint32_t cdctl, expected; |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6372 | |
Shobhit Kumar | f1b391a | 2015-11-05 18:05:32 +0530 | [diff] [blame] | 6373 | /* |
| 6374 | * check if the pre-os intialized the display |
| 6375 | * There is SWF18 scratchpad register defined which is set by the |
| 6376 | * pre-os which can be used by the OS drivers to check the status |
| 6377 | */ |
| 6378 | if ((I915_READ(SWF_ILK(0x18)) & 0x00FFFFFF) == 0) |
| 6379 | goto sanitize; |
| 6380 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6381 | intel_update_cdclk(dev_priv); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 6382 | /* Is PLL enabled and locked ? */ |
| 6383 | if (dev_priv->cdclk_pll.vco == 0 || |
| 6384 | dev_priv->cdclk_freq == dev_priv->cdclk_pll.ref) |
| 6385 | goto sanitize; |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6386 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6387 | /* DPLL okay; verify the cdclock |
| 6388 | * |
| 6389 | * Noticed in some instances that the freq selection is correct but |
| 6390 | * decimal part is programmed wrong from BIOS where pre-os does not |
| 6391 | * enable display. Verify the same as well. |
| 6392 | */ |
Ville Syrjälä | 0949249 | 2016-05-13 23:41:28 +0300 | [diff] [blame] | 6393 | cdctl = I915_READ(CDCLK_CTL); |
| 6394 | expected = (cdctl & CDCLK_FREQ_SEL_MASK) | |
| 6395 | skl_cdclk_decimal(dev_priv->cdclk_freq); |
| 6396 | if (cdctl == expected) |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6397 | /* All well; nothing to sanitize */ |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6398 | return; |
| 6399 | |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6400 | sanitize: |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6401 | DRM_DEBUG_KMS("Sanitizing cdclk programmed by pre-os\n"); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 6402 | |
Ville Syrjälä | 9f7eb31 | 2016-05-13 23:41:29 +0300 | [diff] [blame] | 6403 | /* force cdclk programming */ |
| 6404 | dev_priv->cdclk_freq = 0; |
| 6405 | /* force full PLL disable + enable */ |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 6406 | dev_priv->cdclk_pll.vco = -1; |
Shobhit Kumar | c73666f | 2015-10-20 18:13:12 +0530 | [diff] [blame] | 6407 | } |
| 6408 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6409 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 6410 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 6411 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6412 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6413 | u32 val, cmd; |
| 6414 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 6415 | WARN_ON(dev_priv->display.get_display_clock_speed(dev_priv) |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 6416 | != dev_priv->cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 6417 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6418 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6419 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6420 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6421 | cmd = 1; |
| 6422 | else |
| 6423 | cmd = 0; |
| 6424 | |
| 6425 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6426 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 6427 | val &= ~DSPFREQGUAR_MASK; |
| 6428 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 6429 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 6430 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 6431 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 6432 | 50)) { |
| 6433 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 6434 | } |
| 6435 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6436 | |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 6437 | mutex_lock(&dev_priv->sb_lock); |
| 6438 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6439 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6440 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6441 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6442 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6443 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6444 | /* adjust cdclk divider */ |
| 6445 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 6446 | val &= ~CCK_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6447 | val |= divider; |
| 6448 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 6449 | |
| 6450 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
Vandana Kannan | 87d5d25 | 2015-09-24 23:29:17 +0300 | [diff] [blame] | 6451 | CCK_FREQUENCY_STATUS) == (divider << CCK_FREQUENCY_STATUS_SHIFT), |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 6452 | 50)) |
| 6453 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6454 | } |
| 6455 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6456 | /* adjust self-refresh exit latency value */ |
| 6457 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 6458 | val &= ~0x7f; |
| 6459 | |
| 6460 | /* |
| 6461 | * For high bandwidth configs, we set a higher latency in the bunit |
| 6462 | * so that the core display fetch happens in time to avoid underruns. |
| 6463 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6464 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6465 | val |= 4500 / 250; /* 4.5 usec */ |
| 6466 | else |
| 6467 | val |= 3000 / 250; /* 3.0 usec */ |
| 6468 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
Ville Syrjälä | 54433e9 | 2015-05-26 20:42:31 +0300 | [diff] [blame] | 6469 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 6470 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6471 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6472 | intel_update_cdclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6473 | } |
| 6474 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6475 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 6476 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6477 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6478 | u32 val, cmd; |
| 6479 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 6480 | WARN_ON(dev_priv->display.get_display_clock_speed(dev_priv) |
Vandana Kannan | 164dfd2 | 2014-11-24 13:37:41 +0530 | [diff] [blame] | 6481 | != dev_priv->cdclk_freq); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6482 | |
| 6483 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6484 | case 333333: |
| 6485 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6486 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6487 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6488 | break; |
| 6489 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 6490 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6491 | return; |
| 6492 | } |
| 6493 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 6494 | /* |
| 6495 | * Specs are full of misinformation, but testing on actual |
| 6496 | * hardware has shown that we just need to write the desired |
| 6497 | * CCK divider into the Punit register. |
| 6498 | */ |
| 6499 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 6500 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6501 | mutex_lock(&dev_priv->rps.hw_lock); |
| 6502 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 6503 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 6504 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 6505 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 6506 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 6507 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 6508 | 50)) { |
| 6509 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 6510 | } |
| 6511 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 6512 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 6513 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 6514 | } |
| 6515 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6516 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 6517 | int max_pixclk) |
| 6518 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6519 | 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] | 6520 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 6521 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6522 | /* |
| 6523 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 6524 | * 200MHz |
| 6525 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 6526 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 6527 | * 400MHz (VLV only) |
| 6528 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 6529 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 6530 | * |
| 6531 | * We seem to get an unstable or solid color picture at 200MHz. |
| 6532 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 6533 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6534 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 6535 | if (!IS_CHERRYVIEW(dev_priv) && |
| 6536 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6537 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 6538 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 6539 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 6540 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 6541 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 6542 | else |
| 6543 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6544 | } |
| 6545 | |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6546 | static int glk_calc_cdclk(int max_pixclk) |
| 6547 | { |
Ander Conselvan de Oliveira | 09d0938 | 2016-12-02 10:23:55 +0200 | [diff] [blame] | 6548 | if (max_pixclk > 2 * 158400) |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6549 | return 316800; |
Ander Conselvan de Oliveira | 09d0938 | 2016-12-02 10:23:55 +0200 | [diff] [blame] | 6550 | else if (max_pixclk > 2 * 79200) |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6551 | return 158400; |
| 6552 | else |
| 6553 | return 79200; |
| 6554 | } |
| 6555 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 6556 | static int bxt_calc_cdclk(int max_pixclk) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6557 | { |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 6558 | if (max_pixclk > 576000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6559 | return 624000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 6560 | else if (max_pixclk > 384000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6561 | return 576000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 6562 | else if (max_pixclk > 288000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6563 | return 384000; |
Ville Syrjälä | 760e147 | 2016-05-11 22:44:46 +0300 | [diff] [blame] | 6564 | else if (max_pixclk > 144000) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6565 | return 288000; |
| 6566 | else |
| 6567 | return 144000; |
| 6568 | } |
| 6569 | |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 6570 | /* Compute the max pixel clock for new configuration. */ |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 6571 | static int intel_mode_max_pixclk(struct drm_device *dev, |
| 6572 | struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6573 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6574 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6575 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6576 | struct drm_crtc *crtc; |
| 6577 | struct drm_crtc_state *crtc_state; |
| 6578 | unsigned max_pixclk = 0, i; |
| 6579 | enum pipe pipe; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6580 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6581 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 6582 | sizeof(intel_state->min_pixclk)); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6583 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6584 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 6585 | int pixclk = 0; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6586 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6587 | if (crtc_state->enable) |
| 6588 | pixclk = crtc_state->adjusted_mode.crtc_clock; |
| 6589 | |
| 6590 | intel_state->min_pixclk[i] = pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6591 | } |
| 6592 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6593 | for_each_pipe(dev_priv, pipe) |
| 6594 | max_pixclk = max(intel_state->min_pixclk[pipe], max_pixclk); |
| 6595 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6596 | return max_pixclk; |
| 6597 | } |
| 6598 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6599 | static int valleyview_modeset_calc_cdclk(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6600 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6601 | struct drm_device *dev = state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6602 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6603 | int max_pixclk = intel_mode_max_pixclk(dev, state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6604 | struct intel_atomic_state *intel_state = |
| 6605 | to_intel_atomic_state(state); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6606 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6607 | intel_state->cdclk = intel_state->dev_cdclk = |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6608 | valleyview_calc_cdclk(dev_priv, max_pixclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 6609 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6610 | if (!intel_state->active_crtcs) |
| 6611 | intel_state->dev_cdclk = valleyview_calc_cdclk(dev_priv, 0); |
| 6612 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6613 | return 0; |
| 6614 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6615 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 6616 | static int bxt_modeset_calc_cdclk(struct drm_atomic_state *state) |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6617 | { |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6618 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Ville Syrjälä | 4e5ca60 | 2016-05-11 22:44:44 +0300 | [diff] [blame] | 6619 | int max_pixclk = ilk_max_pixel_rate(state); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6620 | struct intel_atomic_state *intel_state = |
| 6621 | to_intel_atomic_state(state); |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6622 | int cdclk; |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 6623 | |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6624 | if (IS_GEMINILAKE(dev_priv)) |
| 6625 | cdclk = glk_calc_cdclk(max_pixclk); |
| 6626 | else |
| 6627 | cdclk = bxt_calc_cdclk(max_pixclk); |
Maarten Lankhorst | 85a96e7 | 2015-06-01 12:49:53 +0200 | [diff] [blame] | 6628 | |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 6629 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 6630 | |
| 6631 | if (!intel_state->active_crtcs) { |
| 6632 | if (IS_GEMINILAKE(dev_priv)) |
| 6633 | cdclk = glk_calc_cdclk(0); |
| 6634 | else |
| 6635 | cdclk = bxt_calc_cdclk(0); |
| 6636 | |
| 6637 | intel_state->dev_cdclk = cdclk; |
| 6638 | } |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6639 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6640 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6641 | } |
| 6642 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6643 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 6644 | { |
| 6645 | unsigned int credits, default_credits; |
| 6646 | |
| 6647 | if (IS_CHERRYVIEW(dev_priv)) |
| 6648 | default_credits = PFI_CREDIT(12); |
| 6649 | else |
| 6650 | default_credits = PFI_CREDIT(8); |
| 6651 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 6652 | if (dev_priv->cdclk_freq >= dev_priv->czclk_freq) { |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6653 | /* CHV suggested value is 31 or 63 */ |
| 6654 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | fcc0008 | 2015-05-26 20:22:40 +0300 | [diff] [blame] | 6655 | credits = PFI_CREDIT_63; |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 6656 | else |
| 6657 | credits = PFI_CREDIT(15); |
| 6658 | } else { |
| 6659 | credits = default_credits; |
| 6660 | } |
| 6661 | |
| 6662 | /* |
| 6663 | * WA - write default credits before re-programming |
| 6664 | * FIXME: should we also set the resend bit here? |
| 6665 | */ |
| 6666 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6667 | default_credits); |
| 6668 | |
| 6669 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 6670 | credits | PFI_CREDIT_RESEND); |
| 6671 | |
| 6672 | /* |
| 6673 | * FIXME is this guaranteed to clear |
| 6674 | * immediately or should we poll for it? |
| 6675 | */ |
| 6676 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 6677 | } |
| 6678 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6679 | static void valleyview_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6680 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 6681 | struct drm_device *dev = old_state->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6682 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 6683 | struct intel_atomic_state *old_intel_state = |
| 6684 | to_intel_atomic_state(old_state); |
| 6685 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6686 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6687 | /* |
| 6688 | * FIXME: We can end up here with all power domains off, yet |
| 6689 | * with a CDCLK frequency other than the minimum. To account |
| 6690 | * for this take the PIPE-A power domain, which covers the HW |
| 6691 | * blocks needed for the following programming. This can be |
| 6692 | * removed once it's guaranteed that we get here either with |
| 6693 | * the minimum CDCLK set, or the required power domains |
| 6694 | * enabled. |
| 6695 | */ |
| 6696 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 6697 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6698 | if (IS_CHERRYVIEW(dev_priv)) |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6699 | cherryview_set_cdclk(dev, req_cdclk); |
| 6700 | else |
| 6701 | valleyview_set_cdclk(dev, req_cdclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6702 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6703 | vlv_program_pfi_credits(dev_priv); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 6704 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 6705 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 6706 | } |
| 6707 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6708 | static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6709 | struct drm_atomic_state *old_state) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6710 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6711 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6712 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6713 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6714 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6715 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6716 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6717 | if (WARN_ON(intel_crtc->active)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6718 | return; |
| 6719 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 6720 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6721 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6722 | |
| 6723 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6724 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6725 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6726 | if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6727 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 6728 | |
| 6729 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 6730 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 6731 | } |
| 6732 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6733 | i9xx_set_pipeconf(intel_crtc); |
| 6734 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6735 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6736 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6737 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6738 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6739 | intel_encoders_pre_pll_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6740 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6741 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6742 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
| 6743 | chv_enable_pll(intel_crtc, intel_crtc->config); |
| 6744 | } else { |
| 6745 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
| 6746 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6747 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6748 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6749 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6750 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6751 | i9xx_pfit_enable(intel_crtc); |
| 6752 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6753 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6754 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6755 | intel_update_watermarks(intel_crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6756 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6757 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6758 | assert_vblank_disabled(crtc); |
| 6759 | drm_crtc_vblank_on(crtc); |
| 6760 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6761 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6762 | } |
| 6763 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6764 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 6765 | { |
| 6766 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6767 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6768 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6769 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 6770 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6771 | } |
| 6772 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6773 | static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config, |
| 6774 | struct drm_atomic_state *old_state) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6775 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6776 | struct drm_crtc *crtc = pipe_config->base.crtc; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6777 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6778 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6779 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 6780 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6781 | |
Maarten Lankhorst | 53d9f4e | 2015-06-01 12:49:52 +0200 | [diff] [blame] | 6782 | if (WARN_ON(intel_crtc->active)) |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6783 | return; |
| 6784 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 6785 | i9xx_set_pll_dividers(intel_crtc); |
| 6786 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 6787 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6788 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6789 | |
| 6790 | intel_set_pipe_timings(intel_crtc); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 6791 | intel_set_pipe_src_size(intel_crtc); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6792 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6793 | i9xx_set_pipeconf(intel_crtc); |
| 6794 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 6795 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6796 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6797 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6798 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 6799 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6800 | intel_encoders_pre_enable(crtc, pipe_config, old_state); |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 6801 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 6802 | i9xx_enable_pll(intel_crtc); |
| 6803 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 6804 | i9xx_pfit_enable(intel_crtc); |
| 6805 | |
Maarten Lankhorst | b95c532 | 2016-03-30 17:16:34 +0200 | [diff] [blame] | 6806 | intel_color_load_luts(&pipe_config->base); |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 6807 | |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6808 | intel_update_watermarks(intel_crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 6809 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 6810 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6811 | assert_vblank_disabled(crtc); |
| 6812 | drm_crtc_vblank_on(crtc); |
| 6813 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6814 | intel_encoders_enable(crtc, pipe_config, old_state); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6815 | } |
| 6816 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6817 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 6818 | { |
| 6819 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6820 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6821 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6822 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6823 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6824 | |
| 6825 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 6826 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 6827 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 6828 | I915_READ(PFIT_CONTROL)); |
| 6829 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6830 | } |
| 6831 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6832 | static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state, |
| 6833 | struct drm_atomic_state *old_state) |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6834 | { |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6835 | struct drm_crtc *crtc = old_crtc_state->base.crtc; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6836 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 6837 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6838 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6839 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 6840 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6841 | /* |
| 6842 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 6843 | * wait for planes to fully turn off before disabling the pipe. |
| 6844 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6845 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 6846 | intel_wait_for_vblank(dev_priv, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 6847 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6848 | intel_encoders_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 6849 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 6850 | drm_crtc_vblank_off(crtc); |
| 6851 | assert_vblank_disabled(crtc); |
| 6852 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 6853 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6854 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 6855 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 6856 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6857 | intel_encoders_post_disable(crtc, old_crtc_state, old_state); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6858 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 6859 | if (!intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_DSI)) { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 6860 | if (IS_CHERRYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6861 | chv_disable_pll(dev_priv, pipe); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 6862 | else if (IS_VALLEYVIEW(dev_priv)) |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6863 | vlv_disable_pll(dev_priv, pipe); |
| 6864 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6865 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 6866 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6867 | |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 6868 | intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state); |
Ville Syrjälä | d6db995 | 2015-07-08 23:45:49 +0300 | [diff] [blame] | 6869 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 6870 | if (!IS_GEN2(dev_priv)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 6871 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 6872 | } |
| 6873 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6874 | static void intel_crtc_disable_noatomic(struct drm_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 6875 | { |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6876 | struct intel_encoder *encoder; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6877 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6878 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6879 | enum intel_display_power_domain domain; |
| 6880 | unsigned long domains; |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6881 | struct drm_atomic_state *state; |
| 6882 | struct intel_crtc_state *crtc_state; |
| 6883 | int ret; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 6884 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6885 | if (!intel_crtc->active) |
| 6886 | return; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6887 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 6888 | if (to_intel_plane_state(crtc->primary->state)->base.visible) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6889 | WARN_ON(intel_crtc->flip_work); |
Maarten Lankhorst | fc32b1f | 2015-10-19 17:09:23 +0200 | [diff] [blame] | 6890 | |
Ville Syrjälä | 2622a08 | 2016-03-09 19:07:26 +0200 | [diff] [blame] | 6891 | intel_pre_disable_primary_noatomic(crtc); |
Maarten Lankhorst | 54a41961 | 2015-11-23 10:25:28 +0100 | [diff] [blame] | 6892 | |
| 6893 | intel_crtc_disable_planes(crtc, 1 << drm_plane_index(crtc->primary)); |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 6894 | to_intel_plane_state(crtc->primary->state)->base.visible = false; |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 6895 | } |
| 6896 | |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 6897 | state = drm_atomic_state_alloc(crtc->dev); |
| 6898 | state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; |
| 6899 | |
| 6900 | /* Everything's already locked, -EDEADLK can't happen. */ |
| 6901 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 6902 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 6903 | |
| 6904 | WARN_ON(IS_ERR(crtc_state) || ret); |
| 6905 | |
| 6906 | dev_priv->display.crtc_disable(crtc_state, state); |
| 6907 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 6908 | drm_atomic_state_put(state); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6909 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 6910 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n", |
| 6911 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6912 | |
| 6913 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0); |
| 6914 | crtc->state->active = false; |
Matt Roper | 37d9078 | 2015-09-24 15:53:06 -0700 | [diff] [blame] | 6915 | intel_crtc->active = false; |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 6916 | crtc->enabled = false; |
| 6917 | crtc->state->connector_mask = 0; |
| 6918 | crtc->state->encoder_mask = 0; |
| 6919 | |
| 6920 | for_each_encoder_on_crtc(crtc->dev, crtc, encoder) |
| 6921 | encoder->base.crtc = NULL; |
| 6922 | |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 6923 | intel_fbc_disable(intel_crtc); |
Ville Syrjälä | 432081b | 2016-10-31 22:37:03 +0200 | [diff] [blame] | 6924 | intel_update_watermarks(intel_crtc); |
Maarten Lankhorst | 1f7457b | 2015-07-13 11:55:05 +0200 | [diff] [blame] | 6925 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 6926 | |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6927 | domains = intel_crtc->enabled_power_domains; |
| 6928 | for_each_power_domain(domain, domains) |
| 6929 | intel_display_power_put(dev_priv, domain); |
| 6930 | intel_crtc->enabled_power_domains = 0; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 6931 | |
| 6932 | dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe); |
| 6933 | dev_priv->min_pixclk[intel_crtc->pipe] = 0; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 6934 | } |
| 6935 | |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6936 | /* |
| 6937 | * turn all crtc's off, but do not adjust state |
| 6938 | * This has to be paired with a call to intel_modeset_setup_hw_state. |
| 6939 | */ |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6940 | int intel_display_suspend(struct drm_device *dev) |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6941 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6942 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6943 | struct drm_atomic_state *state; |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6944 | int ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6945 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6946 | state = drm_atomic_helper_suspend(dev); |
| 6947 | ret = PTR_ERR_OR_ZERO(state); |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6948 | if (ret) |
| 6949 | DRM_ERROR("Suspending crtc's failed with %i\n", ret); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 6950 | else |
| 6951 | dev_priv->modeset_restore_state = state; |
Maarten Lankhorst | 70e0bd7 | 2015-07-13 16:30:29 +0200 | [diff] [blame] | 6952 | return ret; |
Maarten Lankhorst | 6b72d48 | 2015-06-01 12:49:47 +0200 | [diff] [blame] | 6953 | } |
| 6954 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6955 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 6956 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6957 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6958 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 6959 | drm_encoder_cleanup(encoder); |
| 6960 | kfree(intel_encoder); |
| 6961 | } |
| 6962 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6963 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 6964 | * internal consistency). */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6965 | static void intel_connector_verify_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6966 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6967 | struct drm_crtc *crtc = connector->base.state->crtc; |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6968 | |
| 6969 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 6970 | connector->base.base.id, |
| 6971 | connector->base.name); |
| 6972 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6973 | if (connector->get_hw_state(connector)) { |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6974 | struct intel_encoder *encoder = connector->encoder; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6975 | struct drm_connector_state *conn_state = connector->base.state; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6976 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6977 | I915_STATE_WARN(!crtc, |
| 6978 | "connector enabled without attached crtc\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6979 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6980 | if (!crtc) |
| 6981 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6982 | |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6983 | I915_STATE_WARN(!crtc->state->active, |
| 6984 | "connector is active, but attached crtc isn't\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6985 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6986 | if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST) |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6987 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6988 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6989 | I915_STATE_WARN(conn_state->best_encoder != &encoder->base, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6990 | "atomic encoder doesn't match attached encoder\n"); |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 6991 | |
Maarten Lankhorst | e85376c | 2015-08-27 13:13:31 +0200 | [diff] [blame] | 6992 | I915_STATE_WARN(conn_state->crtc != encoder->base.crtc, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6993 | "attached encoder crtc differs from connector crtc\n"); |
| 6994 | } else { |
Maarten Lankhorst | 4d688a2 | 2015-08-05 12:37:06 +0200 | [diff] [blame] | 6995 | I915_STATE_WARN(crtc && crtc->state->active, |
| 6996 | "attached crtc is active, but connector isn't\n"); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 6997 | I915_STATE_WARN(!crtc && connector->base.state->best_encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 6998 | "best encoder set without crtc!\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 6999 | } |
| 7000 | } |
| 7001 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 7002 | int intel_connector_init(struct intel_connector *connector) |
| 7003 | { |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 7004 | drm_atomic_helper_connector_reset(&connector->base); |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 7005 | |
Maarten Lankhorst | 5350a03 | 2016-01-04 12:53:15 +0100 | [diff] [blame] | 7006 | if (!connector->base.state) |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 7007 | return -ENOMEM; |
| 7008 | |
Ander Conselvan de Oliveira | 08d9bc9 | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 7009 | return 0; |
| 7010 | } |
| 7011 | |
| 7012 | struct intel_connector *intel_connector_alloc(void) |
| 7013 | { |
| 7014 | struct intel_connector *connector; |
| 7015 | |
| 7016 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 7017 | if (!connector) |
| 7018 | return NULL; |
| 7019 | |
| 7020 | if (intel_connector_init(connector) < 0) { |
| 7021 | kfree(connector); |
| 7022 | return NULL; |
| 7023 | } |
| 7024 | |
| 7025 | return connector; |
| 7026 | } |
| 7027 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 7028 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 7029 | * one connector and no cloning and hence the encoder state determines the state |
| 7030 | * of the connector. */ |
| 7031 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 7032 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 7033 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 7034 | struct intel_encoder *encoder = connector->encoder; |
| 7035 | |
| 7036 | return encoder->get_hw_state(encoder, &pipe); |
| 7037 | } |
| 7038 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7039 | 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] | 7040 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7041 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 7042 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 7043 | |
| 7044 | return 0; |
| 7045 | } |
| 7046 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7047 | 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] | 7048 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7049 | { |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 7050 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7051 | struct drm_atomic_state *state = pipe_config->base.state; |
| 7052 | struct intel_crtc *other_crtc; |
| 7053 | struct intel_crtc_state *other_crtc_state; |
| 7054 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7055 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 7056 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 7057 | if (pipe_config->fdi_lanes > 4) { |
| 7058 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 7059 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7060 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7061 | } |
| 7062 | |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 7063 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7064 | if (pipe_config->fdi_lanes > 2) { |
| 7065 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 7066 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7067 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7068 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7069 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7070 | } |
| 7071 | } |
| 7072 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 7073 | if (INTEL_INFO(dev_priv)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7074 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7075 | |
| 7076 | /* Ivybridge 3 pipe is really complicated */ |
| 7077 | switch (pipe) { |
| 7078 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7079 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7080 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7081 | if (pipe_config->fdi_lanes <= 2) |
| 7082 | return 0; |
| 7083 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7084 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7085 | other_crtc_state = |
| 7086 | intel_atomic_get_crtc_state(state, other_crtc); |
| 7087 | if (IS_ERR(other_crtc_state)) |
| 7088 | return PTR_ERR(other_crtc_state); |
| 7089 | |
| 7090 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7091 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 7092 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7093 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7094 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7095 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7096 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 7097 | if (pipe_config->fdi_lanes > 2) { |
| 7098 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 7099 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7100 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 7101 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7102 | |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 7103 | other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7104 | other_crtc_state = |
| 7105 | intel_atomic_get_crtc_state(state, other_crtc); |
| 7106 | if (IS_ERR(other_crtc_state)) |
| 7107 | return PTR_ERR(other_crtc_state); |
| 7108 | |
| 7109 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7110 | 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] | 7111 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7112 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7113 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7114 | default: |
| 7115 | BUG(); |
| 7116 | } |
| 7117 | } |
| 7118 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7119 | #define RETRY 1 |
| 7120 | 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] | 7121 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7122 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7123 | struct drm_device *dev = intel_crtc->base.dev; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7124 | 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] | 7125 | int lane, link_bw, fdi_dotclock, ret; |
| 7126 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7127 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7128 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7129 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 7130 | * each output octet as 10 bits. The actual frequency |
| 7131 | * is stored as a divider into a 100MHz clock, and the |
| 7132 | * mode pixel clock is stored in units of 1KHz. |
| 7133 | * Hence the bw of each lane in terms of the mode signal |
| 7134 | * is: |
| 7135 | */ |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 7136 | link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7137 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 7138 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7139 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 7140 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7141 | pipe_config->pipe_bpp); |
| 7142 | |
| 7143 | pipe_config->fdi_lanes = lane; |
| 7144 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 7145 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7146 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 7147 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 7148 | 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] | 7149 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7150 | pipe_config->pipe_bpp -= 2*3; |
| 7151 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 7152 | pipe_config->pipe_bpp); |
| 7153 | needs_recompute = true; |
| 7154 | pipe_config->bw_constrained = true; |
| 7155 | |
| 7156 | goto retry; |
| 7157 | } |
| 7158 | |
| 7159 | if (needs_recompute) |
| 7160 | return RETRY; |
| 7161 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 7162 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7163 | } |
| 7164 | |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7165 | static bool pipe_config_supports_ips(struct drm_i915_private *dev_priv, |
| 7166 | struct intel_crtc_state *pipe_config) |
| 7167 | { |
| 7168 | if (pipe_config->pipe_bpp > 24) |
| 7169 | return false; |
| 7170 | |
| 7171 | /* HSW can handle pixel rate up to cdclk? */ |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 7172 | if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7173 | return true; |
| 7174 | |
| 7175 | /* |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 7176 | * We compare against max which means we must take |
| 7177 | * the increased cdclk requirement into account when |
| 7178 | * calculating the new cdclk. |
| 7179 | * |
| 7180 | * Should measure whether using a lower cdclk w/o IPS |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7181 | */ |
| 7182 | return ilk_pipe_pixel_rate(pipe_config) <= |
| 7183 | dev_priv->max_cdclk_freq * 95 / 100; |
| 7184 | } |
| 7185 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7186 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7187 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7188 | { |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7189 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7190 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7191 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7192 | pipe_config->ips_enabled = i915.enable_ips && |
Ville Syrjälä | 8cfb340 | 2015-06-03 15:45:11 +0300 | [diff] [blame] | 7193 | hsw_crtc_supports_ips(crtc) && |
| 7194 | pipe_config_supports_ips(dev_priv, pipe_config); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7195 | } |
| 7196 | |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 7197 | static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc) |
| 7198 | { |
| 7199 | const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 7200 | |
| 7201 | /* GDG double wide on either pipe, otherwise pipe A only */ |
| 7202 | return INTEL_INFO(dev_priv)->gen < 4 && |
| 7203 | (crtc->pipe == PIPE_A || IS_I915G(dev_priv)); |
| 7204 | } |
| 7205 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 7206 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7207 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7208 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 7209 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7210 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 7211 | const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 7212 | int clock_limit = dev_priv->max_dotclk_freq; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 7213 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7214 | if (INTEL_GEN(dev_priv) < 4) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 7215 | clock_limit = dev_priv->max_cdclk_freq * 9 / 10; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7216 | |
| 7217 | /* |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 7218 | * Enable double wide mode when the dot clock |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7219 | * is > 90% of the (display) core speed. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7220 | */ |
Ville Syrjälä | 39acb4a | 2015-10-30 23:39:38 +0200 | [diff] [blame] | 7221 | if (intel_crtc_supports_double_wide(crtc) && |
| 7222 | adjusted_mode->crtc_clock > clock_limit) { |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 7223 | clock_limit = dev_priv->max_dotclk_freq; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 7224 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 7225 | } |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 7226 | } |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 7227 | |
Ville Syrjälä | f326115 | 2016-05-24 21:34:18 +0300 | [diff] [blame] | 7228 | if (adjusted_mode->crtc_clock > clock_limit) { |
| 7229 | DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n", |
| 7230 | adjusted_mode->crtc_clock, clock_limit, |
| 7231 | yesno(pipe_config->double_wide)); |
| 7232 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7233 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 7234 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 7235 | /* |
| 7236 | * Pipe horizontal size must be even in: |
| 7237 | * - DVO ganged mode |
| 7238 | * - LVDS dual channel mode |
| 7239 | * - Double wide pipe |
| 7240 | */ |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7241 | if ((intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 7242 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 7243 | pipe_config->pipe_src_w &= ~1; |
| 7244 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 7245 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 7246 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 7247 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7248 | if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) && |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 7249 | adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7250 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 7251 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7252 | if (HAS_IPS(dev_priv)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 7253 | hsw_compute_ips_config(crtc, pipe_config); |
| 7254 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7255 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 7256 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 7257 | |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 7258 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7259 | } |
| 7260 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7261 | static int skylake_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7262 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7263 | u32 cdctl; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7264 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7265 | skl_dpll0_update(dev_priv); |
| 7266 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 7267 | if (dev_priv->cdclk_pll.vco == 0) |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 7268 | return dev_priv->cdclk_pll.ref; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7269 | |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7270 | cdctl = I915_READ(CDCLK_CTL); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7271 | |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 7272 | if (dev_priv->cdclk_pll.vco == 8640000) { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7273 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 7274 | case CDCLK_FREQ_450_432: |
| 7275 | return 432000; |
| 7276 | case CDCLK_FREQ_337_308: |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 7277 | return 308571; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7278 | case CDCLK_FREQ_540: |
| 7279 | return 540000; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7280 | case CDCLK_FREQ_675_617: |
Ville Syrjälä | 487ed2e | 2016-05-13 23:41:31 +0300 | [diff] [blame] | 7281 | return 617143; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7282 | default: |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7283 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7284 | } |
| 7285 | } else { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7286 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 7287 | case CDCLK_FREQ_450_432: |
| 7288 | return 450000; |
| 7289 | case CDCLK_FREQ_337_308: |
| 7290 | return 337500; |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7291 | case CDCLK_FREQ_540: |
| 7292 | return 540000; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7293 | case CDCLK_FREQ_675_617: |
| 7294 | return 675000; |
| 7295 | default: |
Ville Syrjälä | ea61791 | 2016-05-13 23:41:24 +0300 | [diff] [blame] | 7296 | MISSING_CASE(cdctl & CDCLK_FREQ_SEL_MASK); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7297 | } |
| 7298 | } |
| 7299 | |
Ville Syrjälä | 709e05c | 2016-05-13 23:41:33 +0300 | [diff] [blame] | 7300 | return dev_priv->cdclk_pll.ref; |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7301 | } |
| 7302 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7303 | static void bxt_de_pll_update(struct drm_i915_private *dev_priv) |
| 7304 | { |
| 7305 | u32 val; |
| 7306 | |
| 7307 | dev_priv->cdclk_pll.ref = 19200; |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 7308 | dev_priv->cdclk_pll.vco = 0; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7309 | |
| 7310 | val = I915_READ(BXT_DE_PLL_ENABLE); |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 7311 | if ((val & BXT_DE_PLL_PLL_ENABLE) == 0) |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7312 | return; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7313 | |
Imre Deak | 1c3f770 | 2016-05-24 15:38:32 +0300 | [diff] [blame] | 7314 | if (WARN_ON((val & BXT_DE_PLL_LOCK) == 0)) |
| 7315 | return; |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7316 | |
| 7317 | val = I915_READ(BXT_DE_PLL_CTL); |
| 7318 | dev_priv->cdclk_pll.vco = (val & BXT_DE_PLL_RATIO_MASK) * |
| 7319 | dev_priv->cdclk_pll.ref; |
| 7320 | } |
| 7321 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7322 | static int broxton_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7323 | { |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7324 | u32 divider; |
| 7325 | int div, vco; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7326 | |
Ville Syrjälä | 83d7c81 | 2016-05-13 23:41:35 +0300 | [diff] [blame] | 7327 | bxt_de_pll_update(dev_priv); |
| 7328 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7329 | vco = dev_priv->cdclk_pll.vco; |
| 7330 | if (vco == 0) |
| 7331 | return dev_priv->cdclk_pll.ref; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7332 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7333 | divider = I915_READ(CDCLK_CTL) & BXT_CDCLK_CD2X_DIV_SEL_MASK; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7334 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7335 | switch (divider) { |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7336 | case BXT_CDCLK_CD2X_DIV_SEL_1: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7337 | div = 2; |
| 7338 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7339 | case BXT_CDCLK_CD2X_DIV_SEL_1_5: |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 7340 | WARN(IS_GEMINILAKE(dev_priv), "Unsupported divider\n"); |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7341 | div = 3; |
| 7342 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7343 | case BXT_CDCLK_CD2X_DIV_SEL_2: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7344 | div = 4; |
| 7345 | break; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7346 | case BXT_CDCLK_CD2X_DIV_SEL_4: |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7347 | div = 8; |
| 7348 | break; |
| 7349 | default: |
| 7350 | MISSING_CASE(divider); |
| 7351 | return dev_priv->cdclk_pll.ref; |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
Ville Syrjälä | f598624 | 2016-05-13 23:41:37 +0300 | [diff] [blame] | 7354 | return DIV_ROUND_CLOSEST(vco, div); |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 7355 | } |
| 7356 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7357 | static int broadwell_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7358 | { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7359 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 7360 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 7361 | |
| 7362 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 7363 | return 800000; |
| 7364 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 7365 | return 450000; |
| 7366 | else if (freq == LCPLL_CLK_FREQ_450) |
| 7367 | return 450000; |
| 7368 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 7369 | return 540000; |
| 7370 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 7371 | return 337500; |
| 7372 | else |
| 7373 | return 675000; |
| 7374 | } |
| 7375 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7376 | static int haswell_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7377 | { |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7378 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 7379 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 7380 | |
| 7381 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 7382 | return 800000; |
| 7383 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 7384 | return 450000; |
| 7385 | else if (freq == LCPLL_CLK_FREQ_450) |
| 7386 | return 450000; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7387 | else if (IS_HSW_ULT(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 7388 | return 337500; |
| 7389 | else |
| 7390 | return 540000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7391 | } |
| 7392 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7393 | static int valleyview_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 7394 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7395 | return vlv_get_cck_clock_hpll(dev_priv, "cdclk", |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 7396 | CCK_DISPLAY_CLOCK_CONTROL); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 7397 | } |
| 7398 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7399 | static int ilk_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 7400 | { |
| 7401 | return 450000; |
| 7402 | } |
| 7403 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7404 | static int i945_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7405 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7406 | return 400000; |
| 7407 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7408 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7409 | static int i915_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7410 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7411 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7412 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7413 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7414 | static int i9xx_misc_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7415 | { |
| 7416 | return 200000; |
| 7417 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7418 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7419 | static int pnv_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7420 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7421 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7422 | u16 gcfgc = 0; |
| 7423 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7424 | pci_read_config_word(pdev, GCFGC, &gcfgc); |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7425 | |
| 7426 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 7427 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7428 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7429 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7430 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7431 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7432 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7433 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 7434 | return 200000; |
| 7435 | default: |
| 7436 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 7437 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7438 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7439 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7440 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 7441 | } |
| 7442 | } |
| 7443 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7444 | static int i915gm_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7445 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7446 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7447 | u16 gcfgc = 0; |
| 7448 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7449 | pci_read_config_word(pdev, GCFGC, &gcfgc); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7450 | |
| 7451 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7452 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7453 | else { |
| 7454 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 7455 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7456 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7457 | default: |
| 7458 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 7459 | return 190000; |
| 7460 | } |
| 7461 | } |
| 7462 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7463 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7464 | static int i865_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7465 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7466 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7467 | } |
| 7468 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7469 | static int i85x_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7470 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7471 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7472 | u16 hpllcc = 0; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 7473 | |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 7474 | /* |
| 7475 | * 852GM/852GMV only supports 133 MHz and the HPLLCC |
| 7476 | * encoding is different :( |
| 7477 | * FIXME is this the right way to detect 852GM/852GMV? |
| 7478 | */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7479 | if (pdev->revision == 0x1) |
Ville Syrjälä | 65cd2b3 | 2015-05-22 11:22:32 +0300 | [diff] [blame] | 7480 | return 133333; |
| 7481 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7482 | pci_bus_read_config_word(pdev->bus, |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 7483 | PCI_DEVFN(0, 3), HPLLCC, &hpllcc); |
| 7484 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7485 | /* Assume that the hardware is in the high speed state. This |
| 7486 | * should be the default. |
| 7487 | */ |
| 7488 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 7489 | case GC_CLOCK_133_200: |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 7490 | case GC_CLOCK_133_200_2: |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7491 | case GC_CLOCK_100_200: |
| 7492 | return 200000; |
| 7493 | case GC_CLOCK_166_250: |
| 7494 | return 250000; |
| 7495 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7496 | return 133333; |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 7497 | case GC_CLOCK_133_266: |
| 7498 | case GC_CLOCK_133_266_2: |
| 7499 | case GC_CLOCK_166_266: |
| 7500 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7501 | } |
| 7502 | |
| 7503 | /* Shouldn't happen */ |
| 7504 | return 0; |
| 7505 | } |
| 7506 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7507 | static int i830_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 7508 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 7509 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7512 | static unsigned int intel_hpll_vco(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7513 | { |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7514 | static const unsigned int blb_vco[8] = { |
| 7515 | [0] = 3200000, |
| 7516 | [1] = 4000000, |
| 7517 | [2] = 5333333, |
| 7518 | [3] = 4800000, |
| 7519 | [4] = 6400000, |
| 7520 | }; |
| 7521 | static const unsigned int pnv_vco[8] = { |
| 7522 | [0] = 3200000, |
| 7523 | [1] = 4000000, |
| 7524 | [2] = 5333333, |
| 7525 | [3] = 4800000, |
| 7526 | [4] = 2666667, |
| 7527 | }; |
| 7528 | static const unsigned int cl_vco[8] = { |
| 7529 | [0] = 3200000, |
| 7530 | [1] = 4000000, |
| 7531 | [2] = 5333333, |
| 7532 | [3] = 6400000, |
| 7533 | [4] = 3333333, |
| 7534 | [5] = 3566667, |
| 7535 | [6] = 4266667, |
| 7536 | }; |
| 7537 | static const unsigned int elk_vco[8] = { |
| 7538 | [0] = 3200000, |
| 7539 | [1] = 4000000, |
| 7540 | [2] = 5333333, |
| 7541 | [3] = 4800000, |
| 7542 | }; |
| 7543 | static const unsigned int ctg_vco[8] = { |
| 7544 | [0] = 3200000, |
| 7545 | [1] = 4000000, |
| 7546 | [2] = 5333333, |
| 7547 | [3] = 6400000, |
| 7548 | [4] = 2666667, |
| 7549 | [5] = 4266667, |
| 7550 | }; |
| 7551 | const unsigned int *vco_table; |
| 7552 | unsigned int vco; |
| 7553 | uint8_t tmp = 0; |
| 7554 | |
| 7555 | /* FIXME other chipsets? */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 7556 | if (IS_GM45(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7557 | vco_table = ctg_vco; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 7558 | else if (IS_G4X(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7559 | vco_table = elk_vco; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 7560 | else if (IS_I965GM(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7561 | vco_table = cl_vco; |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7562 | else if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7563 | vco_table = pnv_vco; |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7564 | else if (IS_G33(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7565 | vco_table = blb_vco; |
| 7566 | else |
| 7567 | return 0; |
| 7568 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7569 | tmp = I915_READ(IS_MOBILE(dev_priv) ? HPLLVCO_MOBILE : HPLLVCO); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7570 | |
| 7571 | vco = vco_table[tmp & 0x7]; |
| 7572 | if (vco == 0) |
| 7573 | DRM_ERROR("Bad HPLL VCO (HPLLVCO=0x%02x)\n", tmp); |
| 7574 | else |
| 7575 | DRM_DEBUG_KMS("HPLL VCO %u kHz\n", vco); |
| 7576 | |
| 7577 | return vco; |
| 7578 | } |
| 7579 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7580 | static int gm45_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7581 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7582 | struct pci_dev *pdev = dev_priv->drm.pdev; |
| 7583 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev_priv); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7584 | uint16_t tmp = 0; |
| 7585 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7586 | pci_read_config_word(pdev, GCFGC, &tmp); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7587 | |
| 7588 | cdclk_sel = (tmp >> 12) & 0x1; |
| 7589 | |
| 7590 | switch (vco) { |
| 7591 | case 2666667: |
| 7592 | case 4000000: |
| 7593 | case 5333333: |
| 7594 | return cdclk_sel ? 333333 : 222222; |
| 7595 | case 3200000: |
| 7596 | return cdclk_sel ? 320000 : 228571; |
| 7597 | default: |
| 7598 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u, CFGC=0x%04x\n", vco, tmp); |
| 7599 | return 222222; |
| 7600 | } |
| 7601 | } |
| 7602 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7603 | static int i965gm_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7604 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7605 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7606 | static const uint8_t div_3200[] = { 16, 10, 8 }; |
| 7607 | static const uint8_t div_4000[] = { 20, 12, 10 }; |
| 7608 | static const uint8_t div_5333[] = { 24, 16, 14 }; |
| 7609 | const uint8_t *div_table; |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7610 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev_priv); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7611 | uint16_t tmp = 0; |
| 7612 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7613 | pci_read_config_word(pdev, GCFGC, &tmp); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7614 | |
| 7615 | cdclk_sel = ((tmp >> 8) & 0x1f) - 1; |
| 7616 | |
| 7617 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 7618 | goto fail; |
| 7619 | |
| 7620 | switch (vco) { |
| 7621 | case 3200000: |
| 7622 | div_table = div_3200; |
| 7623 | break; |
| 7624 | case 4000000: |
| 7625 | div_table = div_4000; |
| 7626 | break; |
| 7627 | case 5333333: |
| 7628 | div_table = div_5333; |
| 7629 | break; |
| 7630 | default: |
| 7631 | goto fail; |
| 7632 | } |
| 7633 | |
| 7634 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 7635 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 7636 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7637 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%04x\n", vco, tmp); |
| 7638 | return 200000; |
| 7639 | } |
| 7640 | |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7641 | static int g33_get_display_clock_speed(struct drm_i915_private *dev_priv) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7642 | { |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7643 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7644 | static const uint8_t div_3200[] = { 12, 10, 8, 7, 5, 16 }; |
| 7645 | static const uint8_t div_4000[] = { 14, 12, 10, 8, 6, 20 }; |
| 7646 | static const uint8_t div_4800[] = { 20, 14, 12, 10, 8, 24 }; |
| 7647 | static const uint8_t div_5333[] = { 20, 16, 12, 12, 8, 28 }; |
| 7648 | const uint8_t *div_table; |
Ville Syrjälä | 1353c4f | 2016-10-31 22:37:13 +0200 | [diff] [blame] | 7649 | unsigned int cdclk_sel, vco = intel_hpll_vco(dev_priv); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7650 | uint16_t tmp = 0; |
| 7651 | |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 7652 | pci_read_config_word(pdev, GCFGC, &tmp); |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7653 | |
| 7654 | cdclk_sel = (tmp >> 4) & 0x7; |
| 7655 | |
| 7656 | if (cdclk_sel >= ARRAY_SIZE(div_3200)) |
| 7657 | goto fail; |
| 7658 | |
| 7659 | switch (vco) { |
| 7660 | case 3200000: |
| 7661 | div_table = div_3200; |
| 7662 | break; |
| 7663 | case 4000000: |
| 7664 | div_table = div_4000; |
| 7665 | break; |
| 7666 | case 4800000: |
| 7667 | div_table = div_4800; |
| 7668 | break; |
| 7669 | case 5333333: |
| 7670 | div_table = div_5333; |
| 7671 | break; |
| 7672 | default: |
| 7673 | goto fail; |
| 7674 | } |
| 7675 | |
| 7676 | return DIV_ROUND_CLOSEST(vco, div_table[cdclk_sel]); |
| 7677 | |
Damien Lespiau | caf4e25 | 2015-06-04 16:56:18 +0100 | [diff] [blame] | 7678 | fail: |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 7679 | DRM_ERROR("Unable to determine CDCLK. HPLL VCO=%u kHz, CFGC=0x%08x\n", vco, tmp); |
| 7680 | return 190476; |
| 7681 | } |
| 7682 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7683 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7684 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7685 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7686 | while (*num > DATA_LINK_M_N_MASK || |
| 7687 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7688 | *num >>= 1; |
| 7689 | *den >>= 1; |
| 7690 | } |
| 7691 | } |
| 7692 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7693 | static void compute_m_n(unsigned int m, unsigned int n, |
| 7694 | uint32_t *ret_m, uint32_t *ret_n) |
| 7695 | { |
| 7696 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 7697 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 7698 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 7699 | } |
| 7700 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7701 | void |
| 7702 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 7703 | int pixel_clock, int link_clock, |
| 7704 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7705 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 7706 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 7707 | |
| 7708 | compute_m_n(bits_per_pixel * pixel_clock, |
| 7709 | link_clock * nlanes * 8, |
| 7710 | &m_n->gmch_m, &m_n->gmch_n); |
| 7711 | |
| 7712 | compute_m_n(pixel_clock, link_clock, |
| 7713 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7714 | } |
| 7715 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7716 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 7717 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7718 | if (i915.panel_use_ssc >= 0) |
| 7719 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7720 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 7721 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 7722 | } |
| 7723 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7724 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7725 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 7726 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7727 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7728 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7729 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 7730 | { |
| 7731 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 7732 | } |
| 7733 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7734 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7735 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 7736 | struct dpll *reduced_clock) |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7737 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7738 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7739 | u32 fp, fp2 = 0; |
| 7740 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 7741 | if (IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7742 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7743 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7744 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7745 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7746 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7747 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7748 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7749 | } |
| 7750 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7751 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7752 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7753 | crtc->lowfreq_avail = false; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7754 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7755 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7756 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7757 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7758 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7759 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 7760 | } |
| 7761 | } |
| 7762 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7763 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 7764 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7765 | { |
| 7766 | u32 reg_val; |
| 7767 | |
| 7768 | /* |
| 7769 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 7770 | * and set it to a reasonable value instead. |
| 7771 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7772 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7773 | reg_val &= 0xffffff00; |
| 7774 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7775 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7776 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7777 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7778 | reg_val &= 0x8cffffff; |
| 7779 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7780 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7781 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7782 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7783 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7784 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7785 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7786 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7787 | reg_val &= 0x00ffffff; |
| 7788 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7789 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7790 | } |
| 7791 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7792 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 7793 | struct intel_link_m_n *m_n) |
| 7794 | { |
| 7795 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7796 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7797 | int pipe = crtc->pipe; |
| 7798 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7799 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7800 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 7801 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 7802 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7803 | } |
| 7804 | |
| 7805 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7806 | struct intel_link_m_n *m_n, |
| 7807 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7808 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7809 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7810 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7811 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7812 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 7813 | if (INTEL_GEN(dev_priv) >= 5) { |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7814 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7815 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 7816 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 7817 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7818 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 7819 | * for gen < 8) and if DRRS is supported (to make sure the |
| 7820 | * registers are not unnecessarily accessed). |
| 7821 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 7822 | if (m2_n2 && (IS_CHERRYVIEW(dev_priv) || |
| 7823 | INTEL_GEN(dev_priv) < 8) && crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 7824 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 7825 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 7826 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 7827 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 7828 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 7829 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7830 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 7831 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 7832 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 7833 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 7834 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 7835 | } |
| 7836 | } |
| 7837 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7838 | 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] | 7839 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7840 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 7841 | |
| 7842 | if (m_n == M1_N1) { |
| 7843 | dp_m_n = &crtc->config->dp_m_n; |
| 7844 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 7845 | } else if (m_n == M2_N2) { |
| 7846 | |
| 7847 | /* |
| 7848 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 7849 | * needs to be programmed into M1_N1. |
| 7850 | */ |
| 7851 | dp_m_n = &crtc->config->dp_m2_n2; |
| 7852 | } else { |
| 7853 | DRM_ERROR("Unsupported divider value\n"); |
| 7854 | return; |
| 7855 | } |
| 7856 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7857 | if (crtc->config->has_pch_encoder) |
| 7858 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 7859 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 7860 | 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] | 7861 | } |
| 7862 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 7863 | static void vlv_compute_dpll(struct intel_crtc *crtc, |
| 7864 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7865 | { |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7866 | pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7867 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7868 | if (crtc->pipe != PIPE_A) |
| 7869 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7870 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7871 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 7872 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7873 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE | |
| 7874 | DPLL_EXT_BUFFER_ENABLE_VLV; |
| 7875 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7876 | pipe_config->dpll_hw_state.dpll_md = |
| 7877 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 7878 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7879 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7880 | static void chv_compute_dpll(struct intel_crtc *crtc, |
| 7881 | struct intel_crtc_state *pipe_config) |
| 7882 | { |
| 7883 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7884 | DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS; |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7885 | if (crtc->pipe != PIPE_A) |
| 7886 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 7887 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7888 | /* DPLL not used with DSI, but still need the rest set up */ |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 7889 | if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI)) |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7890 | pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE; |
| 7891 | |
Ville Syrjälä | 03ed5cbf | 2016-03-15 16:39:55 +0200 | [diff] [blame] | 7892 | pipe_config->dpll_hw_state.dpll_md = |
| 7893 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7894 | } |
| 7895 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7896 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7897 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7898 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7899 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7900 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7901 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7902 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7903 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7904 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7905 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 7906 | /* Enable Refclk */ |
| 7907 | I915_WRITE(DPLL(pipe), |
| 7908 | pipe_config->dpll_hw_state.dpll & |
| 7909 | ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV)); |
| 7910 | |
| 7911 | /* No need to actually set up the DPLL with DSI */ |
| 7912 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 7913 | return; |
| 7914 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7915 | mutex_lock(&dev_priv->sb_lock); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 7916 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7917 | bestn = pipe_config->dpll.n; |
| 7918 | bestm1 = pipe_config->dpll.m1; |
| 7919 | bestm2 = pipe_config->dpll.m2; |
| 7920 | bestp1 = pipe_config->dpll.p1; |
| 7921 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7922 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7923 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 7924 | |
| 7925 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7926 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 7927 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7928 | |
| 7929 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7930 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7931 | |
| 7932 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7933 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7934 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7935 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7936 | |
| 7937 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7938 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7939 | |
| 7940 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7941 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 7942 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 7943 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7944 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 7945 | |
| 7946 | /* |
| 7947 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 7948 | * but we don't support that). |
| 7949 | * Note: don't use the DAC post divider as it seems unstable. |
| 7950 | */ |
| 7951 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7952 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7953 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7954 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7955 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7956 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7957 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7958 | if (pipe_config->port_clock == 162000 || |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 7959 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_ANALOG) || |
| 7960 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7961 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 7962 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7963 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7964 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7965 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7966 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 7967 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7968 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7969 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7970 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7971 | 0x0df40000); |
| 7972 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7973 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7974 | 0x0df70000); |
| 7975 | } else { /* HDMI or VGA */ |
| 7976 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 7977 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7978 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7979 | 0x0df70000); |
| 7980 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7981 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7982 | 0x0df40000); |
| 7983 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7984 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7985 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7986 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 7987 | if (intel_crtc_has_dp_encoder(crtc->config)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7988 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7989 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 7990 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7991 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 7992 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 7993 | } |
| 7994 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 7995 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7996 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 7997 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7998 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 7999 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 8000 | enum pipe pipe = crtc->pipe; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8001 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8002 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8003 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 8004 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8005 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8006 | |
Ville Syrjälä | cd2d34d | 2016-04-12 22:14:34 +0300 | [diff] [blame] | 8007 | /* Enable Refclk and SSC */ |
| 8008 | I915_WRITE(DPLL(pipe), |
| 8009 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 8010 | |
| 8011 | /* No need to actually set up the DPLL with DSI */ |
| 8012 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 8013 | return; |
| 8014 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8015 | bestn = pipe_config->dpll.n; |
| 8016 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 8017 | bestm1 = pipe_config->dpll.m1; |
| 8018 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 8019 | bestp1 = pipe_config->dpll.p1; |
| 8020 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8021 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 8022 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8023 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8024 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8025 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8026 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8027 | /* p1 and p2 divider */ |
| 8028 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 8029 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 8030 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 8031 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 8032 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 8033 | |
| 8034 | /* Feedback post-divider - m2 */ |
| 8035 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 8036 | |
| 8037 | /* Feedback refclk divider - n and m1 */ |
| 8038 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 8039 | DPIO_CHV_M1_DIV_BY_2 | |
| 8040 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 8041 | |
| 8042 | /* M2 fraction division */ |
Ville Syrjälä | 25a25df | 2015-07-08 23:45:47 +0300 | [diff] [blame] | 8043 | 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] | 8044 | |
| 8045 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 8046 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 8047 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 8048 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 8049 | if (bestm2_frac) |
| 8050 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 8051 | 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] | 8052 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 8053 | /* Program digital lock detect threshold */ |
| 8054 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 8055 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 8056 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 8057 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 8058 | if (!bestm2_frac) |
| 8059 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 8060 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 8061 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8062 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8063 | if (vco == 5400000) { |
| 8064 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 8065 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 8066 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 8067 | tribuf_calcntr = 0x9; |
| 8068 | } else if (vco <= 6200000) { |
| 8069 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 8070 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 8071 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 8072 | tribuf_calcntr = 0x9; |
| 8073 | } else if (vco <= 6480000) { |
| 8074 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 8075 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 8076 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 8077 | tribuf_calcntr = 0x8; |
| 8078 | } else { |
| 8079 | /* Not supported. Apply the same limits as in the max case */ |
| 8080 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 8081 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 8082 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 8083 | tribuf_calcntr = 0; |
| 8084 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8085 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 8086 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 8087 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 8088 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 8089 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 8090 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 8091 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8092 | /* AFC Recal */ |
| 8093 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 8094 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 8095 | DPIO_AFC_RECAL); |
| 8096 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8097 | mutex_unlock(&dev_priv->sb_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 8098 | } |
| 8099 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8100 | /** |
| 8101 | * vlv_force_pll_on - forcibly enable just the PLL |
| 8102 | * @dev_priv: i915 private structure |
| 8103 | * @pipe: pipe PLL to enable |
| 8104 | * @dpll: PLL configuration |
| 8105 | * |
| 8106 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 8107 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 8108 | * be enabled. |
| 8109 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 8110 | int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe, |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 8111 | const struct dpll *dpll) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8112 | { |
Ville Syrjälä | b91eb5c | 2016-10-31 22:37:09 +0200 | [diff] [blame] | 8113 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 8114 | struct intel_crtc_state *pipe_config; |
| 8115 | |
| 8116 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 8117 | if (!pipe_config) |
| 8118 | return -ENOMEM; |
| 8119 | |
| 8120 | pipe_config->base.crtc = &crtc->base; |
| 8121 | pipe_config->pixel_multiplier = 1; |
| 8122 | pipe_config->dpll = *dpll; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8123 | |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 8124 | if (IS_CHERRYVIEW(dev_priv)) { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 8125 | chv_compute_dpll(crtc, pipe_config); |
| 8126 | chv_prepare_pll(crtc, pipe_config); |
| 8127 | chv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8128 | } else { |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 8129 | vlv_compute_dpll(crtc, pipe_config); |
| 8130 | vlv_prepare_pll(crtc, pipe_config); |
| 8131 | vlv_enable_pll(crtc, pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8132 | } |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 8133 | |
| 8134 | kfree(pipe_config); |
| 8135 | |
| 8136 | return 0; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8137 | } |
| 8138 | |
| 8139 | /** |
| 8140 | * vlv_force_pll_off - forcibly disable just the PLL |
| 8141 | * @dev_priv: i915 private structure |
| 8142 | * @pipe: pipe PLL to disable |
| 8143 | * |
| 8144 | * Disable the PLL for @pipe. To be used in cases where we need |
| 8145 | * the PLL enabled even when @pipe is not going to be enabled. |
| 8146 | */ |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 8147 | void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8148 | { |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 8149 | if (IS_CHERRYVIEW(dev_priv)) |
| 8150 | chv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8151 | else |
Ville Syrjälä | 30ad981 | 2016-10-31 22:37:07 +0200 | [diff] [blame] | 8152 | vlv_disable_pll(dev_priv, pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 8153 | } |
| 8154 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 8155 | static void i9xx_compute_dpll(struct intel_crtc *crtc, |
| 8156 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8157 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8158 | { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8159 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8160 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8161 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8162 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8163 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 8164 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8165 | dpll = DPLL_VGA_MODE_DIS; |
| 8166 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8167 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8168 | dpll |= DPLLB_MODE_LVDS; |
| 8169 | else |
| 8170 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 8171 | |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8172 | if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
| 8173 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8174 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8175 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8176 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8177 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 8178 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 8179 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8180 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 8181 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 8182 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8183 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8184 | |
| 8185 | /* compute bitmask from p1 value */ |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8186 | if (IS_PINEVIEW(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8187 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 8188 | else { |
| 8189 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 8190 | if (IS_G4X(dev_priv) && reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8191 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 8192 | } |
| 8193 | switch (clock->p2) { |
| 8194 | case 5: |
| 8195 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 8196 | break; |
| 8197 | case 7: |
| 8198 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 8199 | break; |
| 8200 | case 10: |
| 8201 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 8202 | break; |
| 8203 | case 14: |
| 8204 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 8205 | break; |
| 8206 | } |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8207 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8208 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 8209 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8210 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8211 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8212 | else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8213 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8214 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 8215 | else |
| 8216 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8217 | |
| 8218 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8219 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8220 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 8221 | if (INTEL_GEN(dev_priv) >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8222 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 8223 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8224 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8225 | } |
| 8226 | } |
| 8227 | |
Daniel Vetter | 251ac86 | 2015-06-18 10:30:24 +0200 | [diff] [blame] | 8228 | static void i8xx_compute_dpll(struct intel_crtc *crtc, |
| 8229 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8230 | struct dpll *reduced_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8231 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8232 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8233 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8234 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8235 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8236 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8237 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 8238 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8239 | dpll = DPLL_VGA_MODE_DIS; |
| 8240 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8241 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8242 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 8243 | } else { |
| 8244 | if (clock->p1 == 2) |
| 8245 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 8246 | else |
| 8247 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 8248 | if (clock->p2 == 4) |
| 8249 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 8250 | } |
| 8251 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8252 | if (!IS_I830(dev_priv) && |
| 8253 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 8254 | dpll |= DPLL_DVO_2X_MODE; |
| 8255 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8256 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ceb4100 | 2016-03-21 18:00:02 +0200 | [diff] [blame] | 8257 | intel_panel_use_ssc(dev_priv)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8258 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 8259 | else |
| 8260 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 8261 | |
| 8262 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8263 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 8264 | } |
| 8265 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 8266 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8267 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8268 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8269 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8270 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 8271 | 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] | 8272 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 8273 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 8274 | |
| 8275 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 8276 | * the hw state checker will get angry at the mismatch. */ |
| 8277 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 8278 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8279 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 8280 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8281 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 8282 | crtc_vtotal -= 1; |
| 8283 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 8284 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8285 | if (intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 8286 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 8287 | else |
| 8288 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 8289 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 8290 | if (vsyncshift < 0) |
| 8291 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8292 | } |
| 8293 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8294 | if (INTEL_GEN(dev_priv) > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8295 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8296 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8297 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8298 | (adjusted_mode->crtc_hdisplay - 1) | |
| 8299 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8300 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8301 | (adjusted_mode->crtc_hblank_start - 1) | |
| 8302 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8303 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8304 | (adjusted_mode->crtc_hsync_start - 1) | |
| 8305 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 8306 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8307 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8308 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 8309 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8310 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8311 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 8312 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8313 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8314 | (adjusted_mode->crtc_vsync_start - 1) | |
| 8315 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 8316 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 8317 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 8318 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 8319 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 8320 | * bits. */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 8321 | if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP && |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 8322 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 8323 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 8324 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8325 | } |
| 8326 | |
| 8327 | static void intel_set_pipe_src_size(struct intel_crtc *intel_crtc) |
| 8328 | { |
| 8329 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8330 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8331 | enum pipe pipe = intel_crtc->pipe; |
| 8332 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8333 | /* pipesrc controls the size that is scaled from, which should |
| 8334 | * always be the user's requested size. |
| 8335 | */ |
| 8336 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8337 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 8338 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 8339 | } |
| 8340 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8341 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8342 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8343 | { |
| 8344 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8345 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8346 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 8347 | uint32_t tmp; |
| 8348 | |
| 8349 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8350 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 8351 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8352 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8353 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 8354 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8355 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8356 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 8357 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8358 | |
| 8359 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8360 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 8361 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8362 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8363 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 8364 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8365 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8366 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 8367 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8368 | |
| 8369 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8370 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 8371 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 8372 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8373 | } |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | static void intel_get_pipe_src_size(struct intel_crtc *crtc, |
| 8377 | struct intel_crtc_state *pipe_config) |
| 8378 | { |
| 8379 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8380 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8381 | u32 tmp; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8382 | |
| 8383 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 8384 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 8385 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 8386 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8387 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 8388 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8389 | } |
| 8390 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 8391 | 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] | 8392 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 8393 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8394 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 8395 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 8396 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 8397 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 8398 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8399 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 8400 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 8401 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 8402 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 8403 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8404 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 8405 | mode->type = DRM_MODE_TYPE_DRIVER; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 8406 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 8407 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 8408 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Maarten Lankhorst | cd13f5a | 2015-07-14 14:12:02 +0200 | [diff] [blame] | 8409 | |
| 8410 | mode->hsync = drm_mode_hsync(mode); |
| 8411 | mode->vrefresh = drm_mode_vrefresh(mode); |
| 8412 | drm_mode_set_name(mode); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 8413 | } |
| 8414 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8415 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 8416 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8417 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8418 | uint32_t pipeconf; |
| 8419 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 8420 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8421 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 8422 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 8423 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 8424 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 8425 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8426 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 8427 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8428 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 8429 | /* only g4x and later have fancy bpc/dither controls */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 8430 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 8431 | IS_CHERRYVIEW(dev_priv)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 8432 | /* 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] | 8433 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 8434 | pipeconf |= PIPECONF_DITHER_EN | |
| 8435 | PIPECONF_DITHER_TYPE_SP; |
| 8436 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8437 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 8438 | case 18: |
| 8439 | pipeconf |= PIPECONF_6BPC; |
| 8440 | break; |
| 8441 | case 24: |
| 8442 | pipeconf |= PIPECONF_8BPC; |
| 8443 | break; |
| 8444 | case 30: |
| 8445 | pipeconf |= PIPECONF_10BPC; |
| 8446 | break; |
| 8447 | default: |
| 8448 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 8449 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8450 | } |
| 8451 | } |
| 8452 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 8453 | if (HAS_PIPE_CXSR(dev_priv)) { |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8454 | if (intel_crtc->lowfreq_avail) { |
| 8455 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 8456 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 8457 | } else { |
| 8458 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8459 | } |
| 8460 | } |
| 8461 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8462 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8463 | if (INTEL_GEN(dev_priv) < 4 || |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8464 | intel_crtc_has_type(intel_crtc->config, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 8465 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 8466 | else |
| 8467 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 8468 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8469 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 8470 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8471 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8472 | intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 8473 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 8474 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 8475 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 8476 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 8477 | } |
| 8478 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8479 | static int i8xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 8480 | struct intel_crtc_state *crtc_state) |
| 8481 | { |
| 8482 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8483 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8484 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8485 | int refclk = 48000; |
| 8486 | |
| 8487 | memset(&crtc_state->dpll_hw_state, 0, |
| 8488 | sizeof(crtc_state->dpll_hw_state)); |
| 8489 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8490 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8491 | if (intel_panel_use_ssc(dev_priv)) { |
| 8492 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8493 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 8494 | } |
| 8495 | |
| 8496 | limit = &intel_limits_i8xx_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8497 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) { |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8498 | limit = &intel_limits_i8xx_dvo; |
| 8499 | } else { |
| 8500 | limit = &intel_limits_i8xx_dac; |
| 8501 | } |
| 8502 | |
| 8503 | if (!crtc_state->clock_set && |
| 8504 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8505 | refclk, NULL, &crtc_state->dpll)) { |
| 8506 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8507 | return -EINVAL; |
| 8508 | } |
| 8509 | |
| 8510 | i8xx_compute_dpll(crtc, crtc_state, NULL); |
| 8511 | |
| 8512 | return 0; |
| 8513 | } |
| 8514 | |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 8515 | static int g4x_crtc_compute_clock(struct intel_crtc *crtc, |
| 8516 | struct intel_crtc_state *crtc_state) |
| 8517 | { |
| 8518 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8519 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8520 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 8521 | int refclk = 96000; |
| 8522 | |
| 8523 | memset(&crtc_state->dpll_hw_state, 0, |
| 8524 | sizeof(crtc_state->dpll_hw_state)); |
| 8525 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8526 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 8527 | if (intel_panel_use_ssc(dev_priv)) { |
| 8528 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8529 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 8530 | } |
| 8531 | |
| 8532 | if (intel_is_dual_link_lvds(dev)) |
| 8533 | limit = &intel_limits_g4x_dual_channel_lvds; |
| 8534 | else |
| 8535 | limit = &intel_limits_g4x_single_channel_lvds; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8536 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 8537 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 8538 | limit = &intel_limits_g4x_hdmi; |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8539 | } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 8540 | limit = &intel_limits_g4x_sdvo; |
| 8541 | } else { |
| 8542 | /* The option is for other outputs */ |
| 8543 | limit = &intel_limits_i9xx_sdvo; |
| 8544 | } |
| 8545 | |
| 8546 | if (!crtc_state->clock_set && |
| 8547 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8548 | refclk, NULL, &crtc_state->dpll)) { |
| 8549 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8550 | return -EINVAL; |
| 8551 | } |
| 8552 | |
| 8553 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 8554 | |
| 8555 | return 0; |
| 8556 | } |
| 8557 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8558 | static int pnv_crtc_compute_clock(struct intel_crtc *crtc, |
| 8559 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8560 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8561 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8562 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8563 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8564 | int refclk = 96000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8565 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 8566 | memset(&crtc_state->dpll_hw_state, 0, |
| 8567 | sizeof(crtc_state->dpll_hw_state)); |
| 8568 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8569 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8570 | if (intel_panel_use_ssc(dev_priv)) { |
| 8571 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8572 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
| 8573 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8574 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8575 | limit = &intel_limits_pineview_lvds; |
| 8576 | } else { |
| 8577 | limit = &intel_limits_pineview_sdvo; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8578 | } |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 8579 | |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8580 | if (!crtc_state->clock_set && |
| 8581 | !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8582 | refclk, NULL, &crtc_state->dpll)) { |
| 8583 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8584 | return -EINVAL; |
| 8585 | } |
| 8586 | |
| 8587 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
| 8588 | |
| 8589 | return 0; |
| 8590 | } |
| 8591 | |
| 8592 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 8593 | struct intel_crtc_state *crtc_state) |
| 8594 | { |
| 8595 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8596 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8597 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8598 | int refclk = 96000; |
| 8599 | |
| 8600 | memset(&crtc_state->dpll_hw_state, 0, |
| 8601 | sizeof(crtc_state->dpll_hw_state)); |
| 8602 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 8603 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8604 | if (intel_panel_use_ssc(dev_priv)) { |
| 8605 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 8606 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 8607 | } |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 8608 | |
| 8609 | limit = &intel_limits_i9xx_lvds; |
| 8610 | } else { |
| 8611 | limit = &intel_limits_i9xx_sdvo; |
| 8612 | } |
| 8613 | |
| 8614 | if (!crtc_state->clock_set && |
| 8615 | !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8616 | refclk, NULL, &crtc_state->dpll)) { |
| 8617 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8618 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8619 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8620 | |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 8621 | i9xx_compute_dpll(crtc, crtc_state, NULL); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8622 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8623 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8624 | } |
| 8625 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8626 | static int chv_crtc_compute_clock(struct intel_crtc *crtc, |
| 8627 | struct intel_crtc_state *crtc_state) |
| 8628 | { |
| 8629 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8630 | const struct intel_limit *limit = &intel_limits_chv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8631 | |
| 8632 | memset(&crtc_state->dpll_hw_state, 0, |
| 8633 | sizeof(crtc_state->dpll_hw_state)); |
| 8634 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8635 | if (!crtc_state->clock_set && |
| 8636 | !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8637 | refclk, NULL, &crtc_state->dpll)) { |
| 8638 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8639 | return -EINVAL; |
| 8640 | } |
| 8641 | |
| 8642 | chv_compute_dpll(crtc, crtc_state); |
| 8643 | |
| 8644 | return 0; |
| 8645 | } |
| 8646 | |
| 8647 | static int vlv_crtc_compute_clock(struct intel_crtc *crtc, |
| 8648 | struct intel_crtc_state *crtc_state) |
| 8649 | { |
| 8650 | int refclk = 100000; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 8651 | const struct intel_limit *limit = &intel_limits_vlv; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8652 | |
| 8653 | memset(&crtc_state->dpll_hw_state, 0, |
| 8654 | sizeof(crtc_state->dpll_hw_state)); |
| 8655 | |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 8656 | if (!crtc_state->clock_set && |
| 8657 | !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 8658 | refclk, NULL, &crtc_state->dpll)) { |
| 8659 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8660 | return -EINVAL; |
| 8661 | } |
| 8662 | |
| 8663 | vlv_compute_dpll(crtc, crtc_state); |
| 8664 | |
| 8665 | return 0; |
| 8666 | } |
| 8667 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8668 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8669 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8670 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8671 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8672 | uint32_t tmp; |
| 8673 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8674 | if (INTEL_GEN(dev_priv) <= 3 && |
| 8675 | (IS_I830(dev_priv) || !IS_MOBILE(dev_priv))) |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 8676 | return; |
| 8677 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8678 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8679 | if (!(tmp & PFIT_ENABLE)) |
| 8680 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8681 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8682 | /* Check whether the pfit is attached to our pipe. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8683 | if (INTEL_GEN(dev_priv) < 4) { |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8684 | if (crtc->pipe != PIPE_B) |
| 8685 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8686 | } else { |
| 8687 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 8688 | return; |
| 8689 | } |
| 8690 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 8691 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8692 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8693 | } |
| 8694 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8695 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8696 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8697 | { |
| 8698 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8699 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8700 | int pipe = pipe_config->cpu_transcoder; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8701 | struct dpll clock; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8702 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 8703 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8704 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8705 | /* In case of DSI, DPLL will not be used */ |
| 8706 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 8707 | return; |
| 8708 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8709 | mutex_lock(&dev_priv->sb_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 8710 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8711 | mutex_unlock(&dev_priv->sb_lock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8712 | |
| 8713 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 8714 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 8715 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 8716 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 8717 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 8718 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8719 | pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8720 | } |
| 8721 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8722 | static void |
| 8723 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 8724 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8725 | { |
| 8726 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8727 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8728 | u32 val, base, offset; |
| 8729 | int pipe = crtc->pipe, plane = crtc->plane; |
| 8730 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8731 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8732 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8733 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8734 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8735 | val = I915_READ(DSPCNTR(plane)); |
| 8736 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8737 | return; |
| 8738 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8739 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8740 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8741 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8742 | return; |
| 8743 | } |
| 8744 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8745 | fb = &intel_fb->base; |
| 8746 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8747 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8748 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8749 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8750 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8751 | } |
| 8752 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8753 | |
| 8754 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8755 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8756 | fb->pixel_format = fourcc; |
| 8757 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8758 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8759 | if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8760 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8761 | offset = I915_READ(DSPTILEOFF(plane)); |
| 8762 | else |
| 8763 | offset = I915_READ(DSPLINOFF(plane)); |
| 8764 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 8765 | } else { |
| 8766 | base = I915_READ(DSPADDR(plane)); |
| 8767 | } |
| 8768 | plane_config->base = base; |
| 8769 | |
| 8770 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8771 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8772 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8773 | |
| 8774 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8775 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8776 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8777 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8778 | fb->pixel_format, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 8779 | fb->modifier); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8780 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8781 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8782 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8783 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8784 | pipe_name(pipe), plane, fb->width, fb->height, |
| 8785 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8786 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8787 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8788 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 8789 | } |
| 8790 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8791 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8792 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8793 | { |
| 8794 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 8795 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8796 | int pipe = pipe_config->cpu_transcoder; |
| 8797 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 8798 | struct dpll clock; |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8799 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8800 | int refclk = 100000; |
| 8801 | |
Ville Syrjälä | b521973 | 2016-03-15 16:40:01 +0200 | [diff] [blame] | 8802 | /* In case of DSI, DPLL will not be used */ |
| 8803 | if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0) |
| 8804 | return; |
| 8805 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 8806 | mutex_lock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8807 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 8808 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 8809 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 8810 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
Imre Deak | 0d7b6b1 | 2015-07-02 14:29:58 +0300 | [diff] [blame] | 8811 | 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] | 8812 | mutex_unlock(&dev_priv->sb_lock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8813 | |
| 8814 | 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] | 8815 | clock.m2 = (pll_dw0 & 0xff) << 22; |
| 8816 | if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN) |
| 8817 | clock.m2 |= pll_dw2 & 0x3fffff; |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8818 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 8819 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 8820 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 8821 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 8822 | pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock); |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8823 | } |
| 8824 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8825 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8826 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8827 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8828 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8829 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8830 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8831 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8832 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8833 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 8834 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8835 | return false; |
| 8836 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8837 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 8838 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8839 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8840 | ret = false; |
| 8841 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8842 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8843 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8844 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8845 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 8846 | if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 8847 | IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8848 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8849 | case PIPECONF_6BPC: |
| 8850 | pipe_config->pipe_bpp = 18; |
| 8851 | break; |
| 8852 | case PIPECONF_8BPC: |
| 8853 | pipe_config->pipe_bpp = 24; |
| 8854 | break; |
| 8855 | case PIPECONF_10BPC: |
| 8856 | pipe_config->pipe_bpp = 30; |
| 8857 | break; |
| 8858 | default: |
| 8859 | break; |
| 8860 | } |
| 8861 | } |
| 8862 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8863 | if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) && |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 8864 | (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8865 | pipe_config->limited_color_range = true; |
| 8866 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8867 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 8868 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 8869 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8870 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 8871 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8872 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8873 | i9xx_get_pfit_config(crtc, pipe_config); |
| 8874 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 8875 | if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8876 | /* No way to read it out on pipes B and C */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8877 | if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A) |
Ville Syrjälä | c231775 | 2016-03-15 16:39:56 +0200 | [diff] [blame] | 8878 | tmp = dev_priv->chv_dpll_md[crtc->pipe]; |
| 8879 | else |
| 8880 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8881 | pipe_config->pixel_multiplier = |
| 8882 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 8883 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8884 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8885 | } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) || |
Jani Nikula | 73f67aa | 2016-12-07 22:48:09 +0200 | [diff] [blame] | 8886 | IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) { |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8887 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 8888 | pipe_config->pixel_multiplier = |
| 8889 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 8890 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 8891 | } else { |
| 8892 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 8893 | * port and will be fixed up in the encoder->get_config |
| 8894 | * function. */ |
| 8895 | pipe_config->pixel_multiplier = 1; |
| 8896 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8897 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8898 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8899 | /* |
| 8900 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 8901 | * on 830. Filter it out here so that we don't |
| 8902 | * report errors due to that. |
| 8903 | */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 8904 | if (IS_I830(dev_priv)) |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 8905 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 8906 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8907 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 8908 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 8909 | } else { |
| 8910 | /* Mask out read-only status bits. */ |
| 8911 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 8912 | DPLL_PORTC_READY_MASK | |
| 8913 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8914 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8915 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 8916 | if (IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 8917 | chv_crtc_clock_get(crtc, pipe_config); |
Tvrtko Ursulin | 11a914c | 2016-10-13 11:03:08 +0100 | [diff] [blame] | 8918 | else if (IS_VALLEYVIEW(dev_priv)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 8919 | vlv_crtc_clock_get(crtc, pipe_config); |
| 8920 | else |
| 8921 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8922 | |
Ville Syrjälä | 0f64614 | 2015-08-26 19:39:18 +0300 | [diff] [blame] | 8923 | /* |
| 8924 | * Normally the dotclock is filled in by the encoder .get_config() |
| 8925 | * but in case the pipe is enabled w/o any ports we need a sane |
| 8926 | * default. |
| 8927 | */ |
| 8928 | pipe_config->base.adjusted_mode.crtc_clock = |
| 8929 | pipe_config->port_clock / pipe_config->pixel_multiplier; |
| 8930 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 8931 | ret = true; |
| 8932 | |
| 8933 | out: |
| 8934 | intel_display_power_put(dev_priv, power_domain); |
| 8935 | |
| 8936 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8937 | } |
| 8938 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8939 | static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8940 | { |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8941 | struct intel_encoder *encoder; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8942 | int i; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8943 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8944 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8945 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8946 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8947 | bool has_ck505 = false; |
| 8948 | bool can_ssc = false; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8949 | bool using_ssc_source = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8950 | |
| 8951 | /* We need to take the global config into account */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 8952 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8953 | switch (encoder->type) { |
| 8954 | case INTEL_OUTPUT_LVDS: |
| 8955 | has_panel = true; |
| 8956 | has_lvds = true; |
| 8957 | break; |
| 8958 | case INTEL_OUTPUT_EDP: |
| 8959 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 8960 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 8961 | has_cpu_edp = true; |
| 8962 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 8963 | default: |
| 8964 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8965 | } |
| 8966 | } |
| 8967 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 8968 | if (HAS_PCH_IBX(dev_priv)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 8969 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 8970 | can_ssc = has_ck505; |
| 8971 | } else { |
| 8972 | has_ck505 = false; |
| 8973 | can_ssc = true; |
| 8974 | } |
| 8975 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 8976 | /* Check if any DPLLs are using the SSC source */ |
| 8977 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8978 | u32 temp = I915_READ(PCH_DPLL(i)); |
| 8979 | |
| 8980 | if (!(temp & DPLL_VCO_ENABLE)) |
| 8981 | continue; |
| 8982 | |
| 8983 | if ((temp & PLL_REF_INPUT_MASK) == |
| 8984 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 8985 | using_ssc_source = true; |
| 8986 | break; |
| 8987 | } |
| 8988 | } |
| 8989 | |
| 8990 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n", |
| 8991 | has_panel, has_lvds, has_ck505, using_ssc_source); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8992 | |
| 8993 | /* Ironlake: try to setup display ref clock before DPLL |
| 8994 | * enabling. This is only under driver's control after |
| 8995 | * PCH B stepping, previous chipset stepping should be |
| 8996 | * ignoring this setting. |
| 8997 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 8998 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 8999 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9000 | /* As we must carefully and slowly disable/enable each source in turn, |
| 9001 | * compute the final state we want first and check if we need to |
| 9002 | * make any changes at all. |
| 9003 | */ |
| 9004 | final = val; |
| 9005 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 9006 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9007 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 9008 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9009 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 9010 | |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 9011 | final &= ~DREF_SSC_SOURCE_MASK; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9012 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Daniel Vetter | 8c07eb6 | 2016-06-09 18:39:07 +0200 | [diff] [blame] | 9013 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 9014 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9015 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9016 | final |= DREF_SSC_SOURCE_ENABLE; |
| 9017 | |
| 9018 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 9019 | final |= DREF_SSC1_ENABLE; |
| 9020 | |
| 9021 | if (has_cpu_edp) { |
| 9022 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 9023 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 9024 | else |
| 9025 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 9026 | } else |
| 9027 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 9028 | } else if (using_ssc_source) { |
| 9029 | final |= DREF_SSC_SOURCE_ENABLE; |
| 9030 | final |= DREF_SSC1_ENABLE; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9031 | } |
| 9032 | |
| 9033 | if (final == val) |
| 9034 | return; |
| 9035 | |
| 9036 | /* Always enable nonspread source */ |
| 9037 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 9038 | |
| 9039 | if (has_ck505) |
| 9040 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 9041 | else |
| 9042 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 9043 | |
| 9044 | if (has_panel) { |
| 9045 | val &= ~DREF_SSC_SOURCE_MASK; |
| 9046 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 9047 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9048 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 9049 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9050 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9051 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 9052 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9053 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9054 | |
| 9055 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9056 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9057 | POSTING_READ(PCH_DREF_CONTROL); |
| 9058 | udelay(200); |
| 9059 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9060 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 9061 | |
| 9062 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9063 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 9064 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9065 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9066 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9067 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9068 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9069 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9070 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9071 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9072 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9073 | POSTING_READ(PCH_DREF_CONTROL); |
| 9074 | udelay(200); |
| 9075 | } else { |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 9076 | DRM_DEBUG_KMS("Disabling CPU source output\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9077 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9078 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9079 | |
| 9080 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9081 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9082 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9083 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9084 | POSTING_READ(PCH_DREF_CONTROL); |
| 9085 | udelay(200); |
| 9086 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 9087 | if (!using_ssc_source) { |
| 9088 | DRM_DEBUG_KMS("Disabling SSC source\n"); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9089 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 9090 | /* Turn off the SSC source */ |
| 9091 | val &= ~DREF_SSC_SOURCE_MASK; |
| 9092 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 9093 | |
Lyude | 1c1a24d | 2016-06-14 11:04:09 -0400 | [diff] [blame] | 9094 | /* Turn off SSC1 */ |
| 9095 | val &= ~DREF_SSC1_ENABLE; |
| 9096 | |
| 9097 | I915_WRITE(PCH_DREF_CONTROL, val); |
| 9098 | POSTING_READ(PCH_DREF_CONTROL); |
| 9099 | udelay(200); |
| 9100 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 9101 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 9102 | |
| 9103 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 9104 | } |
| 9105 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9106 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9107 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9108 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9109 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9110 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 9111 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 9112 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9113 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 9114 | if (wait_for_us(I915_READ(SOUTH_CHICKEN2) & |
| 9115 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9116 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9117 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9118 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 9119 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 9120 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9121 | |
Imre Deak | cf3598c | 2016-06-28 13:37:31 +0300 | [diff] [blame] | 9122 | if (wait_for_us((I915_READ(SOUTH_CHICKEN2) & |
| 9123 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9124 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9125 | } |
| 9126 | |
| 9127 | /* WaMPhyProgramming:hsw */ |
| 9128 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 9129 | { |
| 9130 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9131 | |
| 9132 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 9133 | tmp &= ~(0xFF << 24); |
| 9134 | tmp |= (0x12 << 24); |
| 9135 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 9136 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9137 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 9138 | tmp |= (1 << 11); |
| 9139 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 9140 | |
| 9141 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 9142 | tmp |= (1 << 11); |
| 9143 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 9144 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9145 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 9146 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 9147 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 9148 | |
| 9149 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 9150 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 9151 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 9152 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9153 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 9154 | tmp &= ~(7 << 13); |
| 9155 | tmp |= (5 << 13); |
| 9156 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9157 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9158 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 9159 | tmp &= ~(7 << 13); |
| 9160 | tmp |= (5 << 13); |
| 9161 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9162 | |
| 9163 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 9164 | tmp &= ~0xFF; |
| 9165 | tmp |= 0x1C; |
| 9166 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 9167 | |
| 9168 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 9169 | tmp &= ~0xFF; |
| 9170 | tmp |= 0x1C; |
| 9171 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 9172 | |
| 9173 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 9174 | tmp &= ~(0xFF << 16); |
| 9175 | tmp |= (0x1C << 16); |
| 9176 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 9177 | |
| 9178 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 9179 | tmp &= ~(0xFF << 16); |
| 9180 | tmp |= (0x1C << 16); |
| 9181 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 9182 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9183 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 9184 | tmp |= (1 << 27); |
| 9185 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9186 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9187 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 9188 | tmp |= (1 << 27); |
| 9189 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9190 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9191 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 9192 | tmp &= ~(0xF << 28); |
| 9193 | tmp |= (4 << 28); |
| 9194 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9195 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 9196 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 9197 | tmp &= ~(0xF << 28); |
| 9198 | tmp |= (4 << 28); |
| 9199 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9200 | } |
| 9201 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9202 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 9203 | * Programming" based on the parameters passed: |
| 9204 | * - Sequence to enable CLKOUT_DP |
| 9205 | * - Sequence to enable CLKOUT_DP without spread |
| 9206 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 9207 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9208 | static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv, |
| 9209 | bool with_spread, bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9210 | { |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9211 | uint32_t reg, tmp; |
| 9212 | |
| 9213 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 9214 | with_spread = true; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9215 | if (WARN(HAS_PCH_LPT_LP(dev_priv) && |
| 9216 | with_fdi, "LP PCH doesn't have FDI\n")) |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9217 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9218 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 9219 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9220 | |
| 9221 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 9222 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 9223 | tmp |= SBI_SSCCTL_PATHALT; |
| 9224 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 9225 | |
| 9226 | udelay(24); |
| 9227 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9228 | if (with_spread) { |
| 9229 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 9230 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 9231 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 9232 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9233 | if (with_fdi) { |
| 9234 | lpt_reset_fdi_mphy(dev_priv); |
| 9235 | lpt_program_fdi_mphy(dev_priv); |
| 9236 | } |
| 9237 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9238 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9239 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 9240 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 9241 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 9242 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 9243 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 9244 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9245 | } |
| 9246 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9247 | /* Sequence to disable CLKOUT_DP */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9248 | static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9249 | { |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9250 | uint32_t reg, tmp; |
| 9251 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 9252 | mutex_lock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9253 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 9254 | reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0; |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9255 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 9256 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 9257 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 9258 | |
| 9259 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 9260 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 9261 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 9262 | tmp |= SBI_SSCCTL_PATHALT; |
| 9263 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 9264 | udelay(32); |
| 9265 | } |
| 9266 | tmp |= SBI_SSCCTL_DISABLE; |
| 9267 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 9268 | } |
| 9269 | |
Ville Syrjälä | a580516 | 2015-05-26 20:42:30 +0300 | [diff] [blame] | 9270 | mutex_unlock(&dev_priv->sb_lock); |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 9271 | } |
| 9272 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 9273 | #define BEND_IDX(steps) ((50 + (steps)) / 5) |
| 9274 | |
| 9275 | static const uint16_t sscdivintphase[] = { |
| 9276 | [BEND_IDX( 50)] = 0x3B23, |
| 9277 | [BEND_IDX( 45)] = 0x3B23, |
| 9278 | [BEND_IDX( 40)] = 0x3C23, |
| 9279 | [BEND_IDX( 35)] = 0x3C23, |
| 9280 | [BEND_IDX( 30)] = 0x3D23, |
| 9281 | [BEND_IDX( 25)] = 0x3D23, |
| 9282 | [BEND_IDX( 20)] = 0x3E23, |
| 9283 | [BEND_IDX( 15)] = 0x3E23, |
| 9284 | [BEND_IDX( 10)] = 0x3F23, |
| 9285 | [BEND_IDX( 5)] = 0x3F23, |
| 9286 | [BEND_IDX( 0)] = 0x0025, |
| 9287 | [BEND_IDX( -5)] = 0x0025, |
| 9288 | [BEND_IDX(-10)] = 0x0125, |
| 9289 | [BEND_IDX(-15)] = 0x0125, |
| 9290 | [BEND_IDX(-20)] = 0x0225, |
| 9291 | [BEND_IDX(-25)] = 0x0225, |
| 9292 | [BEND_IDX(-30)] = 0x0325, |
| 9293 | [BEND_IDX(-35)] = 0x0325, |
| 9294 | [BEND_IDX(-40)] = 0x0425, |
| 9295 | [BEND_IDX(-45)] = 0x0425, |
| 9296 | [BEND_IDX(-50)] = 0x0525, |
| 9297 | }; |
| 9298 | |
| 9299 | /* |
| 9300 | * Bend CLKOUT_DP |
| 9301 | * steps -50 to 50 inclusive, in steps of 5 |
| 9302 | * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz) |
| 9303 | * change in clock period = -(steps / 10) * 5.787 ps |
| 9304 | */ |
| 9305 | static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps) |
| 9306 | { |
| 9307 | uint32_t tmp; |
| 9308 | int idx = BEND_IDX(steps); |
| 9309 | |
| 9310 | if (WARN_ON(steps % 5 != 0)) |
| 9311 | return; |
| 9312 | |
| 9313 | if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase))) |
| 9314 | return; |
| 9315 | |
| 9316 | mutex_lock(&dev_priv->sb_lock); |
| 9317 | |
| 9318 | if (steps % 10 != 0) |
| 9319 | tmp = 0xAAAAAAAB; |
| 9320 | else |
| 9321 | tmp = 0x00000000; |
| 9322 | intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK); |
| 9323 | |
| 9324 | tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK); |
| 9325 | tmp &= 0xffff0000; |
| 9326 | tmp |= sscdivintphase[idx]; |
| 9327 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK); |
| 9328 | |
| 9329 | mutex_unlock(&dev_priv->sb_lock); |
| 9330 | } |
| 9331 | |
| 9332 | #undef BEND_IDX |
| 9333 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9334 | static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 9335 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 9336 | struct intel_encoder *encoder; |
| 9337 | bool has_vga = false; |
| 9338 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9339 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 9340 | switch (encoder->type) { |
| 9341 | case INTEL_OUTPUT_ANALOG: |
| 9342 | has_vga = true; |
| 9343 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 9344 | default: |
| 9345 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 9346 | } |
| 9347 | } |
| 9348 | |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 9349 | if (has_vga) { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9350 | lpt_bend_clkout_dp(dev_priv, 0); |
| 9351 | lpt_enable_clkout_dp(dev_priv, true, true); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 9352 | } else { |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9353 | lpt_disable_clkout_dp(dev_priv); |
Ville Syrjälä | f7be2c2 | 2015-12-04 22:19:39 +0200 | [diff] [blame] | 9354 | } |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 9355 | } |
| 9356 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9357 | /* |
| 9358 | * Initialize reference clocks when the driver loads |
| 9359 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9360 | void intel_init_pch_refclk(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9361 | { |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9362 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9363 | ironlake_init_pch_refclk(dev_priv); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9364 | else if (HAS_PCH_LPT(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 9365 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9366 | } |
| 9367 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 9368 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9369 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9370 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9371 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9372 | int pipe = intel_crtc->pipe; |
| 9373 | uint32_t val; |
| 9374 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 9375 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9376 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9377 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9378 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 9379 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9380 | break; |
| 9381 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 9382 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9383 | break; |
| 9384 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 9385 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9386 | break; |
| 9387 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 9388 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9389 | break; |
| 9390 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 9391 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 9392 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9393 | } |
| 9394 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9395 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9396 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 9397 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9398 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9399 | val |= PIPECONF_INTERLACED_ILK; |
| 9400 | else |
| 9401 | val |= PIPECONF_PROGRESSIVE; |
| 9402 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9403 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 9404 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 9405 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 9406 | I915_WRITE(PIPECONF(pipe), val); |
| 9407 | POSTING_READ(PIPECONF(pipe)); |
| 9408 | } |
| 9409 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 9410 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9411 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9412 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9413 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9414 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9415 | u32 val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9416 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9417 | if (IS_HASWELL(dev_priv) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9418 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 9419 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9420 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9421 | val |= PIPECONF_INTERLACED_ILK; |
| 9422 | else |
| 9423 | val |= PIPECONF_PROGRESSIVE; |
| 9424 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 9425 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 9426 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9427 | } |
| 9428 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9429 | static void haswell_set_pipemisc(struct drm_crtc *crtc) |
| 9430 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9431 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9432 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9433 | |
| 9434 | if (IS_BROADWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 9) { |
| 9435 | u32 val = 0; |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 9436 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9437 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 9438 | case 18: |
| 9439 | val |= PIPEMISC_DITHER_6_BPC; |
| 9440 | break; |
| 9441 | case 24: |
| 9442 | val |= PIPEMISC_DITHER_8_BPC; |
| 9443 | break; |
| 9444 | case 30: |
| 9445 | val |= PIPEMISC_DITHER_10_BPC; |
| 9446 | break; |
| 9447 | case 36: |
| 9448 | val |= PIPEMISC_DITHER_12_BPC; |
| 9449 | break; |
| 9450 | default: |
| 9451 | /* Case prevented by pipe_config_set_bpp. */ |
| 9452 | BUG(); |
| 9453 | } |
| 9454 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9455 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 9456 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 9457 | |
Jani Nikula | 391bf04 | 2016-03-18 17:05:40 +0200 | [diff] [blame] | 9458 | I915_WRITE(PIPEMISC(intel_crtc->pipe), val); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 9459 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 9460 | } |
| 9461 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 9462 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 9463 | { |
| 9464 | /* |
| 9465 | * Account for spread spectrum to avoid |
| 9466 | * oversubscribing the link. Max center spread |
| 9467 | * is 2.5%; use 5% for safety's sake. |
| 9468 | */ |
| 9469 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 9470 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 9471 | } |
| 9472 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 9473 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 9474 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 9475 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 9476 | } |
| 9477 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9478 | static void ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 9479 | struct intel_crtc_state *crtc_state, |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 9480 | struct dpll *reduced_clock) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 9481 | { |
| 9482 | struct drm_crtc *crtc = &intel_crtc->base; |
| 9483 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9484 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9485 | u32 dpll, fp, fp2; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9486 | int factor; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9487 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 9488 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 9489 | factor = 21; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9490 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 9491 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 9492 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 9493 | (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 9494 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9495 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 9496 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 9497 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9498 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 9499 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9500 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
| 9501 | fp |= FP_CB_TUNE; |
| 9502 | |
| 9503 | if (reduced_clock) { |
| 9504 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
| 9505 | |
| 9506 | if (reduced_clock->m < factor * reduced_clock->n) |
| 9507 | fp2 |= FP_CB_TUNE; |
| 9508 | } else { |
| 9509 | fp2 = fp; |
| 9510 | } |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 9511 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 9512 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 9513 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9514 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 9515 | dpll |= DPLLB_MODE_LVDS; |
| 9516 | else |
| 9517 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 9518 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9519 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 9520 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 9521 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9522 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 9523 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 9524 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9525 | |
Ville Syrjälä | 37a5650 | 2016-06-22 21:57:04 +0300 | [diff] [blame] | 9526 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 9527 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9528 | |
Ville Syrjälä | 7d7f863 | 2016-09-26 11:30:46 +0300 | [diff] [blame] | 9529 | /* |
| 9530 | * The high speed IO clock is only really required for |
| 9531 | * SDVO/HDMI/DP, but we also enable it for CRT to make it |
| 9532 | * possible to share the DPLL between CRT and HDMI. Enabling |
| 9533 | * the clock needlessly does no real harm, except use up a |
| 9534 | * bit of power potentially. |
| 9535 | * |
| 9536 | * We'll limit this to IVB with 3 pipes, since it has only two |
| 9537 | * DPLLs and so DPLL sharing is the only way to get three pipes |
| 9538 | * driving PCH ports at the same time. On SNB we could do this, |
| 9539 | * and potentially avoid enabling the second DPLL, but it's not |
| 9540 | * clear if it''s a win or loss power wise. No point in doing |
| 9541 | * this on ILK at all since it has a fixed DPLL<->pipe mapping. |
| 9542 | */ |
| 9543 | if (INTEL_INFO(dev_priv)->num_pipes == 3 && |
| 9544 | intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) |
| 9545 | dpll |= DPLL_SDVO_HIGH_SPEED; |
| 9546 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 9547 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9548 | 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] | 9549 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9550 | 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] | 9551 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9552 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 9553 | case 5: |
| 9554 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 9555 | break; |
| 9556 | case 7: |
| 9557 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 9558 | break; |
| 9559 | case 10: |
| 9560 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 9561 | break; |
| 9562 | case 14: |
| 9563 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 9564 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9565 | } |
| 9566 | |
Ville Syrjälä | 3d6e9ee | 2016-06-22 21:57:03 +0300 | [diff] [blame] | 9567 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
| 9568 | intel_panel_use_ssc(dev_priv)) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 9569 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9570 | else |
| 9571 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 9572 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9573 | dpll |= DPLL_VCO_ENABLE; |
| 9574 | |
| 9575 | crtc_state->dpll_hw_state.dpll = dpll; |
| 9576 | crtc_state->dpll_hw_state.fp0 = fp; |
| 9577 | crtc_state->dpll_hw_state.fp1 = fp2; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 9578 | } |
| 9579 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 9580 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 9581 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9582 | { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9583 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9584 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 9585 | struct dpll reduced_clock; |
Ander Conselvan de Oliveira | 7ed9f89 | 2016-03-21 18:00:07 +0200 | [diff] [blame] | 9586 | bool has_reduced_clock = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 9587 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 1b6f495 | 2016-05-04 12:11:59 +0300 | [diff] [blame] | 9588 | const struct intel_limit *limit; |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9589 | int refclk = 120000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9590 | |
Ander Conselvan de Oliveira | dd3cd74 | 2015-05-15 13:34:29 +0300 | [diff] [blame] | 9591 | memset(&crtc_state->dpll_hw_state, 0, |
| 9592 | sizeof(crtc_state->dpll_hw_state)); |
| 9593 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9594 | crtc->lowfreq_avail = false; |
| 9595 | |
| 9596 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 9597 | if (!crtc_state->has_pch_encoder) |
| 9598 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9599 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 9600 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9601 | if (intel_panel_use_ssc(dev_priv)) { |
| 9602 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
| 9603 | dev_priv->vbt.lvds_ssc_freq); |
| 9604 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 9605 | } |
| 9606 | |
| 9607 | if (intel_is_dual_link_lvds(dev)) { |
| 9608 | if (refclk == 100000) |
| 9609 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 9610 | else |
| 9611 | limit = &intel_limits_ironlake_dual_lvds; |
| 9612 | } else { |
| 9613 | if (refclk == 100000) |
| 9614 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 9615 | else |
| 9616 | limit = &intel_limits_ironlake_single_lvds; |
| 9617 | } |
| 9618 | } else { |
| 9619 | limit = &intel_limits_ironlake_dac; |
| 9620 | } |
| 9621 | |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 9622 | if (!crtc_state->clock_set && |
Ander Conselvan de Oliveira | 997c030 | 2016-03-21 18:00:12 +0200 | [diff] [blame] | 9623 | !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock, |
| 9624 | refclk, NULL, &crtc_state->dpll)) { |
Ander Conselvan de Oliveira | 364ee29 | 2016-03-21 18:00:10 +0200 | [diff] [blame] | 9625 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 9626 | return -EINVAL; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 9627 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9628 | |
Ander Conselvan de Oliveira | b75ca6f | 2016-03-21 18:00:11 +0200 | [diff] [blame] | 9629 | ironlake_compute_dpll(crtc, crtc_state, |
| 9630 | has_reduced_clock ? &reduced_clock : NULL); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9631 | |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9632 | pll = intel_get_shared_dpll(crtc, crtc_state, NULL); |
| 9633 | if (pll == NULL) { |
| 9634 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 9635 | pipe_name(crtc->pipe)); |
| 9636 | return -EINVAL; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 9637 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9638 | |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 9639 | if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Ander Conselvan de Oliveira | ded220e | 2016-03-21 18:00:09 +0200 | [diff] [blame] | 9640 | has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 9641 | crtc->lowfreq_avail = true; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 9642 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 9643 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9644 | } |
| 9645 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9646 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 9647 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9648 | { |
| 9649 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9650 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9651 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9652 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9653 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 9654 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 9655 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 9656 | & ~TU_SIZE_MASK; |
| 9657 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 9658 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 9659 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9660 | } |
| 9661 | |
| 9662 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 9663 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9664 | struct intel_link_m_n *m_n, |
| 9665 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9666 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9667 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9668 | enum pipe pipe = crtc->pipe; |
| 9669 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9670 | if (INTEL_GEN(dev_priv) >= 5) { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9671 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 9672 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 9673 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 9674 | & ~TU_SIZE_MASK; |
| 9675 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 9676 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 9677 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9678 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 9679 | * gen < 8) and if DRRS is supported (to make sure the |
| 9680 | * registers are not unnecessarily read). |
| 9681 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9682 | if (m2_n2 && INTEL_GEN(dev_priv) < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9683 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9684 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 9685 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 9686 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 9687 | & ~TU_SIZE_MASK; |
| 9688 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 9689 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 9690 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9691 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9692 | } else { |
| 9693 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 9694 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 9695 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9696 | & ~TU_SIZE_MASK; |
| 9697 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 9698 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 9699 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 9700 | } |
| 9701 | } |
| 9702 | |
| 9703 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9704 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9705 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 9706 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9707 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 9708 | else |
| 9709 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9710 | &pipe_config->dp_m_n, |
| 9711 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9712 | } |
| 9713 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9714 | 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] | 9715 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9716 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 9717 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 9718 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9719 | } |
| 9720 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9721 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9722 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9723 | { |
| 9724 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9725 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9726 | struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state; |
| 9727 | uint32_t ps_ctrl = 0; |
| 9728 | int id = -1; |
| 9729 | int i; |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9730 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9731 | /* find scaler attached to this pipe */ |
| 9732 | for (i = 0; i < crtc->num_scalers; i++) { |
| 9733 | ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i)); |
| 9734 | if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) { |
| 9735 | id = i; |
| 9736 | pipe_config->pch_pfit.enabled = true; |
| 9737 | pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i)); |
| 9738 | pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i)); |
| 9739 | break; |
| 9740 | } |
| 9741 | } |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9742 | |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 9743 | scaler_state->scaler_id = id; |
| 9744 | if (id >= 0) { |
| 9745 | scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX); |
| 9746 | } else { |
| 9747 | scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 9748 | } |
| 9749 | } |
| 9750 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9751 | static void |
| 9752 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9753 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9754 | { |
| 9755 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9756 | struct drm_i915_private *dev_priv = to_i915(dev); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9757 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9758 | int pipe = crtc->pipe; |
| 9759 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9760 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9761 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9762 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9763 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9764 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9765 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9766 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9767 | return; |
| 9768 | } |
| 9769 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9770 | fb = &intel_fb->base; |
| 9771 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9772 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9773 | if (!(val & PLANE_CTL_ENABLE)) |
| 9774 | goto error; |
| 9775 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9776 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 9777 | fourcc = skl_format_to_fourcc(pixel_format, |
| 9778 | val & PLANE_CTL_ORDER_RGBX, |
| 9779 | val & PLANE_CTL_ALPHA_MASK); |
| 9780 | fb->pixel_format = fourcc; |
| 9781 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 9782 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9783 | tiling = val & PLANE_CTL_TILED_MASK; |
| 9784 | switch (tiling) { |
| 9785 | case PLANE_CTL_TILED_LINEAR: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9786 | fb->modifier = DRM_FORMAT_MOD_NONE; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9787 | break; |
| 9788 | case PLANE_CTL_TILED_X: |
| 9789 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9790 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9791 | break; |
| 9792 | case PLANE_CTL_TILED_Y: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9793 | fb->modifier = I915_FORMAT_MOD_Y_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9794 | break; |
| 9795 | case PLANE_CTL_TILED_YF: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9796 | fb->modifier = I915_FORMAT_MOD_Yf_TILED; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9797 | break; |
| 9798 | default: |
| 9799 | MISSING_CASE(tiling); |
| 9800 | goto error; |
| 9801 | } |
| 9802 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9803 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 9804 | plane_config->base = base; |
| 9805 | |
| 9806 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 9807 | |
| 9808 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 9809 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 9810 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 9811 | |
| 9812 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9813 | stride_mult = intel_fb_stride_alignment(dev_priv, fb->modifier, |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 9814 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9815 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 9816 | |
| 9817 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9818 | fb->pixel_format, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9819 | fb->modifier); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9820 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9821 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9822 | |
| 9823 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9824 | pipe_name(pipe), fb->width, fb->height, |
| 9825 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9826 | plane_config->size); |
| 9827 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9828 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9829 | return; |
| 9830 | |
| 9831 | error: |
Matthew Auld | d1a3a03 | 2016-08-23 16:00:44 +0100 | [diff] [blame] | 9832 | kfree(intel_fb); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 9833 | } |
| 9834 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9835 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9836 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9837 | { |
| 9838 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9839 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9840 | uint32_t tmp; |
| 9841 | |
| 9842 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 9843 | |
| 9844 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 9845 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9846 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 9847 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9848 | |
| 9849 | /* We currently do not free assignements of panel fitters on |
| 9850 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 9851 | * differentiates them) so just WARN about this case for now. */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 9852 | if (IS_GEN7(dev_priv)) { |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 9853 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 9854 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 9855 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 9856 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9857 | } |
| 9858 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 9859 | static void |
| 9860 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 9861 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9862 | { |
| 9863 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9864 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9865 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9866 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9867 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 9868 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9869 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9870 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9871 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 9872 | val = I915_READ(DSPCNTR(pipe)); |
| 9873 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 9874 | return; |
| 9875 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 9876 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9877 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9878 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 9879 | return; |
| 9880 | } |
| 9881 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 9882 | fb = &intel_fb->base; |
| 9883 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 9884 | if (INTEL_GEN(dev_priv) >= 4) { |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9885 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9886 | plane_config->tiling = I915_TILING_X; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9887 | fb->modifier = I915_FORMAT_MOD_X_TILED; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 9888 | } |
| 9889 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9890 | |
| 9891 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 9892 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9893 | fb->pixel_format = fourcc; |
| 9894 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9895 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9896 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 9897 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9898 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9899 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 9900 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9901 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9902 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 9903 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9904 | } |
| 9905 | plane_config->base = base; |
| 9906 | |
| 9907 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9908 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 9909 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9910 | |
| 9911 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9912 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9913 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9914 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 9915 | fb->pixel_format, |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 9916 | fb->modifier); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9917 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 9918 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9919 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 9920 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 9921 | pipe_name(pipe), fb->width, fb->height, |
| 9922 | fb->bits_per_pixel, base, fb->pitches[0], |
| 9923 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 9924 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 9925 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 9926 | } |
| 9927 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9928 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9929 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9930 | { |
| 9931 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 9932 | struct drm_i915_private *dev_priv = to_i915(dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9933 | enum intel_display_power_domain power_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9934 | uint32_t tmp; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9935 | bool ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9936 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9937 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 9938 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 9939 | return false; |
| 9940 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 9941 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9942 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 9943 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9944 | ret = false; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9945 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 9946 | if (!(tmp & PIPECONF_ENABLE)) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 9947 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9948 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 9949 | switch (tmp & PIPECONF_BPC_MASK) { |
| 9950 | case PIPECONF_6BPC: |
| 9951 | pipe_config->pipe_bpp = 18; |
| 9952 | break; |
| 9953 | case PIPECONF_8BPC: |
| 9954 | pipe_config->pipe_bpp = 24; |
| 9955 | break; |
| 9956 | case PIPECONF_10BPC: |
| 9957 | pipe_config->pipe_bpp = 30; |
| 9958 | break; |
| 9959 | case PIPECONF_12BPC: |
| 9960 | pipe_config->pipe_bpp = 36; |
| 9961 | break; |
| 9962 | default: |
| 9963 | break; |
| 9964 | } |
| 9965 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 9966 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 9967 | pipe_config->limited_color_range = true; |
| 9968 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 9969 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9970 | struct intel_shared_dpll *pll; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9971 | enum intel_dpll_id pll_id; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9972 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9973 | pipe_config->has_pch_encoder = true; |
| 9974 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 9975 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 9976 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 9977 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 9978 | |
| 9979 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 9980 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 9981 | if (HAS_PCH_IBX(dev_priv)) { |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 9982 | /* |
| 9983 | * The pipe->pch transcoder and pch transcoder->pll |
| 9984 | * mapping is fixed. |
| 9985 | */ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9986 | pll_id = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9987 | } else { |
| 9988 | tmp = I915_READ(PCH_DPLL_SEL); |
| 9989 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9990 | pll_id = DPLL_ID_PCH_PLL_B; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9991 | else |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9992 | pll_id= DPLL_ID_PCH_PLL_A; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 9993 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9994 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 9995 | pipe_config->shared_dpll = |
| 9996 | intel_get_shared_dpll_by_id(dev_priv, pll_id); |
| 9997 | pll = pipe_config->shared_dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 9998 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 9999 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 10000 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 10001 | |
| 10002 | tmp = pipe_config->dpll_hw_state.dpll; |
| 10003 | pipe_config->pixel_multiplier = |
| 10004 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 10005 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10006 | |
| 10007 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10008 | } else { |
| 10009 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10010 | } |
| 10011 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10012 | intel_get_pipe_timings(crtc, pipe_config); |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 10013 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10014 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10015 | ironlake_get_pfit_config(crtc, pipe_config); |
| 10016 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10017 | ret = true; |
| 10018 | |
| 10019 | out: |
| 10020 | intel_display_power_put(dev_priv, power_domain); |
| 10021 | |
| 10022 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10023 | } |
| 10024 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10025 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 10026 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 10027 | struct drm_device *dev = &dev_priv->drm; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10028 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10029 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10030 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10031 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10032 | pipe_name(crtc->pipe)); |
| 10033 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10034 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 10035 | 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] | 10036 | I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 10037 | I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 10038 | I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10039 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10040 | "CPU PWM1 enabled\n"); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 10041 | if (IS_HASWELL(dev_priv)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10042 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 10043 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10044 | 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] | 10045 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10046 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10047 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10048 | 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] | 10049 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 10050 | /* |
| 10051 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 10052 | * interrupts remain enabled. We used to check for that, but since it's |
| 10053 | * gen-specific and since we only disable LCPLL after we fully disable |
| 10054 | * the interrupts, the check below should be enough. |
| 10055 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10056 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10057 | } |
| 10058 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10059 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 10060 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 10061 | if (IS_HASWELL(dev_priv)) |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10062 | return I915_READ(D_COMP_HSW); |
| 10063 | else |
| 10064 | return I915_READ(D_COMP_BDW); |
| 10065 | } |
| 10066 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10067 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 10068 | { |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 10069 | if (IS_HASWELL(dev_priv)) { |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10070 | mutex_lock(&dev_priv->rps.hw_lock); |
| 10071 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 10072 | val)) |
Chris Wilson | 79cf219 | 2016-08-24 11:16:07 +0100 | [diff] [blame] | 10073 | DRM_DEBUG_KMS("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10074 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 10075 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10076 | I915_WRITE(D_COMP_BDW, val); |
| 10077 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10078 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10079 | } |
| 10080 | |
| 10081 | /* |
| 10082 | * This function implements pieces of two sequences from BSpec: |
| 10083 | * - Sequence for display software to disable LCPLL |
| 10084 | * - Sequence for display software to allow package C8+ |
| 10085 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 10086 | * register. Callers should take care of disabling all the display engine |
| 10087 | * functions, doing the mode unset, fixing interrupts, etc. |
| 10088 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 10089 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 10090 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10091 | { |
| 10092 | uint32_t val; |
| 10093 | |
| 10094 | assert_can_disable_lcpll(dev_priv); |
| 10095 | |
| 10096 | val = I915_READ(LCPLL_CTL); |
| 10097 | |
| 10098 | if (switch_to_fclk) { |
| 10099 | val |= LCPLL_CD_SOURCE_FCLK; |
| 10100 | I915_WRITE(LCPLL_CTL, val); |
| 10101 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 10102 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 10103 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10104 | DRM_ERROR("Switching to FCLK failed\n"); |
| 10105 | |
| 10106 | val = I915_READ(LCPLL_CTL); |
| 10107 | } |
| 10108 | |
| 10109 | val |= LCPLL_PLL_DISABLE; |
| 10110 | I915_WRITE(LCPLL_CTL, val); |
| 10111 | POSTING_READ(LCPLL_CTL); |
| 10112 | |
Chris Wilson | 24d8441 | 2016-06-30 15:33:07 +0100 | [diff] [blame] | 10113 | if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10114 | DRM_ERROR("LCPLL still locked\n"); |
| 10115 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10116 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10117 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10118 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10119 | ndelay(100); |
| 10120 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10121 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 10122 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10123 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 10124 | |
| 10125 | if (allow_power_down) { |
| 10126 | val = I915_READ(LCPLL_CTL); |
| 10127 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 10128 | I915_WRITE(LCPLL_CTL, val); |
| 10129 | POSTING_READ(LCPLL_CTL); |
| 10130 | } |
| 10131 | } |
| 10132 | |
| 10133 | /* |
| 10134 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 10135 | * source. |
| 10136 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 10137 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10138 | { |
| 10139 | uint32_t val; |
| 10140 | |
| 10141 | val = I915_READ(LCPLL_CTL); |
| 10142 | |
| 10143 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 10144 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 10145 | return; |
| 10146 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 10147 | /* |
| 10148 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 10149 | * 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] | 10150 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 10151 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 10152 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10153 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 10154 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 10155 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 10156 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10157 | } |
| 10158 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 10159 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10160 | val |= D_COMP_COMP_FORCE; |
| 10161 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 10162 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10163 | |
| 10164 | val = I915_READ(LCPLL_CTL); |
| 10165 | val &= ~LCPLL_PLL_DISABLE; |
| 10166 | I915_WRITE(LCPLL_CTL, val); |
| 10167 | |
Chris Wilson | 93220c0 | 2016-06-30 15:33:08 +0100 | [diff] [blame] | 10168 | if (intel_wait_for_register(dev_priv, |
| 10169 | LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK, |
| 10170 | 5)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10171 | DRM_ERROR("LCPLL not locked yet\n"); |
| 10172 | |
| 10173 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 10174 | val = I915_READ(LCPLL_CTL); |
| 10175 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 10176 | I915_WRITE(LCPLL_CTL, val); |
| 10177 | |
Imre Deak | f53dd63 | 2016-06-28 13:37:32 +0300 | [diff] [blame] | 10178 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 10179 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10180 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 10181 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 10182 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 10183 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 10184 | intel_update_cdclk(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 10185 | } |
| 10186 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 10187 | /* |
| 10188 | * Package states C8 and deeper are really deep PC states that can only be |
| 10189 | * reached when all the devices on the system allow it, so even if the graphics |
| 10190 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 10191 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 10192 | * |
| 10193 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 10194 | * well is disabled and most interrupts are disabled, and these are also |
| 10195 | * requirements for runtime PM. When these conditions are met, we manually do |
| 10196 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 10197 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 10198 | * hang the machine. |
| 10199 | * |
| 10200 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 10201 | * the state of some registers, so when we come back from PC8+ we need to |
| 10202 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 10203 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 10204 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 10205 | * because of the runtime PM support). |
| 10206 | * |
| 10207 | * For more, read "Display Sequences for Package C8" on the hardware |
| 10208 | * documentation. |
| 10209 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 10210 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10211 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10212 | uint32_t val; |
| 10213 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10214 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 10215 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10216 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10217 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 10218 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 10219 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 10220 | } |
| 10221 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 10222 | lpt_disable_clkout_dp(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10223 | hsw_disable_lcpll(dev_priv, true, true); |
| 10224 | } |
| 10225 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 10226 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10227 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10228 | uint32_t val; |
| 10229 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10230 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 10231 | |
| 10232 | hsw_restore_lcpll(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 10233 | lpt_init_pch_refclk(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10234 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10235 | if (HAS_PCH_LPT_LP(dev_priv)) { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10236 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 10237 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 10238 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 10239 | } |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 10240 | } |
| 10241 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 10242 | static void bxt_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 10243 | { |
Ander Conselvan de Oliveira | a821fc4 | 2015-04-21 17:13:23 +0300 | [diff] [blame] | 10244 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 10245 | struct intel_atomic_state *old_intel_state = |
| 10246 | to_intel_atomic_state(old_state); |
| 10247 | unsigned int req_cdclk = old_intel_state->dev_cdclk; |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 10248 | |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 10249 | bxt_set_cdclk(to_i915(dev), req_cdclk); |
Vandana Kannan | f8437dd1 | 2014-11-24 13:37:39 +0530 | [diff] [blame] | 10250 | } |
| 10251 | |
Dhinakaran Pandiyan | b30ce9e | 2016-11-01 11:47:59 -0700 | [diff] [blame] | 10252 | static int bdw_adjust_min_pipe_pixel_rate(struct intel_crtc_state *crtc_state, |
| 10253 | int pixel_rate) |
| 10254 | { |
Dhinakaran Pandiyan | 9c75402 | 2016-11-02 13:13:21 -0700 | [diff] [blame] | 10255 | struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev); |
| 10256 | |
Dhinakaran Pandiyan | b30ce9e | 2016-11-01 11:47:59 -0700 | [diff] [blame] | 10257 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
Dhinakaran Pandiyan | 9c75402 | 2016-11-02 13:13:21 -0700 | [diff] [blame] | 10258 | if (IS_BROADWELL(dev_priv) && crtc_state->ips_enabled) |
Dhinakaran Pandiyan | b30ce9e | 2016-11-01 11:47:59 -0700 | [diff] [blame] | 10259 | pixel_rate = DIV_ROUND_UP(pixel_rate * 100, 95); |
| 10260 | |
| 10261 | /* BSpec says "Do not use DisplayPort with CDCLK less than |
| 10262 | * 432 MHz, audio enabled, port width x4, and link rate |
| 10263 | * HBR2 (5.4 GHz), or else there may be audio corruption or |
| 10264 | * screen corruption." |
| 10265 | */ |
| 10266 | if (intel_crtc_has_dp_encoder(crtc_state) && |
| 10267 | crtc_state->has_audio && |
| 10268 | crtc_state->port_clock >= 540000 && |
| 10269 | crtc_state->lane_count == 4) |
| 10270 | pixel_rate = max(432000, pixel_rate); |
| 10271 | |
| 10272 | return pixel_rate; |
| 10273 | } |
| 10274 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10275 | /* compute the max rate for new configuration */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10276 | static int ilk_max_pixel_rate(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10277 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10278 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10279 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10280 | struct drm_crtc *crtc; |
| 10281 | struct drm_crtc_state *cstate; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10282 | struct intel_crtc_state *crtc_state; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10283 | unsigned max_pixel_rate = 0, i; |
| 10284 | enum pipe pipe; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10285 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10286 | memcpy(intel_state->min_pixclk, dev_priv->min_pixclk, |
| 10287 | sizeof(intel_state->min_pixclk)); |
| 10288 | |
| 10289 | for_each_crtc_in_state(state, crtc, cstate, i) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10290 | int pixel_rate; |
| 10291 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10292 | crtc_state = to_intel_crtc_state(cstate); |
| 10293 | if (!crtc_state->base.enable) { |
| 10294 | intel_state->min_pixclk[i] = 0; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10295 | continue; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10296 | } |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10297 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10298 | pixel_rate = ilk_pipe_pixel_rate(crtc_state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10299 | |
Dhinakaran Pandiyan | 9c75402 | 2016-11-02 13:13:21 -0700 | [diff] [blame] | 10300 | if (IS_BROADWELL(dev_priv) || IS_GEN9(dev_priv)) |
Dhinakaran Pandiyan | b30ce9e | 2016-11-01 11:47:59 -0700 | [diff] [blame] | 10301 | pixel_rate = bdw_adjust_min_pipe_pixel_rate(crtc_state, |
| 10302 | pixel_rate); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10303 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10304 | intel_state->min_pixclk[i] = pixel_rate; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10305 | } |
| 10306 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 10307 | for_each_pipe(dev_priv, pipe) |
| 10308 | max_pixel_rate = max(intel_state->min_pixclk[pipe], max_pixel_rate); |
| 10309 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10310 | return max_pixel_rate; |
| 10311 | } |
| 10312 | |
| 10313 | static void broadwell_set_cdclk(struct drm_device *dev, int cdclk) |
| 10314 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10315 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10316 | uint32_t val, data; |
| 10317 | int ret; |
| 10318 | |
| 10319 | if (WARN((I915_READ(LCPLL_CTL) & |
| 10320 | (LCPLL_PLL_DISABLE | LCPLL_PLL_LOCK | |
| 10321 | LCPLL_CD_CLOCK_DISABLE | LCPLL_ROOT_CD_CLOCK_DISABLE | |
| 10322 | LCPLL_CD2X_CLOCK_DISABLE | LCPLL_POWER_DOWN_ALLOW | |
| 10323 | LCPLL_CD_SOURCE_FCLK)) != LCPLL_PLL_LOCK, |
| 10324 | "trying to change cdclk frequency with cdclk not enabled\n")) |
| 10325 | return; |
| 10326 | |
| 10327 | mutex_lock(&dev_priv->rps.hw_lock); |
| 10328 | ret = sandybridge_pcode_write(dev_priv, |
| 10329 | BDW_PCODE_DISPLAY_FREQ_CHANGE_REQ, 0x0); |
| 10330 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 10331 | if (ret) { |
| 10332 | DRM_ERROR("failed to inform pcode about cdclk change\n"); |
| 10333 | return; |
| 10334 | } |
| 10335 | |
| 10336 | val = I915_READ(LCPLL_CTL); |
| 10337 | val |= LCPLL_CD_SOURCE_FCLK; |
| 10338 | I915_WRITE(LCPLL_CTL, val); |
| 10339 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 10340 | if (wait_for_us(I915_READ(LCPLL_CTL) & |
| 10341 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10342 | DRM_ERROR("Switching to FCLK failed\n"); |
| 10343 | |
| 10344 | val = I915_READ(LCPLL_CTL); |
| 10345 | val &= ~LCPLL_CLK_FREQ_MASK; |
| 10346 | |
| 10347 | switch (cdclk) { |
| 10348 | case 450000: |
| 10349 | val |= LCPLL_CLK_FREQ_450; |
| 10350 | data = 0; |
| 10351 | break; |
| 10352 | case 540000: |
| 10353 | val |= LCPLL_CLK_FREQ_54O_BDW; |
| 10354 | data = 1; |
| 10355 | break; |
| 10356 | case 337500: |
| 10357 | val |= LCPLL_CLK_FREQ_337_5_BDW; |
| 10358 | data = 2; |
| 10359 | break; |
| 10360 | case 675000: |
| 10361 | val |= LCPLL_CLK_FREQ_675_BDW; |
| 10362 | data = 3; |
| 10363 | break; |
| 10364 | default: |
| 10365 | WARN(1, "invalid cdclk frequency\n"); |
| 10366 | return; |
| 10367 | } |
| 10368 | |
| 10369 | I915_WRITE(LCPLL_CTL, val); |
| 10370 | |
| 10371 | val = I915_READ(LCPLL_CTL); |
| 10372 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 10373 | I915_WRITE(LCPLL_CTL, val); |
| 10374 | |
Tvrtko Ursulin | 5ba0017 | 2016-03-03 14:36:45 +0000 | [diff] [blame] | 10375 | if (wait_for_us((I915_READ(LCPLL_CTL) & |
| 10376 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10377 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 10378 | |
| 10379 | mutex_lock(&dev_priv->rps.hw_lock); |
| 10380 | sandybridge_pcode_write(dev_priv, HSW_PCODE_DE_WRITE_FREQ_REQ, data); |
| 10381 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 10382 | |
Ville Syrjälä | 7f1052a | 2016-04-26 19:46:32 +0300 | [diff] [blame] | 10383 | I915_WRITE(CDCLK_FREQ, DIV_ROUND_CLOSEST(cdclk, 1000) - 1); |
| 10384 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 10385 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10386 | |
| 10387 | WARN(cdclk != dev_priv->cdclk_freq, |
| 10388 | "cdclk requested %d kHz but got %d kHz\n", |
| 10389 | cdclk, dev_priv->cdclk_freq); |
| 10390 | } |
| 10391 | |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 10392 | static int broadwell_calc_cdclk(int max_pixclk) |
| 10393 | { |
| 10394 | if (max_pixclk > 540000) |
| 10395 | return 675000; |
| 10396 | else if (max_pixclk > 450000) |
| 10397 | return 540000; |
| 10398 | else if (max_pixclk > 337500) |
| 10399 | return 450000; |
| 10400 | else |
| 10401 | return 337500; |
| 10402 | } |
| 10403 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10404 | static int broadwell_modeset_calc_cdclk(struct drm_atomic_state *state) |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10405 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10406 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 10407 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10408 | int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10409 | int cdclk; |
| 10410 | |
| 10411 | /* |
| 10412 | * FIXME should also account for plane ratio |
| 10413 | * once 64bpp pixel formats are supported. |
| 10414 | */ |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 10415 | cdclk = broadwell_calc_cdclk(max_pixclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10416 | |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10417 | if (cdclk > dev_priv->max_cdclk_freq) { |
Maarten Lankhorst | 63ba534 | 2015-11-24 11:29:03 +0100 | [diff] [blame] | 10418 | DRM_DEBUG_KMS("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 10419 | cdclk, dev_priv->max_cdclk_freq); |
| 10420 | return -EINVAL; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10421 | } |
| 10422 | |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 10423 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 10424 | if (!intel_state->active_crtcs) |
Ville Syrjälä | 587c791 | 2016-05-11 22:44:41 +0300 | [diff] [blame] | 10425 | intel_state->dev_cdclk = broadwell_calc_cdclk(0); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10426 | |
| 10427 | return 0; |
| 10428 | } |
| 10429 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10430 | 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] | 10431 | { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10432 | struct drm_device *dev = old_state->dev; |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 10433 | struct intel_atomic_state *old_intel_state = |
| 10434 | to_intel_atomic_state(old_state); |
| 10435 | unsigned req_cdclk = old_intel_state->dev_cdclk; |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10436 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 10437 | broadwell_set_cdclk(dev, req_cdclk); |
Ville Syrjälä | b432e5c | 2015-06-03 15:45:13 +0300 | [diff] [blame] | 10438 | } |
| 10439 | |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10440 | static int skl_modeset_calc_cdclk(struct drm_atomic_state *state) |
| 10441 | { |
| 10442 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 10443 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
| 10444 | const int max_pixclk = ilk_max_pixel_rate(state); |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 10445 | int vco = intel_state->cdclk_pll_vco; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10446 | int cdclk; |
| 10447 | |
| 10448 | /* |
| 10449 | * FIXME should also account for plane ratio |
| 10450 | * once 64bpp pixel formats are supported. |
| 10451 | */ |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 10452 | cdclk = skl_calc_cdclk(max_pixclk, vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10453 | |
| 10454 | /* |
| 10455 | * FIXME move the cdclk caclulation to |
| 10456 | * compute_config() so we can fail gracegully. |
| 10457 | */ |
| 10458 | if (cdclk > dev_priv->max_cdclk_freq) { |
| 10459 | DRM_ERROR("requested cdclk (%d kHz) exceeds max (%d kHz)\n", |
| 10460 | cdclk, dev_priv->max_cdclk_freq); |
| 10461 | cdclk = dev_priv->max_cdclk_freq; |
| 10462 | } |
| 10463 | |
| 10464 | intel_state->cdclk = intel_state->dev_cdclk = cdclk; |
| 10465 | if (!intel_state->active_crtcs) |
Ville Syrjälä | a8ca493 | 2016-05-13 23:41:23 +0300 | [diff] [blame] | 10466 | intel_state->dev_cdclk = skl_calc_cdclk(0, vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10467 | |
| 10468 | return 0; |
| 10469 | } |
| 10470 | |
| 10471 | static void skl_modeset_commit_cdclk(struct drm_atomic_state *old_state) |
| 10472 | { |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 10473 | struct drm_i915_private *dev_priv = to_i915(old_state->dev); |
| 10474 | struct intel_atomic_state *intel_state = to_intel_atomic_state(old_state); |
| 10475 | unsigned int req_cdclk = intel_state->dev_cdclk; |
| 10476 | unsigned int req_vco = intel_state->cdclk_pll_vco; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10477 | |
Ville Syrjälä | 1cd593e | 2016-05-13 23:41:26 +0300 | [diff] [blame] | 10478 | skl_set_cdclk(dev_priv, req_cdclk, req_vco); |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 10479 | } |
| 10480 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 10481 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 10482 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 10483 | { |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 10484 | if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI)) { |
Mika Kahola | af3997b | 2016-02-05 13:29:28 +0200 | [diff] [blame] | 10485 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
| 10486 | return -EINVAL; |
| 10487 | } |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 10488 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 10489 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 10490 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 10491 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10492 | } |
| 10493 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10494 | static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 10495 | enum port port, |
| 10496 | struct intel_crtc_state *pipe_config) |
| 10497 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10498 | enum intel_dpll_id id; |
| 10499 | |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10500 | switch (port) { |
| 10501 | case PORT_A: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 10502 | id = DPLL_ID_SKL_DPLL0; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10503 | break; |
| 10504 | case PORT_B: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 10505 | id = DPLL_ID_SKL_DPLL1; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10506 | break; |
| 10507 | case PORT_C: |
Imre Deak | 08250c4 | 2016-03-14 19:55:34 +0200 | [diff] [blame] | 10508 | id = DPLL_ID_SKL_DPLL2; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10509 | break; |
| 10510 | default: |
| 10511 | DRM_ERROR("Incorrect port type\n"); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10512 | return; |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10513 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10514 | |
| 10515 | 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] | 10516 | } |
| 10517 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10518 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 10519 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10520 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10521 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10522 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | a3c988e | 2016-03-08 17:46:27 +0200 | [diff] [blame] | 10523 | u32 temp; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10524 | |
| 10525 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 10526 | id = temp >> (port * 3 + 1); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10527 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 10528 | if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3)) |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10529 | return; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10530 | |
| 10531 | 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] | 10532 | } |
| 10533 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10534 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 10535 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10536 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10537 | { |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10538 | enum intel_dpll_id id; |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 10539 | uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10540 | |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 10541 | switch (ddi_pll_sel) { |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10542 | case PORT_CLK_SEL_WRPLL1: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10543 | id = DPLL_ID_WRPLL1; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10544 | break; |
| 10545 | case PORT_CLK_SEL_WRPLL2: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10546 | id = DPLL_ID_WRPLL2; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10547 | break; |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 10548 | case PORT_CLK_SEL_SPLL: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10549 | id = DPLL_ID_SPLL; |
Ville Syrjälä | 79bd23d | 2015-12-01 23:32:07 +0200 | [diff] [blame] | 10550 | break; |
Ander Conselvan de Oliveira | 9d16da6 | 2016-03-08 17:46:26 +0200 | [diff] [blame] | 10551 | case PORT_CLK_SEL_LCPLL_810: |
| 10552 | id = DPLL_ID_LCPLL_810; |
| 10553 | break; |
| 10554 | case PORT_CLK_SEL_LCPLL_1350: |
| 10555 | id = DPLL_ID_LCPLL_1350; |
| 10556 | break; |
| 10557 | case PORT_CLK_SEL_LCPLL_2700: |
| 10558 | id = DPLL_ID_LCPLL_2700; |
| 10559 | break; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10560 | default: |
Ander Conselvan de Oliveira | c856052 | 2016-09-01 15:08:07 -0700 | [diff] [blame] | 10561 | MISSING_CASE(ddi_pll_sel); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10562 | /* fall through */ |
| 10563 | case PORT_CLK_SEL_NONE: |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10564 | return; |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 10565 | } |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10566 | |
| 10567 | 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] | 10568 | } |
| 10569 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10570 | static bool hsw_get_transcoder_state(struct intel_crtc *crtc, |
| 10571 | struct intel_crtc_state *pipe_config, |
| 10572 | unsigned long *power_domain_mask) |
| 10573 | { |
| 10574 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10575 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10576 | enum intel_display_power_domain power_domain; |
| 10577 | u32 tmp; |
| 10578 | |
Imre Deak | d9a7bc6 | 2016-05-12 16:18:50 +0300 | [diff] [blame] | 10579 | /* |
| 10580 | * The pipe->transcoder mapping is fixed with the exception of the eDP |
| 10581 | * transcoder handled below. |
| 10582 | */ |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10583 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
| 10584 | |
| 10585 | /* |
| 10586 | * XXX: Do intel_display_power_get_if_enabled before reading this (for |
| 10587 | * consistency and less surprising code; it's in always on power). |
| 10588 | */ |
| 10589 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 10590 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 10591 | enum pipe trans_edp_pipe; |
| 10592 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 10593 | default: |
| 10594 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 10595 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 10596 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 10597 | trans_edp_pipe = PIPE_A; |
| 10598 | break; |
| 10599 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 10600 | trans_edp_pipe = PIPE_B; |
| 10601 | break; |
| 10602 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 10603 | trans_edp_pipe = PIPE_C; |
| 10604 | break; |
| 10605 | } |
| 10606 | |
| 10607 | if (trans_edp_pipe == crtc->pipe) |
| 10608 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 10609 | } |
| 10610 | |
| 10611 | power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder); |
| 10612 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10613 | return false; |
| 10614 | *power_domain_mask |= BIT(power_domain); |
| 10615 | |
| 10616 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
| 10617 | |
| 10618 | return tmp & PIPECONF_ENABLE; |
| 10619 | } |
| 10620 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10621 | static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc, |
| 10622 | struct intel_crtc_state *pipe_config, |
| 10623 | unsigned long *power_domain_mask) |
| 10624 | { |
| 10625 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10626 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10627 | enum intel_display_power_domain power_domain; |
| 10628 | enum port port; |
| 10629 | enum transcoder cpu_transcoder; |
| 10630 | u32 tmp; |
| 10631 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10632 | for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) { |
| 10633 | if (port == PORT_A) |
| 10634 | cpu_transcoder = TRANSCODER_DSI_A; |
| 10635 | else |
| 10636 | cpu_transcoder = TRANSCODER_DSI_C; |
| 10637 | |
| 10638 | power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder); |
| 10639 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
| 10640 | continue; |
| 10641 | *power_domain_mask |= BIT(power_domain); |
| 10642 | |
Imre Deak | db18b6a | 2016-03-24 12:41:40 +0200 | [diff] [blame] | 10643 | /* |
| 10644 | * The PLL needs to be enabled with a valid divider |
| 10645 | * configuration, otherwise accessing DSI registers will hang |
| 10646 | * the machine. See BSpec North Display Engine |
| 10647 | * registers/MIPI[BXT]. We can break out here early, since we |
| 10648 | * need the same DSI PLL to be enabled for both DSI ports. |
| 10649 | */ |
| 10650 | if (!intel_dsi_pll_is_enabled(dev_priv)) |
| 10651 | break; |
| 10652 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10653 | /* XXX: this works for video mode only */ |
| 10654 | tmp = I915_READ(BXT_MIPI_PORT_CTRL(port)); |
| 10655 | if (!(tmp & DPI_ENABLE)) |
| 10656 | continue; |
| 10657 | |
| 10658 | tmp = I915_READ(MIPI_CTRL(port)); |
| 10659 | if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe)) |
| 10660 | continue; |
| 10661 | |
| 10662 | pipe_config->cpu_transcoder = cpu_transcoder; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10663 | break; |
| 10664 | } |
| 10665 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 10666 | return transcoder_is_dsi(pipe_config->cpu_transcoder); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10667 | } |
| 10668 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10669 | 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] | 10670 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10671 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10672 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10673 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10674 | enum port port; |
| 10675 | uint32_t tmp; |
| 10676 | |
| 10677 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 10678 | |
| 10679 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 10680 | |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 10681 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10682 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 10683 | else if (IS_GEN9_LP(dev_priv)) |
Satheeshakrishna M | 3760b59 | 2014-08-22 09:49:11 +0530 | [diff] [blame] | 10684 | bxt_get_ddi_pll(dev_priv, port, pipe_config); |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 10685 | else |
| 10686 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 10687 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10688 | pll = pipe_config->shared_dpll; |
| 10689 | if (pll) { |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 10690 | WARN_ON(!pll->funcs.get_hw_state(dev_priv, pll, |
| 10691 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10692 | } |
| 10693 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10694 | /* |
| 10695 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 10696 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 10697 | * the PCH transcoder is on. |
| 10698 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10699 | if (INTEL_GEN(dev_priv) < 9 && |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 10700 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10701 | pipe_config->has_pch_encoder = true; |
| 10702 | |
| 10703 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 10704 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 10705 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 10706 | |
| 10707 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 10708 | } |
| 10709 | } |
| 10710 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10711 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10712 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10713 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10714 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10715 | enum intel_display_power_domain power_domain; |
| 10716 | unsigned long power_domain_mask; |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10717 | bool active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10718 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10719 | power_domain = POWER_DOMAIN_PIPE(crtc->pipe); |
| 10720 | if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 10721 | return false; |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10722 | power_domain_mask = BIT(power_domain); |
| 10723 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 10724 | pipe_config->shared_dpll = NULL; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10725 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10726 | active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask); |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10727 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 10728 | if (IS_GEN9_LP(dev_priv) && |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 10729 | bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) { |
| 10730 | WARN_ON(active); |
| 10731 | active = true; |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10732 | } |
| 10733 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10734 | if (!active) |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10735 | goto out; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10736 | |
Ville Syrjälä | d7edc4e | 2016-06-22 21:57:07 +0300 | [diff] [blame] | 10737 | if (!transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10738 | haswell_get_ddi_port_state(crtc, pipe_config); |
| 10739 | intel_get_pipe_timings(crtc, pipe_config); |
| 10740 | } |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10741 | |
Jani Nikula | bc58be6 | 2016-03-18 17:05:39 +0200 | [diff] [blame] | 10742 | intel_get_pipe_src_size(crtc, pipe_config); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10743 | |
Lionel Landwerlin | 05dc698 | 2016-03-16 10:57:15 +0000 | [diff] [blame] | 10744 | pipe_config->gamma_mode = |
| 10745 | I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK; |
| 10746 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10747 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 10748 | skl_init_scalers(dev_priv, crtc, pipe_config); |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 10749 | |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 10750 | pipe_config->scaler_state.scaler_id = -1; |
| 10751 | pipe_config->scaler_state.scaler_users &= ~(1 << SKL_CRTC_INDEX); |
| 10752 | } |
| 10753 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10754 | power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 10755 | if (intel_display_power_get_if_enabled(dev_priv, power_domain)) { |
| 10756 | power_domain_mask |= BIT(power_domain); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 10757 | if (INTEL_GEN(dev_priv) >= 9) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10758 | skylake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | ff6d9f5 | 2015-01-21 17:19:54 -0800 | [diff] [blame] | 10759 | else |
Rodrigo Vivi | 1c132b4 | 2015-09-02 15:19:26 -0700 | [diff] [blame] | 10760 | ironlake_get_pfit_config(crtc, pipe_config); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 10761 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10762 | |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 10763 | if (IS_HASWELL(dev_priv)) |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10764 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 10765 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10766 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 10767 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP && |
| 10768 | !transcoder_is_dsi(pipe_config->cpu_transcoder)) { |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 10769 | pipe_config->pixel_multiplier = |
| 10770 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 10771 | } else { |
| 10772 | pipe_config->pixel_multiplier = 1; |
| 10773 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10774 | |
Imre Deak | 1729050 | 2016-02-12 18:55:11 +0200 | [diff] [blame] | 10775 | out: |
| 10776 | for_each_power_domain(power_domain, power_domain_mask) |
| 10777 | intel_display_power_put(dev_priv, power_domain); |
| 10778 | |
Jani Nikula | cf30429 | 2016-03-18 17:05:41 +0200 | [diff] [blame] | 10779 | return active; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10780 | } |
| 10781 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10782 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10783 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10784 | { |
| 10785 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10786 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10787 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10788 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10789 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10790 | if (plane_state && plane_state->base.visible) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10791 | unsigned int width = plane_state->base.crtc_w; |
| 10792 | unsigned int height = plane_state->base.crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10793 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 10794 | |
| 10795 | switch (stride) { |
| 10796 | default: |
| 10797 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 10798 | width, stride); |
| 10799 | stride = 256; |
| 10800 | /* fallthrough */ |
| 10801 | case 256: |
| 10802 | case 512: |
| 10803 | case 1024: |
| 10804 | case 2048: |
| 10805 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10806 | } |
| 10807 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10808 | cntl |= CURSOR_ENABLE | |
| 10809 | CURSOR_GAMMA_ENABLE | |
| 10810 | CURSOR_FORMAT_ARGB | |
| 10811 | CURSOR_STRIDE(stride); |
| 10812 | |
| 10813 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10814 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10815 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10816 | if (intel_crtc->cursor_cntl != 0 && |
| 10817 | (intel_crtc->cursor_base != base || |
| 10818 | intel_crtc->cursor_size != size || |
| 10819 | intel_crtc->cursor_cntl != cntl)) { |
| 10820 | /* On these chipsets we can only modify the base/size/stride |
| 10821 | * whilst the cursor is disabled. |
| 10822 | */ |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10823 | I915_WRITE(CURCNTR(PIPE_A), 0); |
| 10824 | POSTING_READ(CURCNTR(PIPE_A)); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10825 | intel_crtc->cursor_cntl = 0; |
| 10826 | } |
| 10827 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10828 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10829 | I915_WRITE(CURBASE(PIPE_A), base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10830 | intel_crtc->cursor_base = base; |
| 10831 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10832 | |
| 10833 | if (intel_crtc->cursor_size != size) { |
| 10834 | I915_WRITE(CURSIZE, size); |
| 10835 | intel_crtc->cursor_size = size; |
| 10836 | } |
| 10837 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10838 | if (intel_crtc->cursor_cntl != cntl) { |
Ville Syrjälä | 0b87c24 | 2015-09-22 19:47:51 +0300 | [diff] [blame] | 10839 | I915_WRITE(CURCNTR(PIPE_A), cntl); |
| 10840 | POSTING_READ(CURCNTR(PIPE_A)); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10841 | intel_crtc->cursor_cntl = cntl; |
| 10842 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10843 | } |
| 10844 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10845 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base, |
| 10846 | const struct intel_plane_state *plane_state) |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10847 | { |
| 10848 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10849 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10850 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10851 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | 663f312 | 2015-12-14 13:16:48 +0200 | [diff] [blame] | 10852 | uint32_t cntl = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10853 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 10854 | if (plane_state && plane_state->base.visible) { |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10855 | cntl = MCURSOR_GAMMA_ENABLE; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10856 | switch (plane_state->base.crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10857 | case 64: |
| 10858 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 10859 | break; |
| 10860 | case 128: |
| 10861 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 10862 | break; |
| 10863 | case 256: |
| 10864 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 10865 | break; |
| 10866 | default: |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10867 | MISSING_CASE(plane_state->base.crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 10868 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 10869 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10870 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10871 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 10872 | if (HAS_DDI(dev_priv)) |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 10873 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10874 | |
Ville Syrjälä | f22aa14 | 2016-11-14 18:53:58 +0200 | [diff] [blame] | 10875 | if (plane_state->base.rotation & DRM_ROTATE_180) |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10876 | cntl |= CURSOR_ROTATE_180; |
| 10877 | } |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 10878 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 10879 | if (intel_crtc->cursor_cntl != cntl) { |
| 10880 | I915_WRITE(CURCNTR(pipe), cntl); |
| 10881 | POSTING_READ(CURCNTR(pipe)); |
| 10882 | intel_crtc->cursor_cntl = cntl; |
| 10883 | } |
| 10884 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10885 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10886 | I915_WRITE(CURBASE(pipe), base); |
| 10887 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 10888 | |
| 10889 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 10890 | } |
| 10891 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10892 | /* 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] | 10893 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10894 | const struct intel_plane_state *plane_state) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10895 | { |
| 10896 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 10897 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10898 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10899 | int pipe = intel_crtc->pipe; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10900 | u32 base = intel_crtc->cursor_addr; |
| 10901 | u32 pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10902 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10903 | if (plane_state) { |
| 10904 | int x = plane_state->base.crtc_x; |
| 10905 | int y = plane_state->base.crtc_y; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10906 | |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10907 | if (x < 0) { |
| 10908 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 10909 | x = -x; |
| 10910 | } |
| 10911 | pos |= x << CURSOR_X_SHIFT; |
| 10912 | |
| 10913 | if (y < 0) { |
| 10914 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 10915 | y = -y; |
| 10916 | } |
| 10917 | pos |= y << CURSOR_Y_SHIFT; |
| 10918 | |
| 10919 | /* ILK+ do this automagically */ |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 10920 | if (HAS_GMCH_DISPLAY(dev_priv) && |
Ville Syrjälä | f22aa14 | 2016-11-14 18:53:58 +0200 | [diff] [blame] | 10921 | plane_state->base.rotation & DRM_ROTATE_180) { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10922 | base += (plane_state->base.crtc_h * |
| 10923 | plane_state->base.crtc_w - 1) * 4; |
| 10924 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10925 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10926 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10927 | I915_WRITE(CURPOS(pipe), pos); |
| 10928 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 10929 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10930 | i845_update_cursor(crtc, base, plane_state); |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 10931 | else |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 10932 | i9xx_update_cursor(crtc, base, plane_state); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 10933 | } |
| 10934 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10935 | static bool cursor_size_ok(struct drm_i915_private *dev_priv, |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10936 | uint32_t width, uint32_t height) |
| 10937 | { |
| 10938 | if (width == 0 || height == 0) |
| 10939 | return false; |
| 10940 | |
| 10941 | /* |
| 10942 | * 845g/865g are special in that they are only limited by |
| 10943 | * the width of their cursors, the height is arbitrary up to |
| 10944 | * the precision of the register. Everything else requires |
| 10945 | * square cursors, limited to a few power-of-two sizes. |
| 10946 | */ |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 10947 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10948 | if ((width & 63) != 0) |
| 10949 | return false; |
| 10950 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 10951 | if (width > (IS_I845G(dev_priv) ? 64 : 512)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10952 | return false; |
| 10953 | |
| 10954 | if (height > 1023) |
| 10955 | return false; |
| 10956 | } else { |
| 10957 | switch (width | height) { |
| 10958 | case 256: |
| 10959 | case 128: |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 10960 | if (IS_GEN2(dev_priv)) |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 10961 | return false; |
| 10962 | case 64: |
| 10963 | break; |
| 10964 | default: |
| 10965 | return false; |
| 10966 | } |
| 10967 | } |
| 10968 | |
| 10969 | return true; |
| 10970 | } |
| 10971 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10972 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 10973 | static struct drm_display_mode load_detect_mode = { |
| 10974 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 10975 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 10976 | }; |
| 10977 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 10978 | struct drm_framebuffer * |
| 10979 | __intel_framebuffer_create(struct drm_device *dev, |
| 10980 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 10981 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10982 | { |
| 10983 | struct intel_framebuffer *intel_fb; |
| 10984 | int ret; |
| 10985 | |
| 10986 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10987 | if (!intel_fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10988 | return ERR_PTR(-ENOMEM); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10989 | |
| 10990 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10991 | if (ret) |
| 10992 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10993 | |
| 10994 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10995 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 10996 | err: |
| 10997 | kfree(intel_fb); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 10998 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 10999 | } |
| 11000 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 11001 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 11002 | intel_framebuffer_create(struct drm_device *dev, |
| 11003 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 11004 | struct drm_i915_gem_object *obj) |
| 11005 | { |
| 11006 | struct drm_framebuffer *fb; |
| 11007 | int ret; |
| 11008 | |
| 11009 | ret = i915_mutex_lock_interruptible(dev); |
| 11010 | if (ret) |
| 11011 | return ERR_PTR(ret); |
| 11012 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 11013 | mutex_unlock(&dev->struct_mutex); |
| 11014 | |
| 11015 | return fb; |
| 11016 | } |
| 11017 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11018 | static u32 |
| 11019 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 11020 | { |
| 11021 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 11022 | return ALIGN(pitch, 64); |
| 11023 | } |
| 11024 | |
| 11025 | static u32 |
| 11026 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 11027 | { |
| 11028 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 11029 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11030 | } |
| 11031 | |
| 11032 | static struct drm_framebuffer * |
| 11033 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 11034 | struct drm_display_mode *mode, |
| 11035 | int depth, int bpp) |
| 11036 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 11037 | struct drm_framebuffer *fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11038 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 11039 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11040 | |
Tvrtko Ursulin | 12d79d7 | 2016-12-01 14:16:37 +0000 | [diff] [blame] | 11041 | obj = i915_gem_object_create(to_i915(dev), |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11042 | intel_framebuffer_size_for_mode(mode, bpp)); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 11043 | if (IS_ERR(obj)) |
| 11044 | return ERR_CAST(obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11045 | |
| 11046 | mode_cmd.width = mode->hdisplay; |
| 11047 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 11048 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 11049 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 11050 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11051 | |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 11052 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
| 11053 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 11054 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 11055 | |
| 11056 | return fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11057 | } |
| 11058 | |
| 11059 | static struct drm_framebuffer * |
| 11060 | mode_fits_in_fbdev(struct drm_device *dev, |
| 11061 | struct drm_display_mode *mode) |
| 11062 | { |
Daniel Vetter | 0695726 | 2015-08-10 13:34:08 +0200 | [diff] [blame] | 11063 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11064 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11065 | struct drm_i915_gem_object *obj; |
| 11066 | struct drm_framebuffer *fb; |
| 11067 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 11068 | if (!dev_priv->fbdev) |
| 11069 | return NULL; |
| 11070 | |
| 11071 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11072 | return NULL; |
| 11073 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 11074 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 11075 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11076 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 11077 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 11078 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 11079 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11080 | return NULL; |
| 11081 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 11082 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11083 | return NULL; |
| 11084 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11085 | drm_framebuffer_reference(fb); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11086 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 11087 | #else |
| 11088 | return NULL; |
| 11089 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11090 | } |
| 11091 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 11092 | static int intel_modeset_setup_plane_state(struct drm_atomic_state *state, |
| 11093 | struct drm_crtc *crtc, |
| 11094 | struct drm_display_mode *mode, |
| 11095 | struct drm_framebuffer *fb, |
| 11096 | int x, int y) |
| 11097 | { |
| 11098 | struct drm_plane_state *plane_state; |
| 11099 | int hdisplay, vdisplay; |
| 11100 | int ret; |
| 11101 | |
| 11102 | plane_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 11103 | if (IS_ERR(plane_state)) |
| 11104 | return PTR_ERR(plane_state); |
| 11105 | |
| 11106 | if (mode) |
| 11107 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 11108 | else |
| 11109 | hdisplay = vdisplay = 0; |
| 11110 | |
| 11111 | ret = drm_atomic_set_crtc_for_plane(plane_state, fb ? crtc : NULL); |
| 11112 | if (ret) |
| 11113 | return ret; |
| 11114 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 11115 | plane_state->crtc_x = 0; |
| 11116 | plane_state->crtc_y = 0; |
| 11117 | plane_state->crtc_w = hdisplay; |
| 11118 | plane_state->crtc_h = vdisplay; |
| 11119 | plane_state->src_x = x << 16; |
| 11120 | plane_state->src_y = y << 16; |
| 11121 | plane_state->src_w = hdisplay << 16; |
| 11122 | plane_state->src_h = vdisplay << 16; |
| 11123 | |
| 11124 | return 0; |
| 11125 | } |
| 11126 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 11127 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 11128 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11129 | struct intel_load_detect_pipe *old, |
| 11130 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11131 | { |
| 11132 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 11133 | struct intel_encoder *intel_encoder = |
| 11134 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11135 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 11136 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11137 | struct drm_crtc *crtc = NULL; |
| 11138 | struct drm_device *dev = encoder->dev; |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 11139 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11140 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11141 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11142 | struct drm_atomic_state *state = NULL, *restore_state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11143 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 11144 | struct intel_crtc_state *crtc_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11145 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11146 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11147 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11148 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11149 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11150 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11151 | old->restore_state = NULL; |
| 11152 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11153 | retry: |
| 11154 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 11155 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11156 | goto fail; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 11157 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11158 | /* |
| 11159 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 11160 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11161 | * - if the connector already has an assigned crtc, use it (but make |
| 11162 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 11163 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11164 | * - try to find the first unused crtc that can drive this connector, |
| 11165 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11166 | */ |
| 11167 | |
| 11168 | /* See if we already have a CRTC for this connector */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11169 | if (connector->state->crtc) { |
| 11170 | crtc = connector->state->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 11171 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11172 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 11173 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11174 | goto fail; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 11175 | |
| 11176 | /* Make sure the crtc and connector are running */ |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11177 | goto found; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11178 | } |
| 11179 | |
| 11180 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 11181 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11182 | i++; |
| 11183 | if (!(encoder->possible_crtcs & (1 << i))) |
| 11184 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11185 | |
| 11186 | ret = drm_modeset_lock(&possible_crtc->mutex, ctx); |
| 11187 | if (ret) |
| 11188 | goto fail; |
| 11189 | |
| 11190 | if (possible_crtc->state->enable) { |
| 11191 | drm_modeset_unlock(&possible_crtc->mutex); |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 11192 | continue; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11193 | } |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 11194 | |
| 11195 | crtc = possible_crtc; |
| 11196 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11197 | } |
| 11198 | |
| 11199 | /* |
| 11200 | * If we didn't find an unused CRTC, don't use any. |
| 11201 | */ |
| 11202 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 11203 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11204 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11205 | } |
| 11206 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11207 | found: |
| 11208 | intel_crtc = to_intel_crtc(crtc); |
| 11209 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 11210 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 11211 | if (ret) |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11212 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11213 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11214 | state = drm_atomic_state_alloc(dev); |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11215 | restore_state = drm_atomic_state_alloc(dev); |
| 11216 | if (!state || !restore_state) { |
| 11217 | ret = -ENOMEM; |
| 11218 | goto fail; |
| 11219 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11220 | |
| 11221 | state->acquire_ctx = ctx; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11222 | restore_state->acquire_ctx = ctx; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11223 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11224 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 11225 | if (IS_ERR(connector_state)) { |
| 11226 | ret = PTR_ERR(connector_state); |
| 11227 | goto fail; |
| 11228 | } |
| 11229 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11230 | ret = drm_atomic_set_crtc_for_connector(connector_state, crtc); |
| 11231 | if (ret) |
| 11232 | goto fail; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11233 | |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 11234 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 11235 | if (IS_ERR(crtc_state)) { |
| 11236 | ret = PTR_ERR(crtc_state); |
| 11237 | goto fail; |
| 11238 | } |
| 11239 | |
Maarten Lankhorst | 49d6fa2 | 2015-05-11 10:45:15 +0200 | [diff] [blame] | 11240 | crtc_state->base.active = crtc_state->base.enable = true; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 11241 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 11242 | if (!mode) |
| 11243 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11244 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11245 | /* We need a framebuffer large enough to accommodate all accesses |
| 11246 | * that the plane may generate whilst we perform load detection. |
| 11247 | * We can not rely on the fbcon either being present (we get called |
| 11248 | * during its initialisation to detect all boot displays, or it may |
| 11249 | * not even exist) or that it is large enough to satisfy the |
| 11250 | * requested mode. |
| 11251 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11252 | fb = mode_fits_in_fbdev(dev, mode); |
| 11253 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11254 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11255 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11256 | } else |
| 11257 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11258 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11259 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 11260 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11261 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11262 | |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 11263 | ret = intel_modeset_setup_plane_state(state, crtc, mode, fb, 0, 0); |
| 11264 | if (ret) |
| 11265 | goto fail; |
| 11266 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11267 | drm_framebuffer_unreference(fb); |
| 11268 | |
| 11269 | ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode); |
| 11270 | if (ret) |
| 11271 | goto fail; |
| 11272 | |
| 11273 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector)); |
| 11274 | if (!ret) |
| 11275 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc)); |
| 11276 | if (!ret) |
| 11277 | ret = PTR_ERR_OR_ZERO(drm_atomic_get_plane_state(restore_state, crtc->primary)); |
| 11278 | if (ret) { |
| 11279 | DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret); |
| 11280 | goto fail; |
| 11281 | } |
Ander Conselvan de Oliveira | 8c7b5cc | 2015-04-21 17:13:19 +0300 | [diff] [blame] | 11282 | |
Maarten Lankhorst | 3ba8607 | 2016-02-29 09:18:57 +0100 | [diff] [blame] | 11283 | ret = drm_atomic_commit(state); |
| 11284 | if (ret) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 11285 | 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] | 11286 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11287 | } |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11288 | |
| 11289 | old->restore_state = restore_state; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 11290 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11291 | /* let the connector get through one full cycle before testing */ |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 11292 | intel_wait_for_vblank(dev_priv, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 11293 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 11294 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 11295 | fail: |
Chris Wilson | 7fb71c8 | 2016-10-19 12:37:43 +0100 | [diff] [blame] | 11296 | if (state) { |
| 11297 | drm_atomic_state_put(state); |
| 11298 | state = NULL; |
| 11299 | } |
| 11300 | if (restore_state) { |
| 11301 | drm_atomic_state_put(restore_state); |
| 11302 | restore_state = NULL; |
| 11303 | } |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11304 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 11305 | if (ret == -EDEADLK) { |
| 11306 | drm_modeset_backoff(ctx); |
| 11307 | goto retry; |
| 11308 | } |
| 11309 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 11310 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11311 | } |
| 11312 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 11313 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 11314 | struct intel_load_detect_pipe *old, |
| 11315 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11316 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 11317 | struct intel_encoder *intel_encoder = |
| 11318 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 11319 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11320 | struct drm_atomic_state *state = old->restore_state; |
Ander Conselvan de Oliveira | d3a40d1 | 2015-04-21 17:13:09 +0300 | [diff] [blame] | 11321 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11322 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11323 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11324 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11325 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 11326 | |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11327 | if (!state) |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 11328 | return; |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11329 | |
| 11330 | ret = drm_atomic_commit(state); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 11331 | if (ret) |
Maarten Lankhorst | edde361 | 2016-02-17 09:18:35 +0100 | [diff] [blame] | 11332 | DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 11333 | drm_atomic_state_put(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11334 | } |
| 11335 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11336 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11337 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11338 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11339 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11340 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 11341 | |
| 11342 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 11343 | return dev_priv->vbt.lvds_ssc_freq; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 11344 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11345 | return 120000; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11346 | else if (!IS_GEN2(dev_priv)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11347 | return 96000; |
| 11348 | else |
| 11349 | return 48000; |
| 11350 | } |
| 11351 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11352 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11353 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11354 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11355 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11356 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11357 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11358 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 11359 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11360 | u32 fp; |
Ander Conselvan de Oliveira | 9e2c847 | 2016-05-04 12:11:57 +0300 | [diff] [blame] | 11361 | struct dpll clock; |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 11362 | int port_clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11363 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11364 | |
| 11365 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 11366 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11367 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 11368 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11369 | |
| 11370 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 11371 | if (IS_PINEVIEW(dev_priv)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 11372 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 11373 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 11374 | } else { |
| 11375 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 11376 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 11377 | } |
| 11378 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11379 | if (!IS_GEN2(dev_priv)) { |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 11380 | if (IS_PINEVIEW(dev_priv)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 11381 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 11382 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 11383 | else |
| 11384 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11385 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 11386 | |
| 11387 | switch (dpll & DPLL_MODE_MASK) { |
| 11388 | case DPLLB_MODE_DAC_SERIAL: |
| 11389 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 11390 | 5 : 10; |
| 11391 | break; |
| 11392 | case DPLLB_MODE_LVDS: |
| 11393 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 11394 | 7 : 14; |
| 11395 | break; |
| 11396 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 11397 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11398 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11399 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11400 | } |
| 11401 | |
Ville Syrjälä | 9b1e14f | 2016-10-31 22:37:15 +0200 | [diff] [blame] | 11402 | if (IS_PINEVIEW(dev_priv)) |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 11403 | port_clock = pnv_calc_dpll_params(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 11404 | else |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 11405 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11406 | } else { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 11407 | u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 11408 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11409 | |
| 11410 | if (is_lvds) { |
| 11411 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 11412 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 11413 | |
| 11414 | if (lvds & LVDS_CLKB_POWER_UP) |
| 11415 | clock.p2 = 7; |
| 11416 | else |
| 11417 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11418 | } else { |
| 11419 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 11420 | clock.p1 = 2; |
| 11421 | else { |
| 11422 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 11423 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 11424 | } |
| 11425 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 11426 | clock.p2 = 4; |
| 11427 | else |
| 11428 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11429 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 11430 | |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 11431 | port_clock = i9xx_calc_dpll_params(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11432 | } |
| 11433 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11434 | /* |
| 11435 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11436 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11437 | * encoder's get_config() function. |
| 11438 | */ |
Imre Deak | dccbea3 | 2015-06-22 23:35:51 +0300 | [diff] [blame] | 11439 | pipe_config->port_clock = port_clock; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11440 | } |
| 11441 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 11442 | int intel_dotclock_calculate(int link_freq, |
| 11443 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11444 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11445 | /* |
| 11446 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 11447 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11448 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 11449 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11450 | * |
| 11451 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 11452 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11453 | */ |
| 11454 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 11455 | if (!m_n->link_n) |
| 11456 | return 0; |
| 11457 | |
| 11458 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 11459 | } |
| 11460 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11461 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11462 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 11463 | { |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11464 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11465 | |
| 11466 | /* read out port_clock from the DPLL */ |
| 11467 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 11468 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11469 | /* |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 11470 | * In case there is an active pipe without active ports, |
| 11471 | * we may need some idea for the dotclock anyway. |
| 11472 | * Calculate one based on the FDI configuration. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11473 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11474 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 11475 | intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11476 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11477 | } |
| 11478 | |
| 11479 | /** Returns the currently programmed mode of the given pipe. */ |
| 11480 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 11481 | struct drm_crtc *crtc) |
| 11482 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11483 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11484 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11485 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11486 | struct drm_display_mode *mode; |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 11487 | struct intel_crtc_state *pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 11488 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 11489 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 11490 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 11491 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 11492 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11493 | |
| 11494 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 11495 | if (!mode) |
| 11496 | return NULL; |
| 11497 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 11498 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 11499 | if (!pipe_config) { |
| 11500 | kfree(mode); |
| 11501 | return NULL; |
| 11502 | } |
| 11503 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11504 | /* |
| 11505 | * Construct a pipe_config sufficient for getting the clock info |
| 11506 | * back out of crtc_clock_get. |
| 11507 | * |
| 11508 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 11509 | * to use a real value here instead. |
| 11510 | */ |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 11511 | pipe_config->cpu_transcoder = (enum transcoder) pipe; |
| 11512 | pipe_config->pixel_multiplier = 1; |
| 11513 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 11514 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 11515 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
| 11516 | i9xx_crtc_clock_get(intel_crtc, pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11517 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 11518 | mode->clock = pipe_config->port_clock / pipe_config->pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11519 | mode->hdisplay = (htot & 0xffff) + 1; |
| 11520 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 11521 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 11522 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 11523 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 11524 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 11525 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 11526 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 11527 | |
| 11528 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11529 | |
Tvrtko Ursulin | 3f36b93 | 2016-01-19 15:25:17 +0000 | [diff] [blame] | 11530 | kfree(pipe_config); |
| 11531 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11532 | return mode; |
| 11533 | } |
| 11534 | |
| 11535 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 11536 | { |
| 11537 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11538 | struct drm_device *dev = crtc->dev; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11539 | struct intel_flip_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11540 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 11541 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11542 | work = intel_crtc->flip_work; |
| 11543 | intel_crtc->flip_work = NULL; |
| 11544 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11545 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11546 | if (work) { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11547 | cancel_work_sync(&work->mmio_work); |
| 11548 | cancel_work_sync(&work->unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11549 | kfree(work); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11550 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11551 | |
| 11552 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 11553 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11554 | kfree(intel_crtc); |
| 11555 | } |
| 11556 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11557 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 11558 | { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11559 | struct intel_flip_work *work = |
| 11560 | container_of(__work, struct intel_flip_work, unpin_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11561 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 11562 | struct drm_device *dev = crtc->base.dev; |
| 11563 | struct drm_plane *primary = crtc->base.primary; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11564 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11565 | if (is_mmio_work(work)) |
| 11566 | flush_work(&work->mmio_work); |
| 11567 | |
| 11568 | mutex_lock(&dev->struct_mutex); |
| 11569 | intel_unpin_fb_obj(work->old_fb, primary->state->rotation); |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 11570 | i915_gem_object_put(work->pending_flip_obj); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11571 | mutex_unlock(&dev->struct_mutex); |
| 11572 | |
Chris Wilson | e8a261e | 2016-07-20 13:31:49 +0100 | [diff] [blame] | 11573 | i915_gem_request_put(work->flip_queued_req); |
| 11574 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 11575 | intel_frontbuffer_flip_complete(to_i915(dev), |
| 11576 | to_intel_plane(primary)->frontbuffer_bit); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11577 | intel_fbc_post_update(crtc); |
| 11578 | drm_framebuffer_unreference(work->old_fb); |
| 11579 | |
| 11580 | BUG_ON(atomic_read(&crtc->unpin_work_count) == 0); |
| 11581 | atomic_dec(&crtc->unpin_work_count); |
| 11582 | |
| 11583 | kfree(work); |
| 11584 | } |
| 11585 | |
| 11586 | /* Is 'a' after or equal to 'b'? */ |
| 11587 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 11588 | { |
| 11589 | return !((a - b) & 0x80000000); |
| 11590 | } |
| 11591 | |
| 11592 | static bool __pageflip_finished_cs(struct intel_crtc *crtc, |
| 11593 | struct intel_flip_work *work) |
| 11594 | { |
| 11595 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11596 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11597 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 11598 | if (abort_flip_on_reset(crtc)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11599 | return true; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11600 | |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11601 | /* |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11602 | * The relevant registers doen't exist on pre-ctg. |
| 11603 | * As the flip done interrupt doesn't trigger for mmio |
| 11604 | * flips on gmch platforms, a flip count check isn't |
| 11605 | * really needed there. But since ctg has the registers, |
| 11606 | * include it in the check anyway. |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11607 | */ |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 11608 | if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11609 | return true; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11610 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11611 | /* |
| 11612 | * BDW signals flip done immediately if the plane |
| 11613 | * is disabled, even if the plane enable is already |
| 11614 | * armed to occur at the next vblank :( |
| 11615 | */ |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 11616 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11617 | /* |
| 11618 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 11619 | * used the same base address. In that case the mmio flip might |
| 11620 | * have completed, but the CS hasn't even executed the flip yet. |
| 11621 | * |
| 11622 | * A flip count check isn't enough as the CS might have updated |
| 11623 | * the base address just after start of vblank, but before we |
| 11624 | * managed to process the interrupt. This means we'd complete the |
| 11625 | * CS flip too soon. |
| 11626 | * |
| 11627 | * Combining both checks should get us a good enough result. It may |
| 11628 | * still happen that the CS flip has been executed, but has not |
| 11629 | * yet actually completed. But in case the base address is the same |
| 11630 | * anyway, we don't really care. |
| 11631 | */ |
| 11632 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 11633 | crtc->flip_work->gtt_offset && |
| 11634 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_G4X(crtc->pipe)), |
| 11635 | crtc->flip_work->flip_count); |
| 11636 | } |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 11637 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11638 | static bool |
| 11639 | __pageflip_finished_mmio(struct intel_crtc *crtc, |
| 11640 | struct intel_flip_work *work) |
| 11641 | { |
| 11642 | /* |
| 11643 | * MMIO work completes when vblank is different from |
| 11644 | * flip_queued_vblank. |
| 11645 | * |
| 11646 | * Reset counter value doesn't matter, this is handled by |
| 11647 | * i915_wait_request finishing early, so no need to handle |
| 11648 | * reset here. |
| 11649 | */ |
| 11650 | return intel_crtc_get_vblank_counter(crtc) != work->flip_queued_vblank; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11651 | } |
| 11652 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11653 | |
| 11654 | static bool pageflip_finished(struct intel_crtc *crtc, |
| 11655 | struct intel_flip_work *work) |
| 11656 | { |
| 11657 | if (!atomic_read(&work->pending)) |
| 11658 | return false; |
| 11659 | |
| 11660 | smp_rmb(); |
| 11661 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11662 | if (is_mmio_work(work)) |
| 11663 | return __pageflip_finished_mmio(crtc, work); |
| 11664 | else |
| 11665 | return __pageflip_finished_cs(crtc, work); |
| 11666 | } |
| 11667 | |
| 11668 | void intel_finish_page_flip_cs(struct drm_i915_private *dev_priv, int pipe) |
| 11669 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 11670 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 11671 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11672 | struct intel_flip_work *work; |
| 11673 | unsigned long flags; |
| 11674 | |
| 11675 | /* Ignore early vblank irqs */ |
| 11676 | if (!crtc) |
| 11677 | return; |
| 11678 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 11679 | /* |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11680 | * This is called both by irq handlers and the reset code (to complete |
| 11681 | * lost pageflips) so needs the full irqsave spinlocks. |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11682 | */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11683 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 11684 | work = crtc->flip_work; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11685 | |
| 11686 | if (work != NULL && |
| 11687 | !is_mmio_work(work) && |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 11688 | pageflip_finished(crtc, work)) |
| 11689 | page_flip_completed(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11690 | |
| 11691 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 11692 | } |
| 11693 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11694 | void intel_finish_page_flip_mmio(struct drm_i915_private *dev_priv, int pipe) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 11695 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 11696 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 11697 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11698 | struct intel_flip_work *work; |
| 11699 | unsigned long flags; |
| 11700 | |
| 11701 | /* Ignore early vblank irqs */ |
| 11702 | if (!crtc) |
| 11703 | return; |
| 11704 | |
| 11705 | /* |
| 11706 | * This is called both by irq handlers and the reset code (to complete |
| 11707 | * lost pageflips) so needs the full irqsave spinlocks. |
| 11708 | */ |
| 11709 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 11710 | work = crtc->flip_work; |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11711 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11712 | if (work != NULL && |
| 11713 | is_mmio_work(work) && |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 11714 | pageflip_finished(crtc, work)) |
| 11715 | page_flip_completed(crtc); |
Maarten Lankhorst | 6885843 | 2016-05-17 15:07:52 +0200 | [diff] [blame] | 11716 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 11717 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 11718 | } |
| 11719 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11720 | static inline void intel_mark_page_flip_active(struct intel_crtc *crtc, |
| 11721 | struct intel_flip_work *work) |
| 11722 | { |
| 11723 | work->flip_queued_vblank = intel_crtc_get_vblank_counter(crtc); |
| 11724 | |
| 11725 | /* Ensure that the work item is consistent when activating it ... */ |
| 11726 | smp_mb__before_atomic(); |
| 11727 | atomic_set(&work->pending, 1); |
| 11728 | } |
| 11729 | |
| 11730 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 11731 | struct drm_crtc *crtc, |
| 11732 | struct drm_framebuffer *fb, |
| 11733 | struct drm_i915_gem_object *obj, |
| 11734 | struct drm_i915_gem_request *req, |
| 11735 | uint32_t flags) |
| 11736 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 11737 | struct intel_ring *ring = req->ring; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11738 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11739 | u32 flip_mask; |
| 11740 | int ret; |
| 11741 | |
| 11742 | ret = intel_ring_begin(req, 6); |
| 11743 | if (ret) |
| 11744 | return ret; |
| 11745 | |
| 11746 | /* Can't queue multiple flips, so wait for the previous |
| 11747 | * one to finish before executing the next. |
| 11748 | */ |
| 11749 | if (intel_crtc->plane) |
| 11750 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11751 | else |
| 11752 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11753 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 11754 | intel_ring_emit(ring, MI_NOOP); |
| 11755 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11756 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11757 | intel_ring_emit(ring, fb->pitches[0]); |
| 11758 | intel_ring_emit(ring, intel_crtc->flip_work->gtt_offset); |
| 11759 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11760 | |
| 11761 | return 0; |
| 11762 | } |
| 11763 | |
| 11764 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 11765 | struct drm_crtc *crtc, |
| 11766 | struct drm_framebuffer *fb, |
| 11767 | struct drm_i915_gem_object *obj, |
| 11768 | struct drm_i915_gem_request *req, |
| 11769 | uint32_t flags) |
| 11770 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 11771 | struct intel_ring *ring = req->ring; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11772 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11773 | u32 flip_mask; |
| 11774 | int ret; |
| 11775 | |
| 11776 | ret = intel_ring_begin(req, 6); |
| 11777 | if (ret) |
| 11778 | return ret; |
| 11779 | |
| 11780 | if (intel_crtc->plane) |
| 11781 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 11782 | else |
| 11783 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11784 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 11785 | intel_ring_emit(ring, MI_NOOP); |
| 11786 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11787 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11788 | intel_ring_emit(ring, fb->pitches[0]); |
| 11789 | intel_ring_emit(ring, intel_crtc->flip_work->gtt_offset); |
| 11790 | intel_ring_emit(ring, MI_NOOP); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11791 | |
| 11792 | return 0; |
| 11793 | } |
| 11794 | |
| 11795 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 11796 | struct drm_crtc *crtc, |
| 11797 | struct drm_framebuffer *fb, |
| 11798 | struct drm_i915_gem_object *obj, |
| 11799 | struct drm_i915_gem_request *req, |
| 11800 | uint32_t flags) |
| 11801 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 11802 | struct intel_ring *ring = req->ring; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11803 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11804 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11805 | uint32_t pf, pipesrc; |
| 11806 | int ret; |
| 11807 | |
| 11808 | ret = intel_ring_begin(req, 4); |
| 11809 | if (ret) |
| 11810 | return ret; |
| 11811 | |
| 11812 | /* i965+ uses the linear or tiled offsets from the |
| 11813 | * Display Registers (which do not change across a page-flip) |
| 11814 | * so we need only reprogram the base address. |
| 11815 | */ |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11816 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11817 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11818 | intel_ring_emit(ring, fb->pitches[0]); |
| 11819 | intel_ring_emit(ring, intel_crtc->flip_work->gtt_offset | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 11820 | intel_fb_modifier_to_tiling(fb->modifier)); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11821 | |
| 11822 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 11823 | * untested on non-native modes, so ignore it for now. |
| 11824 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 11825 | */ |
| 11826 | pf = 0; |
| 11827 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11828 | intel_ring_emit(ring, pf | pipesrc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11829 | |
| 11830 | return 0; |
| 11831 | } |
| 11832 | |
| 11833 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 11834 | struct drm_crtc *crtc, |
| 11835 | struct drm_framebuffer *fb, |
| 11836 | struct drm_i915_gem_object *obj, |
| 11837 | struct drm_i915_gem_request *req, |
| 11838 | uint32_t flags) |
| 11839 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 11840 | struct intel_ring *ring = req->ring; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11841 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11842 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11843 | uint32_t pf, pipesrc; |
| 11844 | int ret; |
| 11845 | |
| 11846 | ret = intel_ring_begin(req, 4); |
| 11847 | if (ret) |
| 11848 | return ret; |
| 11849 | |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11850 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11851 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 11852 | intel_ring_emit(ring, fb->pitches[0] | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 11853 | intel_fb_modifier_to_tiling(fb->modifier)); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11854 | intel_ring_emit(ring, intel_crtc->flip_work->gtt_offset); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11855 | |
| 11856 | /* Contrary to the suggestions in the documentation, |
| 11857 | * "Enable Panel Fitter" does not seem to be required when page |
| 11858 | * flipping with a non-native mode, and worse causes a normal |
| 11859 | * modeset to fail. |
| 11860 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 11861 | */ |
| 11862 | pf = 0; |
| 11863 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11864 | intel_ring_emit(ring, pf | pipesrc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11865 | |
| 11866 | return 0; |
| 11867 | } |
| 11868 | |
| 11869 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 11870 | struct drm_crtc *crtc, |
| 11871 | struct drm_framebuffer *fb, |
| 11872 | struct drm_i915_gem_object *obj, |
| 11873 | struct drm_i915_gem_request *req, |
| 11874 | uint32_t flags) |
| 11875 | { |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11876 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 11877 | struct intel_ring *ring = req->ring; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11878 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11879 | uint32_t plane_bit = 0; |
| 11880 | int len, ret; |
| 11881 | |
| 11882 | switch (intel_crtc->plane) { |
| 11883 | case PLANE_A: |
| 11884 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 11885 | break; |
| 11886 | case PLANE_B: |
| 11887 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 11888 | break; |
| 11889 | case PLANE_C: |
| 11890 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 11891 | break; |
| 11892 | default: |
| 11893 | WARN_ONCE(1, "unknown plane in flip command\n"); |
| 11894 | return -ENODEV; |
| 11895 | } |
| 11896 | |
| 11897 | len = 4; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11898 | if (req->engine->id == RCS) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11899 | len += 6; |
| 11900 | /* |
| 11901 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 11902 | * 48bits addresses, and we need a NOOP for the batch size to |
| 11903 | * stay even. |
| 11904 | */ |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11905 | if (IS_GEN8(dev_priv)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11906 | len += 2; |
| 11907 | } |
| 11908 | |
| 11909 | /* |
| 11910 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 11911 | * "The full packet must be contained within the same cache line." |
| 11912 | * |
| 11913 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 11914 | * cacheline, if we ever start emitting more commands before |
| 11915 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 11916 | * then do the cacheline alignment, and finally emit the |
| 11917 | * MI_DISPLAY_FLIP. |
| 11918 | */ |
| 11919 | ret = intel_ring_cacheline_align(req); |
| 11920 | if (ret) |
| 11921 | return ret; |
| 11922 | |
| 11923 | ret = intel_ring_begin(req, len); |
| 11924 | if (ret) |
| 11925 | return ret; |
| 11926 | |
| 11927 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 11928 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 11929 | * more than one flip event at any time (or ensure that one flip message |
| 11930 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 11931 | * Experimentation says that BCS works despite DERRMR masking all |
| 11932 | * flip-done completion events and that unmasking all planes at once |
| 11933 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 11934 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 11935 | */ |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11936 | if (req->engine->id == RCS) { |
| 11937 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 11938 | intel_ring_emit_reg(ring, DERRMR); |
| 11939 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11940 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 11941 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11942 | if (IS_GEN8(dev_priv)) |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11943 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11944 | MI_SRM_LRM_GLOBAL_GTT); |
| 11945 | else |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11946 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11947 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11948 | intel_ring_emit_reg(ring, DERRMR); |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 11949 | intel_ring_emit(ring, |
| 11950 | i915_ggtt_offset(req->engine->scratch) + 256); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 11951 | if (IS_GEN8(dev_priv)) { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11952 | intel_ring_emit(ring, 0); |
| 11953 | intel_ring_emit(ring, MI_NOOP); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11954 | } |
| 11955 | } |
| 11956 | |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11957 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 11958 | intel_ring_emit(ring, fb->pitches[0] | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 11959 | intel_fb_modifier_to_tiling(fb->modifier)); |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 11960 | intel_ring_emit(ring, intel_crtc->flip_work->gtt_offset); |
| 11961 | intel_ring_emit(ring, (MI_NOOP)); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11962 | |
| 11963 | return 0; |
| 11964 | } |
| 11965 | |
| 11966 | static bool use_mmio_flip(struct intel_engine_cs *engine, |
| 11967 | struct drm_i915_gem_object *obj) |
| 11968 | { |
| 11969 | /* |
| 11970 | * This is not being used for older platforms, because |
| 11971 | * non-availability of flip done interrupt forces us to use |
| 11972 | * CS flips. Older platforms derive flip done using some clever |
| 11973 | * tricks involving the flip_pending status bits and vblank irqs. |
| 11974 | * So using MMIO flips there would disrupt this mechanism. |
| 11975 | */ |
| 11976 | |
| 11977 | if (engine == NULL) |
| 11978 | return true; |
| 11979 | |
| 11980 | if (INTEL_GEN(engine->i915) < 5) |
| 11981 | return false; |
| 11982 | |
| 11983 | if (i915.use_mmio_flip < 0) |
| 11984 | return false; |
| 11985 | else if (i915.use_mmio_flip > 0) |
| 11986 | return true; |
| 11987 | else if (i915.enable_execlists) |
| 11988 | return true; |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 11989 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 11990 | return engine != i915_gem_object_last_write_engine(obj); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11991 | } |
| 11992 | |
| 11993 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 11994 | unsigned int rotation, |
| 11995 | struct intel_flip_work *work) |
| 11996 | { |
| 11997 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 11998 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 11999 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
| 12000 | const enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | d219677 | 2016-01-28 18:33:11 +0200 | [diff] [blame] | 12001 | u32 ctl, stride = skl_plane_stride(fb, 0, rotation); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12002 | |
| 12003 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 12004 | ctl &= ~PLANE_CTL_TILED_MASK; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 12005 | switch (fb->modifier) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12006 | case DRM_FORMAT_MOD_NONE: |
| 12007 | break; |
| 12008 | case I915_FORMAT_MOD_X_TILED: |
| 12009 | ctl |= PLANE_CTL_TILED_X; |
| 12010 | break; |
| 12011 | case I915_FORMAT_MOD_Y_TILED: |
| 12012 | ctl |= PLANE_CTL_TILED_Y; |
| 12013 | break; |
| 12014 | case I915_FORMAT_MOD_Yf_TILED: |
| 12015 | ctl |= PLANE_CTL_TILED_YF; |
| 12016 | break; |
| 12017 | default: |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 12018 | MISSING_CASE(fb->modifier); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12019 | } |
| 12020 | |
| 12021 | /* |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12022 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 12023 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 12024 | */ |
| 12025 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 12026 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 12027 | |
| 12028 | I915_WRITE(PLANE_SURF(pipe, 0), work->gtt_offset); |
| 12029 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 12030 | } |
| 12031 | |
| 12032 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc, |
| 12033 | struct intel_flip_work *work) |
| 12034 | { |
| 12035 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12036 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 72618eb | 2016-02-04 20:38:20 +0200 | [diff] [blame] | 12037 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12038 | i915_reg_t reg = DSPCNTR(intel_crtc->plane); |
| 12039 | u32 dspcntr; |
| 12040 | |
| 12041 | dspcntr = I915_READ(reg); |
| 12042 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 12043 | if (fb->modifier == I915_FORMAT_MOD_X_TILED) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12044 | dspcntr |= DISPPLANE_TILED; |
| 12045 | else |
| 12046 | dspcntr &= ~DISPPLANE_TILED; |
| 12047 | |
| 12048 | I915_WRITE(reg, dspcntr); |
| 12049 | |
| 12050 | I915_WRITE(DSPSURF(intel_crtc->plane), work->gtt_offset); |
| 12051 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
| 12052 | } |
| 12053 | |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 12054 | static void intel_mmio_flip_work_func(struct work_struct *w) |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 12055 | { |
Maarten Lankhorst | 51cbaf0 | 2016-05-17 15:07:49 +0200 | [diff] [blame] | 12056 | struct intel_flip_work *work = |
| 12057 | container_of(w, struct intel_flip_work, mmio_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12058 | struct intel_crtc *crtc = to_intel_crtc(work->crtc); |
| 12059 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
| 12060 | struct intel_framebuffer *intel_fb = |
| 12061 | to_intel_framebuffer(crtc->base.primary->fb); |
| 12062 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 12063 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12064 | WARN_ON(i915_gem_object_wait(obj, 0, MAX_SCHEDULE_TIMEOUT, NULL) < 0); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12065 | |
| 12066 | intel_pipe_update_start(crtc); |
| 12067 | |
| 12068 | if (INTEL_GEN(dev_priv) >= 9) |
| 12069 | skl_do_mmio_flip(crtc, work->rotation, work); |
| 12070 | else |
| 12071 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 12072 | ilk_do_mmio_flip(crtc, work); |
| 12073 | |
| 12074 | intel_pipe_update_end(crtc, work); |
| 12075 | } |
| 12076 | |
| 12077 | static int intel_default_queue_flip(struct drm_device *dev, |
| 12078 | struct drm_crtc *crtc, |
| 12079 | struct drm_framebuffer *fb, |
| 12080 | struct drm_i915_gem_object *obj, |
| 12081 | struct drm_i915_gem_request *req, |
| 12082 | uint32_t flags) |
| 12083 | { |
| 12084 | return -ENODEV; |
| 12085 | } |
| 12086 | |
| 12087 | static bool __pageflip_stall_check_cs(struct drm_i915_private *dev_priv, |
| 12088 | struct intel_crtc *intel_crtc, |
| 12089 | struct intel_flip_work *work) |
| 12090 | { |
| 12091 | u32 addr, vblank; |
| 12092 | |
| 12093 | if (!atomic_read(&work->pending)) |
| 12094 | return false; |
| 12095 | |
| 12096 | smp_rmb(); |
| 12097 | |
| 12098 | vblank = intel_crtc_get_vblank_counter(intel_crtc); |
| 12099 | if (work->flip_ready_vblank == 0) { |
| 12100 | if (work->flip_queued_req && |
Chris Wilson | f69a02c | 2016-07-01 17:23:16 +0100 | [diff] [blame] | 12101 | !i915_gem_request_completed(work->flip_queued_req)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12102 | return false; |
| 12103 | |
| 12104 | work->flip_ready_vblank = vblank; |
| 12105 | } |
| 12106 | |
| 12107 | if (vblank - work->flip_ready_vblank < 3) |
| 12108 | return false; |
| 12109 | |
| 12110 | /* Potential stall - if we see that the flip has happened, |
| 12111 | * assume a missed interrupt. */ |
| 12112 | if (INTEL_GEN(dev_priv) >= 4) |
| 12113 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 12114 | else |
| 12115 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 12116 | |
| 12117 | /* There is a potential issue here with a false positive after a flip |
| 12118 | * to the same address. We could address this by checking for a |
| 12119 | * non-incrementing frame counter. |
| 12120 | */ |
| 12121 | return addr == work->gtt_offset; |
| 12122 | } |
| 12123 | |
| 12124 | void intel_check_page_flip(struct drm_i915_private *dev_priv, int pipe) |
| 12125 | { |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 12126 | struct drm_device *dev = &dev_priv->drm; |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 12127 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12128 | struct intel_flip_work *work; |
| 12129 | |
| 12130 | WARN_ON(!in_interrupt()); |
| 12131 | |
| 12132 | if (crtc == NULL) |
| 12133 | return; |
| 12134 | |
| 12135 | spin_lock(&dev->event_lock); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 12136 | work = crtc->flip_work; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12137 | |
| 12138 | if (work != NULL && !is_mmio_work(work) && |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 12139 | __pageflip_stall_check_cs(dev_priv, crtc, work)) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12140 | WARN_ONCE(1, |
| 12141 | "Kicking stuck page flip: queued at %d, now %d\n", |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 12142 | work->flip_queued_vblank, intel_crtc_get_vblank_counter(crtc)); |
| 12143 | page_flip_completed(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12144 | work = NULL; |
| 12145 | } |
| 12146 | |
| 12147 | if (work != NULL && !is_mmio_work(work) && |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 12148 | intel_crtc_get_vblank_counter(crtc) - work->flip_queued_vblank > 1) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12149 | intel_queue_rps_boost_for_request(work->flip_queued_req); |
| 12150 | spin_unlock(&dev->event_lock); |
| 12151 | } |
| 12152 | |
| 12153 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 12154 | struct drm_framebuffer *fb, |
| 12155 | struct drm_pending_vblank_event *event, |
| 12156 | uint32_t page_flip_flags) |
| 12157 | { |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12158 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12159 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12160 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 12161 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12162 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12163 | struct drm_plane *primary = crtc->primary; |
| 12164 | enum pipe pipe = intel_crtc->pipe; |
| 12165 | struct intel_flip_work *work; |
| 12166 | struct intel_engine_cs *engine; |
| 12167 | bool mmio_flip; |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12168 | struct drm_i915_gem_request *request; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 12169 | struct i915_vma *vma; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12170 | int ret; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 12171 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12172 | /* |
| 12173 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 12174 | * check to be safe. In the future we may enable pageflipping from |
| 12175 | * a disabled primary plane. |
| 12176 | */ |
| 12177 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 12178 | return -EBUSY; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 12179 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12180 | /* Can't change pixel format via MI display flips. */ |
| 12181 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
| 12182 | return -EINVAL; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12183 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12184 | /* |
| 12185 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 12186 | * Note that pitch changes could also affect these register. |
| 12187 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12188 | if (INTEL_GEN(dev_priv) > 3 && |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12189 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 12190 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
| 12191 | return -EINVAL; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12192 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12193 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 12194 | goto out_hang; |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12195 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12196 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
| 12197 | if (work == NULL) |
| 12198 | return -ENOMEM; |
| 12199 | |
| 12200 | work->event = event; |
| 12201 | work->crtc = crtc; |
| 12202 | work->old_fb = old_fb; |
| 12203 | INIT_WORK(&work->unpin_work, intel_unpin_work_fn); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 12204 | |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 12205 | ret = drm_crtc_vblank_get(crtc); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12206 | if (ret) |
| 12207 | goto free_work; |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 12208 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12209 | /* We borrow the event spin lock for protecting flip_work */ |
| 12210 | spin_lock_irq(&dev->event_lock); |
| 12211 | if (intel_crtc->flip_work) { |
| 12212 | /* Before declaring the flip queue wedged, check if |
| 12213 | * the hardware completed the operation behind our backs. |
| 12214 | */ |
| 12215 | if (pageflip_finished(intel_crtc, intel_crtc->flip_work)) { |
| 12216 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 12217 | page_flip_completed(intel_crtc); |
| 12218 | } else { |
| 12219 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
| 12220 | spin_unlock_irq(&dev->event_lock); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 12221 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12222 | drm_crtc_vblank_put(crtc); |
| 12223 | kfree(work); |
| 12224 | return -EBUSY; |
| 12225 | } |
| 12226 | } |
| 12227 | intel_crtc->flip_work = work; |
| 12228 | spin_unlock_irq(&dev->event_lock); |
Alex Goins | fd8e058 | 2015-11-25 18:43:38 -0800 | [diff] [blame] | 12229 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12230 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 12231 | flush_workqueue(dev_priv->wq); |
| 12232 | |
| 12233 | /* Reference the objects for the scheduled work. */ |
| 12234 | drm_framebuffer_reference(work->old_fb); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12235 | |
| 12236 | crtc->primary->fb = fb; |
| 12237 | update_state_fb(crtc->primary); |
Maarten Lankhorst | faf68d9 | 2016-06-14 14:24:20 +0200 | [diff] [blame] | 12238 | |
Chris Wilson | 25dc556 | 2016-07-20 13:31:52 +0100 | [diff] [blame] | 12239 | work->pending_flip_obj = i915_gem_object_get(obj); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12240 | |
| 12241 | ret = i915_mutex_lock_interruptible(dev); |
| 12242 | if (ret) |
| 12243 | goto cleanup; |
| 12244 | |
Chris Wilson | 8af29b0 | 2016-09-09 14:11:47 +0100 | [diff] [blame] | 12245 | intel_crtc->reset_count = i915_reset_count(&dev_priv->gpu_error); |
| 12246 | if (i915_reset_in_progress_or_wedged(&dev_priv->gpu_error)) { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12247 | ret = -EIO; |
Matthew Auld | ddbb271 | 2016-11-28 10:36:48 +0000 | [diff] [blame] | 12248 | goto unlock; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12249 | } |
| 12250 | |
| 12251 | atomic_inc(&intel_crtc->unpin_work_count); |
| 12252 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12253 | if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12254 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_G4X(pipe)) + 1; |
| 12255 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 12256 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 12257 | engine = dev_priv->engine[BCS]; |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 12258 | if (fb->modifier != old_fb->modifier) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12259 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 12260 | engine = NULL; |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 12261 | } else if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv)) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 12262 | engine = dev_priv->engine[BCS]; |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12263 | } else if (INTEL_GEN(dev_priv) >= 7) { |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 12264 | engine = i915_gem_object_last_write_engine(obj); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12265 | if (engine == NULL || engine->id != RCS) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 12266 | engine = dev_priv->engine[BCS]; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12267 | } else { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 12268 | engine = dev_priv->engine[RCS]; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12269 | } |
| 12270 | |
| 12271 | mmio_flip = use_mmio_flip(engine, obj); |
| 12272 | |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 12273 | vma = intel_pin_and_fence_fb_obj(fb, primary->state->rotation); |
| 12274 | if (IS_ERR(vma)) { |
| 12275 | ret = PTR_ERR(vma); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12276 | goto cleanup_pending; |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 12277 | } |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12278 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 12279 | work->gtt_offset = intel_fb_gtt_offset(fb, primary->state->rotation); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12280 | work->gtt_offset += intel_crtc->dspaddr_offset; |
| 12281 | work->rotation = crtc->primary->state->rotation; |
| 12282 | |
Paulo Zanoni | 1f061316 | 2016-08-17 16:41:44 -0300 | [diff] [blame] | 12283 | /* |
| 12284 | * There's the potential that the next frame will not be compatible with |
| 12285 | * FBC, so we want to call pre_update() before the actual page flip. |
| 12286 | * The problem is that pre_update() caches some information about the fb |
| 12287 | * object, so we want to do this only after the object is pinned. Let's |
| 12288 | * be on the safe side and do this immediately before scheduling the |
| 12289 | * flip. |
| 12290 | */ |
| 12291 | intel_fbc_pre_update(intel_crtc, intel_crtc->config, |
| 12292 | to_intel_plane_state(primary->state)); |
| 12293 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12294 | if (mmio_flip) { |
| 12295 | INIT_WORK(&work->mmio_work, intel_mmio_flip_work_func); |
Imre Deak | 6277c8d | 2016-09-20 14:58:19 +0300 | [diff] [blame] | 12296 | queue_work(system_unbound_wq, &work->mmio_work); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12297 | } else { |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 12298 | request = i915_gem_request_alloc(engine, |
| 12299 | dev_priv->kernel_context); |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12300 | if (IS_ERR(request)) { |
| 12301 | ret = PTR_ERR(request); |
| 12302 | goto cleanup_unpin; |
| 12303 | } |
| 12304 | |
Chris Wilson | a2bc469 | 2016-09-09 14:11:56 +0100 | [diff] [blame] | 12305 | ret = i915_gem_request_await_object(request, obj, false); |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12306 | if (ret) |
| 12307 | goto cleanup_request; |
| 12308 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12309 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, request, |
| 12310 | page_flip_flags); |
| 12311 | if (ret) |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12312 | goto cleanup_request; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12313 | |
| 12314 | intel_mark_page_flip_active(intel_crtc, work); |
| 12315 | |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12316 | work->flip_queued_req = i915_gem_request_get(request); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12317 | i915_add_request_no_flush(request); |
Maarten Lankhorst | 143f73b3 | 2016-05-17 15:07:54 +0200 | [diff] [blame] | 12318 | } |
| 12319 | |
Chris Wilson | 92117f0 | 2016-11-28 14:36:48 +0000 | [diff] [blame] | 12320 | i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12321 | i915_gem_track_fb(intel_fb_obj(old_fb), obj, |
| 12322 | to_intel_plane(primary)->frontbuffer_bit); |
| 12323 | mutex_unlock(&dev->struct_mutex); |
| 12324 | |
Chris Wilson | 5748b6a | 2016-08-04 16:32:38 +0100 | [diff] [blame] | 12325 | intel_frontbuffer_flip_prepare(to_i915(dev), |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12326 | to_intel_plane(primary)->frontbuffer_bit); |
| 12327 | |
| 12328 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 12329 | |
| 12330 | return 0; |
| 12331 | |
Chris Wilson | 8e63717 | 2016-08-02 22:50:26 +0100 | [diff] [blame] | 12332 | cleanup_request: |
| 12333 | i915_add_request_no_flush(request); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12334 | cleanup_unpin: |
| 12335 | intel_unpin_fb_obj(fb, crtc->primary->state->rotation); |
| 12336 | cleanup_pending: |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12337 | atomic_dec(&intel_crtc->unpin_work_count); |
Matthew Auld | ddbb271 | 2016-11-28 10:36:48 +0000 | [diff] [blame] | 12338 | unlock: |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12339 | mutex_unlock(&dev->struct_mutex); |
| 12340 | cleanup: |
| 12341 | crtc->primary->fb = old_fb; |
| 12342 | update_state_fb(crtc->primary); |
| 12343 | |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 12344 | i915_gem_object_put(obj); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12345 | drm_framebuffer_unreference(work->old_fb); |
| 12346 | |
| 12347 | spin_lock_irq(&dev->event_lock); |
| 12348 | intel_crtc->flip_work = NULL; |
| 12349 | spin_unlock_irq(&dev->event_lock); |
| 12350 | |
| 12351 | drm_crtc_vblank_put(crtc); |
| 12352 | free_work: |
| 12353 | kfree(work); |
| 12354 | |
| 12355 | if (ret == -EIO) { |
| 12356 | struct drm_atomic_state *state; |
| 12357 | struct drm_plane_state *plane_state; |
| 12358 | |
| 12359 | out_hang: |
| 12360 | state = drm_atomic_state_alloc(dev); |
| 12361 | if (!state) |
| 12362 | return -ENOMEM; |
| 12363 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 12364 | |
| 12365 | retry: |
| 12366 | plane_state = drm_atomic_get_plane_state(state, primary); |
| 12367 | ret = PTR_ERR_OR_ZERO(plane_state); |
| 12368 | if (!ret) { |
| 12369 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 12370 | |
| 12371 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 12372 | if (!ret) |
| 12373 | ret = drm_atomic_commit(state); |
| 12374 | } |
| 12375 | |
| 12376 | if (ret == -EDEADLK) { |
| 12377 | drm_modeset_backoff(state->acquire_ctx); |
| 12378 | drm_atomic_state_clear(state); |
| 12379 | goto retry; |
| 12380 | } |
| 12381 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 12382 | drm_atomic_state_put(state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12383 | |
| 12384 | if (ret == 0 && event) { |
| 12385 | spin_lock_irq(&dev->event_lock); |
| 12386 | drm_crtc_send_vblank_event(crtc, event); |
| 12387 | spin_unlock_irq(&dev->event_lock); |
| 12388 | } |
| 12389 | } |
| 12390 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 12391 | } |
| 12392 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12393 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12394 | /** |
| 12395 | * intel_wm_need_update - Check whether watermarks need updating |
| 12396 | * @plane: drm plane |
| 12397 | * @state: new plane state |
| 12398 | * |
| 12399 | * Check current plane state versus the new one to determine whether |
| 12400 | * watermarks need to be recalculated. |
| 12401 | * |
| 12402 | * Returns true or false. |
| 12403 | */ |
| 12404 | static bool intel_wm_need_update(struct drm_plane *plane, |
| 12405 | struct drm_plane_state *state) |
| 12406 | { |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 12407 | struct intel_plane_state *new = to_intel_plane_state(state); |
| 12408 | struct intel_plane_state *cur = to_intel_plane_state(plane->state); |
| 12409 | |
| 12410 | /* Update watermarks on tiling or size changes. */ |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 12411 | if (new->base.visible != cur->base.visible) |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 12412 | return true; |
| 12413 | |
| 12414 | if (!cur->base.fb || !new->base.fb) |
| 12415 | return false; |
| 12416 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 12417 | if (cur->base.fb->modifier != new->base.fb->modifier || |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 12418 | cur->base.rotation != new->base.rotation || |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 12419 | drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) || |
| 12420 | drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) || |
| 12421 | drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) || |
| 12422 | drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst)) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12423 | return true; |
| 12424 | |
| 12425 | return false; |
| 12426 | } |
| 12427 | |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 12428 | static bool needs_scaling(struct intel_plane_state *state) |
| 12429 | { |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 12430 | int src_w = drm_rect_width(&state->base.src) >> 16; |
| 12431 | int src_h = drm_rect_height(&state->base.src) >> 16; |
| 12432 | int dst_w = drm_rect_width(&state->base.dst); |
| 12433 | int dst_h = drm_rect_height(&state->base.dst); |
Matt Roper | d21fbe8 | 2015-09-24 15:53:12 -0700 | [diff] [blame] | 12434 | |
| 12435 | return (src_w != dst_w || src_h != dst_h); |
| 12436 | } |
| 12437 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12438 | int intel_plane_atomic_calc_changes(struct drm_crtc_state *crtc_state, |
| 12439 | struct drm_plane_state *plane_state) |
| 12440 | { |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 12441 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12442 | struct drm_crtc *crtc = crtc_state->crtc; |
| 12443 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12444 | struct drm_plane *plane = plane_state->plane; |
| 12445 | struct drm_device *dev = crtc->dev; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12446 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12447 | struct intel_plane_state *old_plane_state = |
| 12448 | to_intel_plane_state(plane->state); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12449 | bool mode_changed = needs_modeset(crtc_state); |
| 12450 | bool was_crtc_enabled = crtc->state->active; |
| 12451 | bool is_crtc_enabled = crtc_state->active; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12452 | bool turn_off, turn_on, visible, was_visible; |
| 12453 | struct drm_framebuffer *fb = plane_state->fb; |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12454 | int ret; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12455 | |
Tvrtko Ursulin | 55b8f2a | 2016-10-14 09:17:22 +0100 | [diff] [blame] | 12456 | if (INTEL_GEN(dev_priv) >= 9 && plane->type != DRM_PLANE_TYPE_CURSOR) { |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12457 | ret = skl_update_scaler_plane( |
| 12458 | to_intel_crtc_state(crtc_state), |
| 12459 | to_intel_plane_state(plane_state)); |
| 12460 | if (ret) |
| 12461 | return ret; |
| 12462 | } |
| 12463 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 12464 | was_visible = old_plane_state->base.visible; |
| 12465 | visible = to_intel_plane_state(plane_state)->base.visible; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12466 | |
| 12467 | if (!was_crtc_enabled && WARN_ON(was_visible)) |
| 12468 | was_visible = false; |
| 12469 | |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 12470 | /* |
| 12471 | * Visibility is calculated as if the crtc was on, but |
| 12472 | * after scaler setup everything depends on it being off |
| 12473 | * when the crtc isn't active. |
Ville Syrjälä | f818ffe | 2016-04-29 17:31:18 +0300 | [diff] [blame] | 12474 | * |
| 12475 | * FIXME this is wrong for watermarks. Watermarks should also |
| 12476 | * be computed as if the pipe would be active. Perhaps move |
| 12477 | * per-plane wm computation to the .check_plane() hook, and |
| 12478 | * only combine the results from all planes in the current place? |
Maarten Lankhorst | 35c08f4 | 2015-12-03 14:31:07 +0100 | [diff] [blame] | 12479 | */ |
| 12480 | if (!is_crtc_enabled) |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 12481 | to_intel_plane_state(plane_state)->base.visible = visible = false; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12482 | |
| 12483 | if (!was_visible && !visible) |
| 12484 | return 0; |
| 12485 | |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 12486 | if (fb != old_plane_state->base.fb) |
| 12487 | pipe_config->fb_changed = true; |
| 12488 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12489 | turn_off = was_visible && (!visible || mode_changed); |
| 12490 | turn_on = visible && (!was_visible || mode_changed); |
| 12491 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 12492 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n", |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 12493 | intel_crtc->base.base.id, |
| 12494 | intel_crtc->base.name, |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 12495 | plane->base.id, plane->name, |
| 12496 | fb ? fb->base.id : -1); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12497 | |
Ville Syrjälä | 72660ce | 2016-05-27 20:59:20 +0300 | [diff] [blame] | 12498 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n", |
| 12499 | plane->base.id, plane->name, |
| 12500 | was_visible, visible, |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12501 | turn_off, turn_on, mode_changed); |
| 12502 | |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12503 | if (turn_on) { |
| 12504 | pipe_config->update_wm_pre = true; |
| 12505 | |
| 12506 | /* must disable cxsr around plane enable/disable */ |
| 12507 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
| 12508 | pipe_config->disable_cxsr = true; |
| 12509 | } else if (turn_off) { |
| 12510 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | 92826fc | 2015-12-03 13:49:13 +0100 | [diff] [blame] | 12511 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12512 | /* must disable cxsr around plane enable/disable */ |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 12513 | if (plane->type != DRM_PLANE_TYPE_CURSOR) |
Maarten Lankhorst | ab1d3a0 | 2015-11-19 16:07:14 +0100 | [diff] [blame] | 12514 | pipe_config->disable_cxsr = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12515 | } else if (intel_wm_need_update(plane, plane_state)) { |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12516 | /* FIXME bollocks */ |
| 12517 | pipe_config->update_wm_pre = true; |
| 12518 | pipe_config->update_wm_post = true; |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12519 | } |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12520 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12521 | /* Pre-gen9 platforms need two-step watermark updates */ |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12522 | if ((pipe_config->update_wm_pre || pipe_config->update_wm_post) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12523 | INTEL_GEN(dev_priv) < 9 && dev_priv->display.optimize_watermarks) |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12524 | to_intel_crtc_state(crtc_state)->wm.need_postvbl_update = true; |
| 12525 | |
Rodrigo Vivi | 8be6ca8 | 2015-08-24 16:38:23 -0700 | [diff] [blame] | 12526 | if (visible || was_visible) |
Maarten Lankhorst | cd202f6 | 2016-03-09 10:35:44 +0100 | [diff] [blame] | 12527 | pipe_config->fb_bits |= to_intel_plane(plane)->frontbuffer_bit; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 12528 | |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 12529 | /* |
| 12530 | * WaCxSRDisabledForSpriteScaling:ivb |
| 12531 | * |
| 12532 | * cstate->update_wm was already set above, so this flag will |
| 12533 | * take effect when we commit and program watermarks. |
| 12534 | */ |
Tvrtko Ursulin | fd6b8f4 | 2016-10-14 10:13:06 +0100 | [diff] [blame] | 12535 | if (plane->type == DRM_PLANE_TYPE_OVERLAY && IS_IVYBRIDGE(dev_priv) && |
Maarten Lankhorst | 31ae71f | 2016-03-09 10:35:45 +0100 | [diff] [blame] | 12536 | needs_scaling(to_intel_plane_state(plane_state)) && |
| 12537 | !needs_scaling(old_plane_state)) |
| 12538 | pipe_config->disable_lp_wm = true; |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12539 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 12540 | return 0; |
| 12541 | } |
| 12542 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12543 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 12544 | const struct intel_encoder *b) |
| 12545 | { |
| 12546 | /* masks could be asymmetric, so check both ways */ |
| 12547 | return a == b || (a->cloneable & (1 << b->type) && |
| 12548 | b->cloneable & (1 << a->type)); |
| 12549 | } |
| 12550 | |
| 12551 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 12552 | struct intel_crtc *crtc, |
| 12553 | struct intel_encoder *encoder) |
| 12554 | { |
| 12555 | struct intel_encoder *source_encoder; |
| 12556 | struct drm_connector *connector; |
| 12557 | struct drm_connector_state *connector_state; |
| 12558 | int i; |
| 12559 | |
| 12560 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12561 | if (connector_state->crtc != &crtc->base) |
| 12562 | continue; |
| 12563 | |
| 12564 | source_encoder = |
| 12565 | to_intel_encoder(connector_state->best_encoder); |
| 12566 | if (!encoders_cloneable(encoder, source_encoder)) |
| 12567 | return false; |
| 12568 | } |
| 12569 | |
| 12570 | return true; |
| 12571 | } |
| 12572 | |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12573 | static int intel_crtc_atomic_check(struct drm_crtc *crtc, |
| 12574 | struct drm_crtc_state *crtc_state) |
| 12575 | { |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 12576 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 12577 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12578 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Maarten Lankhorst | cf5a15b | 2015-06-15 12:33:41 +0200 | [diff] [blame] | 12579 | struct intel_crtc_state *pipe_config = |
| 12580 | to_intel_crtc_state(crtc_state); |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12581 | struct drm_atomic_state *state = crtc_state->state; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 12582 | int ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12583 | bool mode_changed = needs_modeset(crtc_state); |
| 12584 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 12585 | if (mode_changed && !crtc_state->active) |
Ville Syrjälä | caed361 | 2016-03-09 19:07:25 +0200 | [diff] [blame] | 12586 | pipe_config->update_wm_post = true; |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 12587 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12588 | if (mode_changed && crtc_state->enable && |
| 12589 | dev_priv->display.crtc_compute_clock && |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12590 | !WARN_ON(pipe_config->shared_dpll)) { |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 12591 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 12592 | pipe_config); |
| 12593 | if (ret) |
| 12594 | return ret; |
| 12595 | } |
| 12596 | |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 12597 | if (crtc_state->color_mgmt_changed) { |
| 12598 | ret = intel_color_check(crtc, crtc_state); |
| 12599 | if (ret) |
| 12600 | return ret; |
Lionel Landwerlin | e7852a4 | 2016-05-25 14:30:41 +0100 | [diff] [blame] | 12601 | |
| 12602 | /* |
| 12603 | * Changing color management on Intel hardware is |
| 12604 | * handled as part of planes update. |
| 12605 | */ |
| 12606 | crtc_state->planes_changed = true; |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 12607 | } |
| 12608 | |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 12609 | ret = 0; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12610 | if (dev_priv->display.compute_pipe_wm) { |
Maarten Lankhorst | e3bddde | 2016-03-01 11:07:22 +0100 | [diff] [blame] | 12611 | ret = dev_priv->display.compute_pipe_wm(pipe_config); |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12612 | if (ret) { |
| 12613 | DRM_DEBUG_KMS("Target pipe watermarks are invalid\n"); |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12614 | return ret; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12615 | } |
| 12616 | } |
| 12617 | |
| 12618 | if (dev_priv->display.compute_intermediate_wm && |
| 12619 | !to_intel_atomic_state(state)->skip_intermediate_wm) { |
| 12620 | if (WARN_ON(!dev_priv->display.compute_pipe_wm)) |
| 12621 | return 0; |
| 12622 | |
| 12623 | /* |
| 12624 | * Calculate 'intermediate' watermarks that satisfy both the |
| 12625 | * old state and the new state. We can program these |
| 12626 | * immediately. |
| 12627 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12628 | ret = dev_priv->display.compute_intermediate_wm(dev, |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 12629 | intel_crtc, |
| 12630 | pipe_config); |
| 12631 | if (ret) { |
| 12632 | DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n"); |
| 12633 | return ret; |
| 12634 | } |
Ville Syrjälä | e3d5457 | 2016-05-13 10:10:42 -0700 | [diff] [blame] | 12635 | } else if (dev_priv->display.compute_intermediate_wm) { |
| 12636 | if (HAS_PCH_SPLIT(dev_priv) && INTEL_GEN(dev_priv) < 9) |
| 12637 | pipe_config->wm.ilk.intermediate = pipe_config->wm.ilk.optimal; |
Matt Roper | 86c8bbb | 2015-09-24 15:53:16 -0700 | [diff] [blame] | 12638 | } |
| 12639 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 12640 | if (INTEL_GEN(dev_priv) >= 9) { |
Maarten Lankhorst | e435d6e | 2015-07-13 16:30:15 +0200 | [diff] [blame] | 12641 | if (mode_changed) |
| 12642 | ret = skl_update_scaler_crtc(pipe_config); |
| 12643 | |
| 12644 | if (!ret) |
| 12645 | ret = intel_atomic_setup_scalers(dev, intel_crtc, |
| 12646 | pipe_config); |
| 12647 | } |
| 12648 | |
| 12649 | return ret; |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12650 | } |
| 12651 | |
Jani Nikula | 65b38e0 | 2015-04-13 11:26:56 +0300 | [diff] [blame] | 12652 | static const struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12653 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 12654 | .atomic_begin = intel_begin_crtc_commit, |
| 12655 | .atomic_flush = intel_finish_crtc_commit, |
Maarten Lankhorst | 6d3a1ce | 2015-06-15 12:33:40 +0200 | [diff] [blame] | 12656 | .atomic_check = intel_crtc_atomic_check, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12657 | }; |
| 12658 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12659 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 12660 | { |
| 12661 | struct intel_connector *connector; |
| 12662 | |
| 12663 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 12664 | if (connector->base.state->crtc) |
| 12665 | drm_connector_unreference(&connector->base); |
| 12666 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12667 | if (connector->base.encoder) { |
| 12668 | connector->base.state->best_encoder = |
| 12669 | connector->base.encoder; |
| 12670 | connector->base.state->crtc = |
| 12671 | connector->base.encoder->crtc; |
Daniel Vetter | 8863dc7 | 2016-05-06 15:39:03 +0200 | [diff] [blame] | 12672 | |
| 12673 | drm_connector_reference(&connector->base); |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 12674 | } else { |
| 12675 | connector->base.state->best_encoder = NULL; |
| 12676 | connector->base.state->crtc = NULL; |
| 12677 | } |
| 12678 | } |
| 12679 | } |
| 12680 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12681 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 12682 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12683 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12684 | { |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 12685 | const struct drm_display_info *info = &connector->base.display_info; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12686 | int bpp = pipe_config->pipe_bpp; |
| 12687 | |
| 12688 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 12689 | connector->base.base.id, |
| 12690 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12691 | |
| 12692 | /* Don't use an invalid EDID bpc value */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 12693 | if (info->bpc != 0 && info->bpc * 3 < bpp) { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12694 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 12695 | bpp, info->bpc * 3); |
| 12696 | pipe_config->pipe_bpp = info->bpc * 3; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12697 | } |
| 12698 | |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 12699 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
Ville Syrjälä | 6a2a5c5 | 2016-09-28 16:51:42 +0300 | [diff] [blame] | 12700 | if (info->bpc == 0 && bpp > 24) { |
Mario Kleiner | 196f954 | 2016-07-06 12:05:45 +0200 | [diff] [blame] | 12701 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 12702 | bpp); |
| 12703 | pipe_config->pipe_bpp = 24; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12704 | } |
| 12705 | } |
| 12706 | |
| 12707 | static int |
| 12708 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12709 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 12710 | { |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12711 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12712 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12713 | struct drm_connector *connector; |
| 12714 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12715 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12716 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12717 | if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || |
| 12718 | IS_CHERRYVIEW(dev_priv))) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12719 | bpp = 10*3; |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 12720 | else if (INTEL_GEN(dev_priv) >= 5) |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12721 | bpp = 12*3; |
| 12722 | else |
| 12723 | bpp = 8*3; |
| 12724 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12725 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12726 | pipe_config->pipe_bpp = bpp; |
| 12727 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12728 | state = pipe_config->base.state; |
| 12729 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12730 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12731 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12732 | if (connector_state->crtc != &crtc->base) |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 12733 | continue; |
| 12734 | |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12735 | connected_sink_compute_bpp(to_intel_connector(connector), |
| 12736 | pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12737 | } |
| 12738 | |
| 12739 | return bpp; |
| 12740 | } |
| 12741 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12742 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 12743 | { |
| 12744 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 12745 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 12746 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 12747 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 12748 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 12749 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 12750 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 12751 | } |
| 12752 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 12753 | static inline void |
| 12754 | intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id, |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 12755 | unsigned int lane_count, struct intel_link_m_n *m_n) |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 12756 | { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 12757 | DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 12758 | id, lane_count, |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 12759 | m_n->gmch_m, m_n->gmch_n, |
| 12760 | m_n->link_m, m_n->link_n, m_n->tu); |
| 12761 | } |
| 12762 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12763 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12764 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12765 | const char *context) |
| 12766 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12767 | struct drm_device *dev = crtc->base.dev; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12768 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12769 | struct drm_plane *plane; |
| 12770 | struct intel_plane *intel_plane; |
| 12771 | struct intel_plane_state *state; |
| 12772 | struct drm_framebuffer *fb; |
| 12773 | |
Tvrtko Ursulin | 66766e4 | 2016-11-17 12:30:10 +0000 | [diff] [blame] | 12774 | DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n", |
| 12775 | crtc->base.base.id, crtc->base.name, context); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12776 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 12777 | DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n", |
| 12778 | transcoder_name(pipe_config->cpu_transcoder), |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12779 | pipe_config->pipe_bpp, pipe_config->dither); |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 12780 | |
| 12781 | if (pipe_config->has_pch_encoder) |
| 12782 | intel_dump_m_n_config(pipe_config, "fdi", |
| 12783 | pipe_config->fdi_lanes, |
| 12784 | &pipe_config->fdi_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12785 | |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 12786 | if (intel_crtc_has_dp_encoder(pipe_config)) { |
Tvrtko Ursulin | a430965 | 2016-11-17 12:30:09 +0000 | [diff] [blame] | 12787 | intel_dump_m_n_config(pipe_config, "dp m_n", |
| 12788 | pipe_config->lane_count, &pipe_config->dp_m_n); |
Tvrtko Ursulin | d806e68 | 2016-11-17 15:44:09 +0000 | [diff] [blame] | 12789 | if (pipe_config->has_drrs) |
| 12790 | intel_dump_m_n_config(pipe_config, "dp m2_n2", |
| 12791 | pipe_config->lane_count, |
| 12792 | &pipe_config->dp_m2_n2); |
Tvrtko Ursulin | f698233 | 2016-11-17 12:30:08 +0000 | [diff] [blame] | 12793 | } |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 12794 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 12795 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 12796 | pipe_config->has_audio, pipe_config->has_infoframe); |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 12797 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12798 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12799 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12800 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12801 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 12802 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 12803 | DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d\n", |
| 12804 | pipe_config->port_clock, |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 12805 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 12806 | |
| 12807 | if (INTEL_GEN(dev_priv) >= 9) |
| 12808 | DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n", |
| 12809 | crtc->num_scalers, |
| 12810 | pipe_config->scaler_state.scaler_users, |
| 12811 | pipe_config->scaler_state.scaler_id); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 12812 | |
| 12813 | if (HAS_GMCH_DISPLAY(dev_priv)) |
| 12814 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 12815 | pipe_config->gmch_pfit.control, |
| 12816 | pipe_config->gmch_pfit.pgm_ratios, |
| 12817 | pipe_config->gmch_pfit.lvds_border_bits); |
| 12818 | else |
| 12819 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
| 12820 | pipe_config->pch_pfit.pos, |
| 12821 | pipe_config->pch_pfit.size, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 12822 | enableddisabled(pipe_config->pch_pfit.enabled)); |
Tvrtko Ursulin | a74f837 | 2016-11-17 12:30:13 +0000 | [diff] [blame] | 12823 | |
Tvrtko Ursulin | 2c89429 | 2016-11-17 12:30:11 +0000 | [diff] [blame] | 12824 | DRM_DEBUG_KMS("ips: %i, double wide: %i\n", |
| 12825 | pipe_config->ips_enabled, pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12826 | |
Ander Conselvan de Oliveira | f50b79f | 2016-12-29 17:22:12 +0200 | [diff] [blame] | 12827 | intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state); |
Tvrtko Ursulin | 415ff0f | 2015-05-14 13:38:31 +0100 | [diff] [blame] | 12828 | |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12829 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 12830 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 12831 | struct drm_format_name_buf format_name; |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12832 | intel_plane = to_intel_plane(plane); |
| 12833 | if (intel_plane->pipe != crtc->pipe) |
| 12834 | continue; |
| 12835 | |
| 12836 | state = to_intel_plane_state(plane->state); |
| 12837 | fb = state->base.fb; |
| 12838 | if (!fb) { |
Ville Syrjälä | 1d577e0 | 2016-05-27 20:59:25 +0300 | [diff] [blame] | 12839 | DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n", |
| 12840 | plane->base.id, plane->name, state->scaler_id); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12841 | continue; |
| 12842 | } |
| 12843 | |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 12844 | DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n", |
| 12845 | plane->base.id, plane->name, |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 12846 | fb->base.id, fb->width, fb->height, |
| 12847 | drm_get_format_name(fb->pixel_format, &format_name)); |
Tvrtko Ursulin | dd2f616 | 2016-11-17 12:30:12 +0000 | [diff] [blame] | 12848 | if (INTEL_GEN(dev_priv) >= 9) |
| 12849 | DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n", |
| 12850 | state->scaler_id, |
| 12851 | state->base.src.x1 >> 16, |
| 12852 | state->base.src.y1 >> 16, |
| 12853 | drm_rect_width(&state->base.src) >> 16, |
| 12854 | drm_rect_height(&state->base.src) >> 16, |
| 12855 | state->base.dst.x1, state->base.dst.y1, |
| 12856 | drm_rect_width(&state->base.dst), |
| 12857 | drm_rect_height(&state->base.dst)); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 12858 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 12859 | } |
| 12860 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12861 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12862 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12863 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12864 | struct drm_connector *connector; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12865 | unsigned int used_ports = 0; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 12866 | unsigned int used_mst_ports = 0; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12867 | |
| 12868 | /* |
| 12869 | * Walk the connector list instead of the encoder |
| 12870 | * list to detect the problem on ddi platforms |
| 12871 | * where there's just one encoder per digital port. |
| 12872 | */ |
Ville Syrjälä | 0bff485 | 2015-12-10 18:22:31 +0200 | [diff] [blame] | 12873 | drm_for_each_connector(connector, dev) { |
| 12874 | struct drm_connector_state *connector_state; |
| 12875 | struct intel_encoder *encoder; |
| 12876 | |
| 12877 | connector_state = drm_atomic_get_existing_connector_state(state, connector); |
| 12878 | if (!connector_state) |
| 12879 | connector_state = connector->state; |
| 12880 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 12881 | if (!connector_state->best_encoder) |
| 12882 | continue; |
| 12883 | |
| 12884 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 12885 | |
| 12886 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12887 | |
| 12888 | switch (encoder->type) { |
| 12889 | unsigned int port_mask; |
| 12890 | case INTEL_OUTPUT_UNKNOWN: |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 12891 | if (WARN_ON(!HAS_DDI(to_i915(dev)))) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12892 | break; |
Ville Syrjälä | cca0502 | 2016-06-22 21:57:06 +0300 | [diff] [blame] | 12893 | case INTEL_OUTPUT_DP: |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12894 | case INTEL_OUTPUT_HDMI: |
| 12895 | case INTEL_OUTPUT_EDP: |
| 12896 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 12897 | |
| 12898 | /* the same port mustn't appear more than once */ |
| 12899 | if (used_ports & port_mask) |
| 12900 | return false; |
| 12901 | |
| 12902 | used_ports |= port_mask; |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 12903 | break; |
| 12904 | case INTEL_OUTPUT_DP_MST: |
| 12905 | used_mst_ports |= |
| 12906 | 1 << enc_to_mst(&encoder->base)->primary->port; |
| 12907 | break; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12908 | default: |
| 12909 | break; |
| 12910 | } |
| 12911 | } |
| 12912 | |
Ville Syrjälä | 477321e | 2016-07-28 17:50:40 +0300 | [diff] [blame] | 12913 | /* can't mix MST and SST/HDMI on the same port */ |
| 12914 | if (used_ports & used_mst_ports) |
| 12915 | return false; |
| 12916 | |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 12917 | return true; |
| 12918 | } |
| 12919 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12920 | static void |
| 12921 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 12922 | { |
| 12923 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12924 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12925 | struct intel_dpll_hw_state dpll_hw_state; |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 12926 | struct intel_shared_dpll *shared_dpll; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12927 | bool force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12928 | |
Ander Conselvan de Oliveira | 7546a38 | 2015-05-20 09:03:27 +0300 | [diff] [blame] | 12929 | /* FIXME: before the switch to atomic started, a new pipe_config was |
| 12930 | * kzalloc'd. Code that depends on any field being zero should be |
| 12931 | * fixed, so that the crtc_state can be safely duplicated. For now, |
| 12932 | * only fields that are know to not cause problems are preserved. */ |
| 12933 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12934 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12935 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12936 | shared_dpll = crtc_state->shared_dpll; |
| 12937 | dpll_hw_state = crtc_state->dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12938 | force_thru = crtc_state->pch_pfit.force_thru; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12939 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12940 | memset(crtc_state, 0, sizeof *crtc_state); |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12941 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12942 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame] | 12943 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 4978cc9 | 2015-04-21 17:13:21 +0300 | [diff] [blame] | 12944 | crtc_state->shared_dpll = shared_dpll; |
| 12945 | crtc_state->dpll_hw_state = dpll_hw_state; |
Maarten Lankhorst | c4e2d04 | 2015-08-05 12:36:59 +0200 | [diff] [blame] | 12946 | crtc_state->pch_pfit.force_thru = force_thru; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12947 | } |
| 12948 | |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 12949 | static int |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12950 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12951 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12952 | { |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 12953 | struct drm_atomic_state *state = pipe_config->base.state; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12954 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 12955 | struct drm_connector *connector; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12956 | struct drm_connector_state *connector_state; |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12957 | int base_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 12958 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 12959 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12960 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12961 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 12962 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 12963 | pipe_config->cpu_transcoder = |
| 12964 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 12965 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12966 | /* |
| 12967 | * Sanitize sync polarity flags based on requested ones. If neither |
| 12968 | * positive or negative polarity is requested, treat this as meaning |
| 12969 | * negative polarity. |
| 12970 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12971 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12972 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12973 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12974 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12975 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12976 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12977 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 12978 | |
Daniel Vetter | d328c9d | 2015-04-10 16:22:37 +0200 | [diff] [blame] | 12979 | base_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 12980 | pipe_config); |
| 12981 | if (base_bpp < 0) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 12982 | goto fail; |
| 12983 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12984 | /* |
| 12985 | * Determine the real pipe dimensions. Note that stereo modes can |
| 12986 | * increase the actual pipe size due to the frame doubling and |
| 12987 | * insertion of additional space for blanks between the frame. This |
| 12988 | * is stored in the crtc timings. We use the requested mode to do this |
| 12989 | * computation to clearly distinguish it from the adjusted mode, which |
| 12990 | * can be changed by the connectors in the below retry loop. |
| 12991 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 12992 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 12993 | &pipe_config->pipe_src_w, |
| 12994 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 12995 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 12996 | for_each_connector_in_state(state, connector, connector_state, i) { |
| 12997 | if (connector_state->crtc != crtc) |
| 12998 | continue; |
| 12999 | |
| 13000 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 13001 | |
Ville Syrjälä | e25148d | 2016-06-22 21:57:09 +0300 | [diff] [blame] | 13002 | if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) { |
| 13003 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 13004 | goto fail; |
| 13005 | } |
| 13006 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 13007 | /* |
| 13008 | * Determine output_types before calling the .compute_config() |
| 13009 | * hooks so that the hooks can use this information safely. |
| 13010 | */ |
| 13011 | pipe_config->output_types |= 1 << encoder->type; |
| 13012 | } |
| 13013 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 13014 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 13015 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 13016 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 13017 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 13018 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 13019 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13020 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 13021 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 13022 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13023 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 13024 | * adjust it according to limitations or connector properties, and also |
| 13025 | * a chance to reject the mode entirely. |
| 13026 | */ |
Ander Conselvan de Oliveira | da3ced298 | 2015-04-21 17:12:59 +0300 | [diff] [blame] | 13027 | for_each_connector_in_state(state, connector, connector_state, i) { |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 13028 | if (connector_state->crtc != crtc) |
| 13029 | continue; |
| 13030 | |
| 13031 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 13032 | |
Maarten Lankhorst | 0a478c2 | 2016-08-09 17:04:05 +0200 | [diff] [blame] | 13033 | if (!(encoder->compute_config(encoder, pipe_config, connector_state))) { |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 13034 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13035 | goto fail; |
| 13036 | } |
| 13037 | } |
| 13038 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 13039 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 13040 | * done afterwards in case the encoder adjusts the mode. */ |
| 13041 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13042 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 13043 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 13044 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 13045 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 13046 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13047 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 13048 | goto fail; |
| 13049 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 13050 | |
| 13051 | if (ret == RETRY) { |
| 13052 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 13053 | ret = -EINVAL; |
| 13054 | goto fail; |
| 13055 | } |
| 13056 | |
| 13057 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 13058 | retry = false; |
| 13059 | goto encoder_retry; |
| 13060 | } |
| 13061 | |
Daniel Vetter | e8fa427 | 2015-08-12 11:43:34 +0200 | [diff] [blame] | 13062 | /* Dithering seems to not pass-through bits correctly when it should, so |
| 13063 | * only enable it on 6bpc panels. */ |
| 13064 | pipe_config->dither = pipe_config->pipe_bpp == 6*3; |
Daniel Vetter | 62f0ace | 2015-08-26 18:57:26 +0200 | [diff] [blame] | 13065 | 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] | 13066 | base_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 13067 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13068 | fail: |
Ander Conselvan de Oliveira | 548ee15 | 2015-04-21 17:13:02 +0300 | [diff] [blame] | 13069 | return ret; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 13070 | } |
| 13071 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13072 | static void |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 13073 | intel_modeset_update_crtc_state(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13074 | { |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13075 | struct drm_crtc *crtc; |
| 13076 | struct drm_crtc_state *crtc_state; |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 13077 | int i; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13078 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 13079 | /* Double check state. */ |
Maarten Lankhorst | 8a75d15 | 2015-07-13 16:30:14 +0200 | [diff] [blame] | 13080 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 3cb480b | 2015-06-01 12:49:49 +0200 | [diff] [blame] | 13081 | to_intel_crtc(crtc)->config = to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | fc467a22 | 2015-06-01 12:50:07 +0200 | [diff] [blame] | 13082 | |
| 13083 | /* Update hwmode for vblank functions */ |
| 13084 | if (crtc->state->active) |
| 13085 | crtc->hwmode = crtc->state->adjusted_mode; |
| 13086 | else |
| 13087 | crtc->hwmode.crtc_clock = 0; |
Maarten Lankhorst | 61067a5 | 2015-09-23 16:29:36 +0200 | [diff] [blame] | 13088 | |
| 13089 | /* |
| 13090 | * Update legacy state to satisfy fbc code. This can |
| 13091 | * be removed when fbc uses the atomic state. |
| 13092 | */ |
| 13093 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { |
| 13094 | struct drm_plane_state *plane_state = crtc->primary->state; |
| 13095 | |
| 13096 | crtc->primary->fb = plane_state->fb; |
| 13097 | crtc->x = plane_state->src_x >> 16; |
| 13098 | crtc->y = plane_state->src_y >> 16; |
| 13099 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13100 | } |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 13101 | } |
| 13102 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 13103 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 13104 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 13105 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 13106 | |
| 13107 | if (clock1 == clock2) |
| 13108 | return true; |
| 13109 | |
| 13110 | if (!clock1 || !clock2) |
| 13111 | return false; |
| 13112 | |
| 13113 | diff = abs(clock1 - clock2); |
| 13114 | |
| 13115 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 13116 | return true; |
| 13117 | |
| 13118 | return false; |
| 13119 | } |
| 13120 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13121 | static bool |
| 13122 | intel_compare_m_n(unsigned int m, unsigned int n, |
| 13123 | unsigned int m2, unsigned int n2, |
| 13124 | bool exact) |
| 13125 | { |
| 13126 | if (m == m2 && n == n2) |
| 13127 | return true; |
| 13128 | |
| 13129 | if (exact || !m || !n || !m2 || !n2) |
| 13130 | return false; |
| 13131 | |
| 13132 | BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX); |
| 13133 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 13134 | if (n > n2) { |
| 13135 | while (n > n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13136 | m2 <<= 1; |
| 13137 | n2 <<= 1; |
| 13138 | } |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 13139 | } else if (n < n2) { |
| 13140 | while (n < n2) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13141 | m <<= 1; |
| 13142 | n <<= 1; |
| 13143 | } |
| 13144 | } |
| 13145 | |
Maarten Lankhorst | 31d10b5 | 2016-01-06 13:54:43 +0100 | [diff] [blame] | 13146 | if (n != n2) |
| 13147 | return false; |
| 13148 | |
| 13149 | return intel_fuzzy_clock_check(m, m2); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13150 | } |
| 13151 | |
| 13152 | static bool |
| 13153 | intel_compare_link_m_n(const struct intel_link_m_n *m_n, |
| 13154 | struct intel_link_m_n *m2_n2, |
| 13155 | bool adjust) |
| 13156 | { |
| 13157 | if (m_n->tu == m2_n2->tu && |
| 13158 | intel_compare_m_n(m_n->gmch_m, m_n->gmch_n, |
| 13159 | m2_n2->gmch_m, m2_n2->gmch_n, !adjust) && |
| 13160 | intel_compare_m_n(m_n->link_m, m_n->link_n, |
| 13161 | m2_n2->link_m, m2_n2->link_n, !adjust)) { |
| 13162 | if (adjust) |
| 13163 | *m2_n2 = *m_n; |
| 13164 | |
| 13165 | return true; |
| 13166 | } |
| 13167 | |
| 13168 | return false; |
| 13169 | } |
| 13170 | |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13171 | static void __printf(3, 4) |
| 13172 | pipe_config_err(bool adjust, const char *name, const char *format, ...) |
| 13173 | { |
| 13174 | char *level; |
| 13175 | unsigned int category; |
| 13176 | struct va_format vaf; |
| 13177 | va_list args; |
| 13178 | |
| 13179 | if (adjust) { |
| 13180 | level = KERN_DEBUG; |
| 13181 | category = DRM_UT_KMS; |
| 13182 | } else { |
| 13183 | level = KERN_ERR; |
| 13184 | category = DRM_UT_NONE; |
| 13185 | } |
| 13186 | |
| 13187 | va_start(args, format); |
| 13188 | vaf.fmt = format; |
| 13189 | vaf.va = &args; |
| 13190 | |
| 13191 | drm_printk(level, category, "mismatch in %s %pV", name, &vaf); |
| 13192 | |
| 13193 | va_end(args); |
| 13194 | } |
| 13195 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13196 | static bool |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13197 | intel_pipe_config_compare(struct drm_i915_private *dev_priv, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 13198 | struct intel_crtc_state *current_config, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13199 | struct intel_crtc_state *pipe_config, |
| 13200 | bool adjust) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13201 | { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13202 | bool ret = true; |
| 13203 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13204 | #define PIPE_CONF_CHECK_X(name) \ |
| 13205 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13206 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13207 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 13208 | current_config->name, \ |
| 13209 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13210 | ret = false; \ |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13211 | } |
| 13212 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 13213 | #define PIPE_CONF_CHECK_I(name) \ |
| 13214 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13215 | pipe_config_err(adjust, __stringify(name), \ |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 13216 | "(expected %i, found %i)\n", \ |
| 13217 | current_config->name, \ |
| 13218 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13219 | ret = false; \ |
| 13220 | } |
| 13221 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13222 | #define PIPE_CONF_CHECK_P(name) \ |
| 13223 | if (current_config->name != pipe_config->name) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13224 | pipe_config_err(adjust, __stringify(name), \ |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13225 | "(expected %p, found %p)\n", \ |
| 13226 | current_config->name, \ |
| 13227 | pipe_config->name); \ |
| 13228 | ret = false; \ |
| 13229 | } |
| 13230 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13231 | #define PIPE_CONF_CHECK_M_N(name) \ |
| 13232 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 13233 | &pipe_config->name,\ |
| 13234 | adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13235 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13236 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 13237 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 13238 | current_config->name.tu, \ |
| 13239 | current_config->name.gmch_m, \ |
| 13240 | current_config->name.gmch_n, \ |
| 13241 | current_config->name.link_m, \ |
| 13242 | current_config->name.link_n, \ |
| 13243 | pipe_config->name.tu, \ |
| 13244 | pipe_config->name.gmch_m, \ |
| 13245 | pipe_config->name.gmch_n, \ |
| 13246 | pipe_config->name.link_m, \ |
| 13247 | pipe_config->name.link_n); \ |
| 13248 | ret = false; \ |
| 13249 | } |
| 13250 | |
Daniel Vetter | 55c561a | 2016-03-30 11:34:36 +0200 | [diff] [blame] | 13251 | /* This is required for BDW+ where there is only one set of registers for |
| 13252 | * switching between high and low RR. |
| 13253 | * This macro can be used whenever a comparison has to be made between one |
| 13254 | * hw state and multiple sw state variables. |
| 13255 | */ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13256 | #define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) \ |
| 13257 | if (!intel_compare_link_m_n(¤t_config->name, \ |
| 13258 | &pipe_config->name, adjust) && \ |
| 13259 | !intel_compare_link_m_n(¤t_config->alt_name, \ |
| 13260 | &pipe_config->name, adjust)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13261 | pipe_config_err(adjust, __stringify(name), \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13262 | "(expected tu %i gmch %i/%i link %i/%i, " \ |
| 13263 | "or tu %i gmch %i/%i link %i/%i, " \ |
| 13264 | "found tu %i, gmch %i/%i link %i/%i)\n", \ |
| 13265 | current_config->name.tu, \ |
| 13266 | current_config->name.gmch_m, \ |
| 13267 | current_config->name.gmch_n, \ |
| 13268 | current_config->name.link_m, \ |
| 13269 | current_config->name.link_n, \ |
| 13270 | current_config->alt_name.tu, \ |
| 13271 | current_config->alt_name.gmch_m, \ |
| 13272 | current_config->alt_name.gmch_n, \ |
| 13273 | current_config->alt_name.link_m, \ |
| 13274 | current_config->alt_name.link_n, \ |
| 13275 | pipe_config->name.tu, \ |
| 13276 | pipe_config->name.gmch_m, \ |
| 13277 | pipe_config->name.gmch_n, \ |
| 13278 | pipe_config->name.link_m, \ |
| 13279 | pipe_config->name.link_n); \ |
| 13280 | ret = false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 13281 | } |
| 13282 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13283 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 13284 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13285 | pipe_config_err(adjust, __stringify(name), \ |
| 13286 | "(%x) (expected %i, found %i)\n", \ |
| 13287 | (mask), \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13288 | current_config->name & (mask), \ |
| 13289 | pipe_config->name & (mask)); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13290 | ret = false; \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13291 | } |
| 13292 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 13293 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 13294 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
Tvrtko Ursulin | 4e8048f | 2016-12-06 10:50:20 +0000 | [diff] [blame] | 13295 | pipe_config_err(adjust, __stringify(name), \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 13296 | "(expected %i, found %i)\n", \ |
| 13297 | current_config->name, \ |
| 13298 | pipe_config->name); \ |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13299 | ret = false; \ |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 13300 | } |
| 13301 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13302 | #define PIPE_CONF_QUIRK(quirk) \ |
| 13303 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 13304 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 13305 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 13306 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 13307 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 13308 | PIPE_CONF_CHECK_I(fdi_lanes); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13309 | PIPE_CONF_CHECK_M_N(fdi_m_n); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 13310 | |
Ville Syrjälä | 90a6b7b | 2015-07-06 16:39:15 +0300 | [diff] [blame] | 13311 | PIPE_CONF_CHECK_I(lane_count); |
Imre Deak | 95a7a2a | 2016-06-13 16:44:35 +0300 | [diff] [blame] | 13312 | PIPE_CONF_CHECK_X(lane_lat_optim_mask); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 13313 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13314 | if (INTEL_GEN(dev_priv) < 8) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13315 | PIPE_CONF_CHECK_M_N(dp_m_n); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 13316 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13317 | if (current_config->has_drrs) |
| 13318 | PIPE_CONF_CHECK_M_N(dp_m2_n2); |
| 13319 | } else |
| 13320 | 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] | 13321 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 13322 | PIPE_CONF_CHECK_X(output_types); |
Jani Nikula | a65347b | 2015-11-27 12:21:46 +0200 | [diff] [blame] | 13323 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13324 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 13325 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 13326 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 13327 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 13328 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 13329 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13330 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13331 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 13332 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 13333 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 13334 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 13335 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 13336 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13337 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 13338 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 13339 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 13340 | if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) || |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 13341 | IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 13342 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 13343 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 13344 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 13345 | PIPE_CONF_CHECK_I(has_audio); |
| 13346 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13347 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13348 | DRM_MODE_FLAG_INTERLACE); |
| 13349 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13350 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13351 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13352 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13353 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13354 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13355 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13356 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13357 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13358 | DRM_MODE_FLAG_NVSYNC); |
| 13359 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 13360 | |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 13361 | PIPE_CONF_CHECK_X(gmch_pfit.control); |
Daniel Vetter | e2ff2d4 | 2015-07-15 14:15:50 +0200 | [diff] [blame] | 13362 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13363 | if (INTEL_GEN(dev_priv) < 4) |
Ville Syrjälä | 7f7d8dd | 2016-03-15 16:40:07 +0200 | [diff] [blame] | 13364 | PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios); |
Ville Syrjälä | 333b8ca | 2015-09-03 21:50:16 +0300 | [diff] [blame] | 13365 | PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits); |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 13366 | |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 13367 | if (!adjust) { |
| 13368 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 13369 | PIPE_CONF_CHECK_I(pipe_src_h); |
| 13370 | |
| 13371 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 13372 | if (current_config->pch_pfit.enabled) { |
| 13373 | PIPE_CONF_CHECK_X(pch_pfit.pos); |
| 13374 | PIPE_CONF_CHECK_X(pch_pfit.size); |
| 13375 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 13376 | |
Maarten Lankhorst | 7aefe2b | 2015-09-14 11:30:10 +0200 | [diff] [blame] | 13377 | PIPE_CONF_CHECK_I(scaler_state.scaler_id); |
| 13378 | } |
Chandra Konduru | a1b2278 | 2015-04-07 15:28:45 -0700 | [diff] [blame] | 13379 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 13380 | /* BDW+ don't expose a synchronous way to read the state */ |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 13381 | if (IS_HASWELL(dev_priv)) |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 13382 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 13383 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 13384 | PIPE_CONF_CHECK_I(double_wide); |
| 13385 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13386 | PIPE_CONF_CHECK_P(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13387 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 13388 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13389 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 13390 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 13391 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Maarten Lankhorst | 00490c2 | 2015-11-16 14:42:12 +0100 | [diff] [blame] | 13392 | PIPE_CONF_CHECK_X(dpll_hw_state.spll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 13393 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 13394 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 13395 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 13396 | |
Ville Syrjälä | 47eacba | 2016-04-12 22:14:35 +0300 | [diff] [blame] | 13397 | PIPE_CONF_CHECK_X(dsi_pll.ctrl); |
| 13398 | PIPE_CONF_CHECK_X(dsi_pll.div); |
| 13399 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 13400 | if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 13401 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 13402 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 13403 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 13404 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 13405 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 13406 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 13407 | #undef PIPE_CONF_CHECK_I |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13408 | #undef PIPE_CONF_CHECK_P |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 13409 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 13410 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 13411 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 13412 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13413 | return ret; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13414 | } |
| 13415 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 13416 | static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv, |
| 13417 | const struct intel_crtc_state *pipe_config) |
| 13418 | { |
| 13419 | if (pipe_config->has_pch_encoder) { |
Ville Syrjälä | 21a727b | 2016-02-17 21:41:10 +0200 | [diff] [blame] | 13420 | 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] | 13421 | &pipe_config->fdi_m_n); |
| 13422 | int dotclock = pipe_config->base.adjusted_mode.crtc_clock; |
| 13423 | |
| 13424 | /* |
| 13425 | * FDI already provided one idea for the dotclock. |
| 13426 | * Yell if the encoder disagrees. |
| 13427 | */ |
| 13428 | WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock), |
| 13429 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
| 13430 | fdi_dotclock, dotclock); |
| 13431 | } |
| 13432 | } |
| 13433 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13434 | static void verify_wm_state(struct drm_crtc *crtc, |
| 13435 | struct drm_crtc_state *new_state) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13436 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13437 | struct drm_i915_private *dev_priv = to_i915(crtc->dev); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13438 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13439 | struct skl_pipe_wm hw_wm, *sw_wm; |
| 13440 | struct skl_plane_wm *hw_plane_wm, *sw_plane_wm; |
| 13441 | struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13442 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13443 | const enum pipe pipe = intel_crtc->pipe; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13444 | int plane, level, max_level = ilk_wm_max_level(dev_priv); |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13445 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13446 | if (INTEL_GEN(dev_priv) < 9 || !new_state->active) |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13447 | return; |
| 13448 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13449 | skl_pipe_wm_get_hw_state(crtc, &hw_wm); |
Maarten Lankhorst | 03af79e | 2016-10-26 15:41:36 +0200 | [diff] [blame] | 13450 | sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal; |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13451 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13452 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 13453 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 13454 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13455 | /* planes */ |
Matt Roper | 8b364b4 | 2016-10-26 15:51:28 -0700 | [diff] [blame] | 13456 | for_each_universal_plane(dev_priv, pipe, plane) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13457 | hw_plane_wm = &hw_wm.planes[plane]; |
| 13458 | sw_plane_wm = &sw_wm->planes[plane]; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13459 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13460 | /* Watermarks */ |
| 13461 | for (level = 0; level <= max_level; level++) { |
| 13462 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 13463 | &sw_plane_wm->wm[level])) |
| 13464 | continue; |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13465 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13466 | DRM_ERROR("mismatch in WM pipe %c plane %d level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 13467 | pipe_name(pipe), plane + 1, level, |
| 13468 | sw_plane_wm->wm[level].plane_en, |
| 13469 | sw_plane_wm->wm[level].plane_res_b, |
| 13470 | sw_plane_wm->wm[level].plane_res_l, |
| 13471 | hw_plane_wm->wm[level].plane_en, |
| 13472 | hw_plane_wm->wm[level].plane_res_b, |
| 13473 | hw_plane_wm->wm[level].plane_res_l); |
| 13474 | } |
| 13475 | |
| 13476 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 13477 | &sw_plane_wm->trans_wm)) { |
| 13478 | DRM_ERROR("mismatch in trans WM pipe %c plane %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 13479 | pipe_name(pipe), plane + 1, |
| 13480 | sw_plane_wm->trans_wm.plane_en, |
| 13481 | sw_plane_wm->trans_wm.plane_res_b, |
| 13482 | sw_plane_wm->trans_wm.plane_res_l, |
| 13483 | hw_plane_wm->trans_wm.plane_en, |
| 13484 | hw_plane_wm->trans_wm.plane_res_b, |
| 13485 | hw_plane_wm->trans_wm.plane_res_l); |
| 13486 | } |
| 13487 | |
| 13488 | /* DDB */ |
| 13489 | hw_ddb_entry = &hw_ddb.plane[pipe][plane]; |
| 13490 | sw_ddb_entry = &sw_ddb->plane[pipe][plane]; |
| 13491 | |
| 13492 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 13493 | DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n", |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13494 | pipe_name(pipe), plane + 1, |
| 13495 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 13496 | hw_ddb_entry->start, hw_ddb_entry->end); |
| 13497 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13498 | } |
| 13499 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13500 | /* |
| 13501 | * cursor |
| 13502 | * If the cursor plane isn't active, we may not have updated it's ddb |
| 13503 | * allocation. In that case since the ddb allocation will be updated |
| 13504 | * once the plane becomes visible, we can skip this check |
| 13505 | */ |
| 13506 | if (intel_crtc->cursor_addr) { |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13507 | hw_plane_wm = &hw_wm.planes[PLANE_CURSOR]; |
| 13508 | sw_plane_wm = &sw_wm->planes[PLANE_CURSOR]; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13509 | |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13510 | /* Watermarks */ |
| 13511 | for (level = 0; level <= max_level; level++) { |
| 13512 | if (skl_wm_level_equals(&hw_plane_wm->wm[level], |
| 13513 | &sw_plane_wm->wm[level])) |
| 13514 | continue; |
| 13515 | |
| 13516 | DRM_ERROR("mismatch in WM pipe %c cursor level %d (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 13517 | pipe_name(pipe), level, |
| 13518 | sw_plane_wm->wm[level].plane_en, |
| 13519 | sw_plane_wm->wm[level].plane_res_b, |
| 13520 | sw_plane_wm->wm[level].plane_res_l, |
| 13521 | hw_plane_wm->wm[level].plane_en, |
| 13522 | hw_plane_wm->wm[level].plane_res_b, |
| 13523 | hw_plane_wm->wm[level].plane_res_l); |
| 13524 | } |
| 13525 | |
| 13526 | if (!skl_wm_level_equals(&hw_plane_wm->trans_wm, |
| 13527 | &sw_plane_wm->trans_wm)) { |
| 13528 | DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n", |
| 13529 | pipe_name(pipe), |
| 13530 | sw_plane_wm->trans_wm.plane_en, |
| 13531 | sw_plane_wm->trans_wm.plane_res_b, |
| 13532 | sw_plane_wm->trans_wm.plane_res_l, |
| 13533 | hw_plane_wm->trans_wm.plane_en, |
| 13534 | hw_plane_wm->trans_wm.plane_res_b, |
| 13535 | hw_plane_wm->trans_wm.plane_res_l); |
| 13536 | } |
| 13537 | |
| 13538 | /* DDB */ |
| 13539 | hw_ddb_entry = &hw_ddb.plane[pipe][PLANE_CURSOR]; |
| 13540 | sw_ddb_entry = &sw_ddb->plane[pipe][PLANE_CURSOR]; |
| 13541 | |
| 13542 | if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) { |
cpaul@redhat.com | faccd99 | 2016-10-14 17:31:58 -0400 | [diff] [blame] | 13543 | DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n", |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13544 | pipe_name(pipe), |
cpaul@redhat.com | 3de8a14 | 2016-10-14 17:31:57 -0400 | [diff] [blame] | 13545 | sw_ddb_entry->start, sw_ddb_entry->end, |
| 13546 | hw_ddb_entry->start, hw_ddb_entry->end); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 13547 | } |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 13548 | } |
| 13549 | } |
| 13550 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13551 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13552 | verify_connector_state(struct drm_device *dev, |
| 13553 | struct drm_atomic_state *state, |
| 13554 | struct drm_crtc *crtc) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13555 | { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 13556 | struct drm_connector *connector; |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13557 | struct drm_connector_state *old_conn_state; |
| 13558 | int i; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13559 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13560 | for_each_connector_in_state(state, connector, old_conn_state, i) { |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 13561 | struct drm_encoder *encoder = connector->encoder; |
| 13562 | struct drm_connector_state *state = connector->state; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 13563 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13564 | if (state->crtc != crtc) |
| 13565 | continue; |
| 13566 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13567 | intel_connector_verify_state(to_intel_connector(connector)); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13568 | |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 13569 | I915_STATE_WARN(state->best_encoder != encoder, |
Maarten Lankhorst | 35dd3c6 | 2015-08-06 13:49:22 +0200 | [diff] [blame] | 13570 | "connector's atomic encoder doesn't match legacy encoder\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13571 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13572 | } |
| 13573 | |
| 13574 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13575 | verify_encoder_state(struct drm_device *dev) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13576 | { |
| 13577 | struct intel_encoder *encoder; |
| 13578 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13579 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13580 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13581 | bool enabled = false; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13582 | enum pipe pipe; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13583 | |
| 13584 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 13585 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13586 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13587 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13588 | for_each_intel_connector(dev, connector) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13589 | if (connector->base.state->best_encoder != &encoder->base) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13590 | continue; |
| 13591 | enabled = true; |
Maarten Lankhorst | ad3c558 | 2015-07-13 16:30:26 +0200 | [diff] [blame] | 13592 | |
| 13593 | I915_STATE_WARN(connector->base.state->crtc != |
| 13594 | encoder->base.crtc, |
| 13595 | "connector's crtc doesn't match encoder crtc\n"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13596 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 13597 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 13598 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13599 | "encoder's enabled state mismatch " |
| 13600 | "(expected %i, found %i)\n", |
| 13601 | !!encoder->base.crtc, enabled); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13602 | |
| 13603 | if (!encoder->base.crtc) { |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13604 | bool active; |
| 13605 | |
| 13606 | active = encoder->get_hw_state(encoder, &pipe); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13607 | I915_STATE_WARN(active, |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13608 | "encoder detached but still enabled on pipe %c.\n", |
| 13609 | pipe_name(pipe)); |
Maarten Lankhorst | 7c60d19 | 2015-08-05 12:37:04 +0200 | [diff] [blame] | 13610 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13611 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13612 | } |
| 13613 | |
| 13614 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13615 | verify_crtc_state(struct drm_crtc *crtc, |
| 13616 | struct drm_crtc_state *old_crtc_state, |
| 13617 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13618 | { |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13619 | struct drm_device *dev = crtc->dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13620 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13621 | struct intel_encoder *encoder; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13622 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 13623 | struct intel_crtc_state *pipe_config, *sw_config; |
| 13624 | struct drm_atomic_state *old_state; |
| 13625 | bool active; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13626 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13627 | old_state = old_crtc_state->state; |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 13628 | __drm_atomic_helper_crtc_destroy_state(old_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13629 | pipe_config = to_intel_crtc_state(old_crtc_state); |
| 13630 | memset(pipe_config, 0, sizeof(*pipe_config)); |
| 13631 | pipe_config->base.crtc = crtc; |
| 13632 | pipe_config->base.state = old_state; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13633 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 13634 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 13635 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13636 | active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13637 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13638 | /* hw state is inconsistent with the pipe quirk */ |
| 13639 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 13640 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 13641 | active = new_crtc_state->active; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13642 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13643 | I915_STATE_WARN(new_crtc_state->active != active, |
| 13644 | "crtc active state doesn't match with hw state " |
| 13645 | "(expected %i, found %i)\n", new_crtc_state->active, active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13646 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13647 | I915_STATE_WARN(intel_crtc->active != new_crtc_state->active, |
| 13648 | "transitional active state does not match atomic hw state " |
| 13649 | "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13650 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13651 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 13652 | enum pipe pipe; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13653 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13654 | active = encoder->get_hw_state(encoder, &pipe); |
| 13655 | I915_STATE_WARN(active != new_crtc_state->active, |
| 13656 | "[ENCODER:%i] active %i with crtc active %i\n", |
| 13657 | encoder->base.base.id, active, new_crtc_state->active); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13658 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13659 | I915_STATE_WARN(active && intel_crtc->pipe != pipe, |
| 13660 | "Encoder connected to wrong pipe %c\n", |
| 13661 | pipe_name(pipe)); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13662 | |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 13663 | if (active) { |
| 13664 | pipe_config->output_types |= 1 << encoder->type; |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13665 | encoder->get_config(encoder, pipe_config); |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 13666 | } |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13667 | } |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13668 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13669 | if (!new_crtc_state->active) |
| 13670 | return; |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13671 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13672 | intel_pipe_config_sanity_check(dev_priv, pipe_config); |
Maarten Lankhorst | 4d20cd8 | 2015-08-05 12:37:05 +0200 | [diff] [blame] | 13673 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13674 | sw_config = to_intel_crtc_state(crtc->state); |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 13675 | if (!intel_pipe_config_compare(dev_priv, sw_config, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13676 | pipe_config, false)) { |
| 13677 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
| 13678 | intel_dump_pipe_config(intel_crtc, pipe_config, |
| 13679 | "[hw state]"); |
| 13680 | intel_dump_pipe_config(intel_crtc, sw_config, |
| 13681 | "[sw state]"); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13682 | } |
| 13683 | } |
| 13684 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13685 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13686 | verify_single_dpll_state(struct drm_i915_private *dev_priv, |
| 13687 | struct intel_shared_dpll *pll, |
| 13688 | struct drm_crtc *crtc, |
| 13689 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13690 | { |
| 13691 | struct intel_dpll_hw_state dpll_hw_state; |
| 13692 | unsigned crtc_mask; |
| 13693 | bool active; |
| 13694 | |
| 13695 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 13696 | |
| 13697 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 13698 | |
| 13699 | active = pll->funcs.get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 13700 | |
| 13701 | if (!(pll->flags & INTEL_DPLL_ALWAYS_ON)) { |
| 13702 | I915_STATE_WARN(!pll->on && pll->active_mask, |
| 13703 | "pll in active use but not on in sw tracking\n"); |
| 13704 | I915_STATE_WARN(pll->on && !pll->active_mask, |
| 13705 | "pll is on but not used by any active crtc\n"); |
| 13706 | I915_STATE_WARN(pll->on != active, |
| 13707 | "pll on state mismatch (expected %i, found %i)\n", |
| 13708 | pll->on, active); |
| 13709 | } |
| 13710 | |
| 13711 | if (!crtc) { |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13712 | I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13713 | "more active pll users than references: %x vs %x\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13714 | pll->active_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13715 | |
| 13716 | return; |
| 13717 | } |
| 13718 | |
| 13719 | crtc_mask = 1 << drm_crtc_index(crtc); |
| 13720 | |
| 13721 | if (new_state->active) |
| 13722 | I915_STATE_WARN(!(pll->active_mask & crtc_mask), |
| 13723 | "pll active mismatch (expected pipe %c in active mask 0x%02x)\n", |
| 13724 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 13725 | else |
| 13726 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 13727 | "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n", |
| 13728 | pipe_name(drm_crtc_index(crtc)), pll->active_mask); |
| 13729 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13730 | I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask), |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13731 | "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13732 | crtc_mask, pll->state.crtc_mask); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13733 | |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13734 | I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13735 | &dpll_hw_state, |
| 13736 | sizeof(dpll_hw_state)), |
| 13737 | "pll hw state mismatch\n"); |
| 13738 | } |
| 13739 | |
| 13740 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13741 | verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc, |
| 13742 | struct drm_crtc_state *old_crtc_state, |
| 13743 | struct drm_crtc_state *new_crtc_state) |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13744 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13745 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13746 | struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state); |
| 13747 | struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state); |
| 13748 | |
| 13749 | if (new_state->shared_dpll) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13750 | verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13751 | |
| 13752 | if (old_state->shared_dpll && |
| 13753 | old_state->shared_dpll != new_state->shared_dpll) { |
| 13754 | unsigned crtc_mask = 1 << drm_crtc_index(crtc); |
| 13755 | struct intel_shared_dpll *pll = old_state->shared_dpll; |
| 13756 | |
| 13757 | I915_STATE_WARN(pll->active_mask & crtc_mask, |
| 13758 | "pll active mismatch (didn't expect pipe %c in active mask)\n", |
| 13759 | pipe_name(drm_crtc_index(crtc))); |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 13760 | I915_STATE_WARN(pll->state.crtc_mask & crtc_mask, |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13761 | "pll enabled crtcs mismatch (found %x in enabled mask)\n", |
| 13762 | pipe_name(drm_crtc_index(crtc))); |
| 13763 | } |
| 13764 | } |
| 13765 | |
| 13766 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13767 | intel_modeset_verify_crtc(struct drm_crtc *crtc, |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13768 | struct drm_atomic_state *state, |
| 13769 | struct drm_crtc_state *old_state, |
| 13770 | struct drm_crtc_state *new_state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13771 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 13772 | if (!needs_modeset(new_state) && |
| 13773 | !to_intel_crtc_state(new_state)->update_pipe) |
| 13774 | return; |
| 13775 | |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13776 | verify_wm_state(crtc, new_state); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13777 | verify_connector_state(crtc->dev, state, crtc); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13778 | verify_crtc_state(crtc, old_state, new_state); |
| 13779 | verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13780 | } |
| 13781 | |
| 13782 | static void |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13783 | verify_disabled_dpll_state(struct drm_device *dev) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13784 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13785 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 13786 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13787 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13788 | for (i = 0; i < dev_priv->num_shared_dpll; i++) |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13789 | verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL); |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13790 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13791 | |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13792 | static void |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13793 | intel_modeset_verify_disabled(struct drm_device *dev, |
| 13794 | struct drm_atomic_state *state) |
Maarten Lankhorst | e7c8454 | 2016-03-23 14:58:06 +0100 | [diff] [blame] | 13795 | { |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13796 | verify_encoder_state(dev); |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 13797 | verify_connector_state(dev, state, NULL); |
Maarten Lankhorst | c0ead70 | 2016-03-30 10:00:05 +0200 | [diff] [blame] | 13798 | verify_disabled_dpll_state(dev); |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 13799 | } |
| 13800 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13801 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 13802 | { |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13803 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13804 | |
| 13805 | /* |
| 13806 | * The scanline counter increments at the leading edge of hsync. |
| 13807 | * |
| 13808 | * On most platforms it starts counting from vtotal-1 on the |
| 13809 | * first active line. That means the scanline counter value is |
| 13810 | * always one less than what we would expect. Ie. just after |
| 13811 | * start of vblank, which also occurs at start of hsync (on the |
| 13812 | * last active line), the scanline counter will read vblank_start-1. |
| 13813 | * |
| 13814 | * On gen2 the scanline counter starts counting from 1 instead |
| 13815 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 13816 | * to keep the value positive), instead of adding one. |
| 13817 | * |
| 13818 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 13819 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 13820 | * there's an extra 1 line difference. So we need to add two instead of |
| 13821 | * one to the value. |
| 13822 | */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13823 | if (IS_GEN2(dev_priv)) { |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13824 | 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] | 13825 | int vtotal; |
| 13826 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 13827 | vtotal = adjusted_mode->crtc_vtotal; |
| 13828 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13829 | vtotal /= 2; |
| 13830 | |
| 13831 | crtc->scanline_offset = vtotal - 1; |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 13832 | } else if (HAS_DDI(dev_priv) && |
Ville Syrjälä | 2d84d2b | 2016-06-22 21:57:02 +0300 | [diff] [blame] | 13833 | intel_crtc_has_type(crtc->config, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13834 | crtc->scanline_offset = 2; |
| 13835 | } else |
| 13836 | crtc->scanline_offset = 1; |
| 13837 | } |
| 13838 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13839 | 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] | 13840 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13841 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13842 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13843 | struct drm_crtc *crtc; |
| 13844 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13845 | int i; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13846 | |
| 13847 | if (!dev_priv->display.crtc_compute_clock) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13848 | return; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13849 | |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13850 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13851 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13852 | struct intel_shared_dpll *old_dpll = |
| 13853 | to_intel_crtc_state(crtc->state)->shared_dpll; |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 13854 | |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13855 | if (!needs_modeset(crtc_state)) |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 13856 | continue; |
| 13857 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13858 | to_intel_crtc_state(crtc_state)->shared_dpll = NULL; |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13859 | |
Ander Conselvan de Oliveira | 8106ddb | 2016-03-08 17:46:18 +0200 | [diff] [blame] | 13860 | if (!old_dpll) |
Maarten Lankhorst | fb1a38a | 2016-02-09 13:02:17 +0100 | [diff] [blame] | 13861 | continue; |
Ander Conselvan de Oliveira | 0a9ab30 | 2015-04-21 17:13:04 +0300 | [diff] [blame] | 13862 | |
Ander Conselvan de Oliveira | a1c414e | 2016-12-29 17:22:07 +0200 | [diff] [blame] | 13863 | intel_release_shared_dpll(old_dpll, intel_crtc, state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13864 | } |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 13865 | } |
| 13866 | |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 13867 | /* |
| 13868 | * This implements the workaround described in the "notes" section of the mode |
| 13869 | * set sequence documentation. When going from no pipes or single pipe to |
| 13870 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 13871 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 13872 | */ |
| 13873 | static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state) |
| 13874 | { |
| 13875 | struct drm_crtc_state *crtc_state; |
| 13876 | struct intel_crtc *intel_crtc; |
| 13877 | struct drm_crtc *crtc; |
| 13878 | struct intel_crtc_state *first_crtc_state = NULL; |
| 13879 | struct intel_crtc_state *other_crtc_state = NULL; |
| 13880 | enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE; |
| 13881 | int i; |
| 13882 | |
| 13883 | /* look at all crtc's that are going to be enabled in during modeset */ |
| 13884 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13885 | intel_crtc = to_intel_crtc(crtc); |
| 13886 | |
| 13887 | if (!crtc_state->active || !needs_modeset(crtc_state)) |
| 13888 | continue; |
| 13889 | |
| 13890 | if (first_crtc_state) { |
| 13891 | other_crtc_state = to_intel_crtc_state(crtc_state); |
| 13892 | break; |
| 13893 | } else { |
| 13894 | first_crtc_state = to_intel_crtc_state(crtc_state); |
| 13895 | first_pipe = intel_crtc->pipe; |
| 13896 | } |
| 13897 | } |
| 13898 | |
| 13899 | /* No workaround needed? */ |
| 13900 | if (!first_crtc_state) |
| 13901 | return 0; |
| 13902 | |
| 13903 | /* w/a possibly needed, check how many crtc's are already enabled. */ |
| 13904 | for_each_intel_crtc(state->dev, intel_crtc) { |
| 13905 | struct intel_crtc_state *pipe_config; |
| 13906 | |
| 13907 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 13908 | if (IS_ERR(pipe_config)) |
| 13909 | return PTR_ERR(pipe_config); |
| 13910 | |
| 13911 | pipe_config->hsw_workaround_pipe = INVALID_PIPE; |
| 13912 | |
| 13913 | if (!pipe_config->base.active || |
| 13914 | needs_modeset(&pipe_config->base)) |
| 13915 | continue; |
| 13916 | |
| 13917 | /* 2 or more enabled crtcs means no need for w/a */ |
| 13918 | if (enabled_pipe != INVALID_PIPE) |
| 13919 | return 0; |
| 13920 | |
| 13921 | enabled_pipe = intel_crtc->pipe; |
| 13922 | } |
| 13923 | |
| 13924 | if (enabled_pipe != INVALID_PIPE) |
| 13925 | first_crtc_state->hsw_workaround_pipe = enabled_pipe; |
| 13926 | else if (other_crtc_state) |
| 13927 | other_crtc_state->hsw_workaround_pipe = first_pipe; |
| 13928 | |
| 13929 | return 0; |
| 13930 | } |
| 13931 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 13932 | static int intel_lock_all_pipes(struct drm_atomic_state *state) |
| 13933 | { |
| 13934 | struct drm_crtc *crtc; |
| 13935 | |
| 13936 | /* Add all pipes to the state */ |
| 13937 | for_each_crtc(state->dev, crtc) { |
| 13938 | struct drm_crtc_state *crtc_state; |
| 13939 | |
| 13940 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13941 | if (IS_ERR(crtc_state)) |
| 13942 | return PTR_ERR(crtc_state); |
| 13943 | } |
| 13944 | |
| 13945 | return 0; |
| 13946 | } |
| 13947 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13948 | static int intel_modeset_all_pipes(struct drm_atomic_state *state) |
| 13949 | { |
| 13950 | struct drm_crtc *crtc; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13951 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 13952 | /* |
| 13953 | * Add all pipes to the state, and force |
| 13954 | * a modeset on all the active ones. |
| 13955 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13956 | for_each_crtc(state->dev, crtc) { |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 13957 | struct drm_crtc_state *crtc_state; |
| 13958 | int ret; |
| 13959 | |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13960 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 13961 | if (IS_ERR(crtc_state)) |
| 13962 | return PTR_ERR(crtc_state); |
| 13963 | |
| 13964 | if (!crtc_state->active || needs_modeset(crtc_state)) |
| 13965 | continue; |
| 13966 | |
| 13967 | crtc_state->mode_changed = true; |
| 13968 | |
| 13969 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 13970 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 13971 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13972 | |
| 13973 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 13974 | if (ret) |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 13975 | return ret; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13976 | } |
| 13977 | |
Ville Syrjälä | 9780aad | 2016-11-14 18:35:11 +0200 | [diff] [blame] | 13978 | return 0; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 13979 | } |
| 13980 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 13981 | static int intel_modeset_checks(struct drm_atomic_state *state) |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13982 | { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13983 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 13984 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13985 | struct drm_crtc *crtc; |
| 13986 | struct drm_crtc_state *crtc_state; |
| 13987 | int ret = 0, i; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 13988 | |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 13989 | if (!check_digital_port_conflicts(state)) { |
| 13990 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 13991 | return -EINVAL; |
| 13992 | } |
| 13993 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 13994 | intel_state->modeset = true; |
| 13995 | intel_state->active_crtcs = dev_priv->active_crtcs; |
| 13996 | |
| 13997 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 13998 | if (crtc_state->active) |
| 13999 | intel_state->active_crtcs |= 1 << i; |
| 14000 | else |
| 14001 | intel_state->active_crtcs &= ~(1 << i); |
Matt Roper | 8b4a7d0 | 2016-05-12 07:06:00 -0700 | [diff] [blame] | 14002 | |
| 14003 | if (crtc_state->active != crtc->state->active) |
| 14004 | intel_state->active_pipe_changes |= drm_crtc_mask(crtc); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 14005 | } |
| 14006 | |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 14007 | /* |
| 14008 | * See if the config requires any additional preparation, e.g. |
| 14009 | * to adjust global state with pipes off. We need to do this |
| 14010 | * here so we can get the modeset_pipe updated config for the new |
| 14011 | * mode set on this crtc. For other crtcs we need to use the |
| 14012 | * adjusted_mode bits in the crtc directly. |
| 14013 | */ |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14014 | if (dev_priv->display.modeset_calc_cdclk) { |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 14015 | if (!intel_state->cdclk_pll_vco) |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 14016 | intel_state->cdclk_pll_vco = dev_priv->cdclk_pll.vco; |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 14017 | if (!intel_state->cdclk_pll_vco) |
| 14018 | intel_state->cdclk_pll_vco = dev_priv->skl_preferred_vco_freq; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14019 | |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 14020 | ret = dev_priv->display.modeset_calc_cdclk(state); |
| 14021 | if (ret < 0) |
| 14022 | return ret; |
| 14023 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 14024 | /* |
| 14025 | * Writes to dev_priv->atomic_cdclk_freq must protected by |
| 14026 | * holding all the crtc locks, even if we don't end up |
| 14027 | * touching the hardware |
| 14028 | */ |
| 14029 | if (intel_state->cdclk != dev_priv->atomic_cdclk_freq) { |
| 14030 | ret = intel_lock_all_pipes(state); |
| 14031 | if (ret < 0) |
| 14032 | return ret; |
| 14033 | } |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14034 | |
Ville Syrjälä | 8d96561 | 2016-11-14 18:35:10 +0200 | [diff] [blame] | 14035 | /* All pipes must be switched off while we change the cdclk. */ |
| 14036 | if (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
| 14037 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco) { |
| 14038 | ret = intel_modeset_all_pipes(state); |
| 14039 | if (ret < 0) |
| 14040 | return ret; |
| 14041 | } |
Maarten Lankhorst | e8788cb | 2016-02-16 10:25:11 +0100 | [diff] [blame] | 14042 | |
| 14043 | DRM_DEBUG_KMS("New cdclk calculated to be atomic %u, actual %u\n", |
| 14044 | intel_state->cdclk, intel_state->dev_cdclk); |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 14045 | } else { |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 14046 | to_intel_atomic_state(state)->cdclk = dev_priv->atomic_cdclk_freq; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 14047 | } |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 14048 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 14049 | intel_modeset_clear_plls(state); |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 14050 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 14051 | if (IS_HASWELL(dev_priv)) |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 14052 | return haswell_mode_set_planes_workaround(state); |
Maarten Lankhorst | 99d736a | 2015-06-01 12:50:09 +0200 | [diff] [blame] | 14053 | |
Maarten Lankhorst | ad42137 | 2015-06-15 12:33:42 +0200 | [diff] [blame] | 14054 | return 0; |
Ander Conselvan de Oliveira | 054518d | 2015-04-21 17:13:06 +0300 | [diff] [blame] | 14055 | } |
| 14056 | |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 14057 | /* |
| 14058 | * Handle calculation of various watermark data at the end of the atomic check |
| 14059 | * phase. The code here should be run after the per-crtc and per-plane 'check' |
| 14060 | * handlers to ensure that all derived state has been updated. |
| 14061 | */ |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 14062 | static int calc_watermark_data(struct drm_atomic_state *state) |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 14063 | { |
| 14064 | struct drm_device *dev = state->dev; |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 14065 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | 98d3949 | 2016-05-12 07:06:03 -0700 | [diff] [blame] | 14066 | |
| 14067 | /* Is there platform-specific watermark information to calculate? */ |
| 14068 | if (dev_priv->display.compute_global_watermarks) |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 14069 | return dev_priv->display.compute_global_watermarks(state); |
| 14070 | |
| 14071 | return 0; |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 14072 | } |
| 14073 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 14074 | /** |
| 14075 | * intel_atomic_check - validate state object |
| 14076 | * @dev: drm device |
| 14077 | * @state: state to validate |
| 14078 | */ |
| 14079 | static int intel_atomic_check(struct drm_device *dev, |
| 14080 | struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 14081 | { |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 14082 | struct drm_i915_private *dev_priv = to_i915(dev); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 14083 | 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] | 14084 | struct drm_crtc *crtc; |
| 14085 | struct drm_crtc_state *crtc_state; |
| 14086 | int ret, i; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 14087 | bool any_ms = false; |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14088 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 14089 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 14090 | if (ret) |
| 14091 | return ret; |
| 14092 | |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14093 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14094 | struct intel_crtc_state *pipe_config = |
| 14095 | to_intel_crtc_state(crtc_state); |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 14096 | |
| 14097 | /* Catch I915_MODE_FLAG_INHERITED */ |
| 14098 | if (crtc_state->mode.private_flags != crtc->state->mode.private_flags) |
| 14099 | crtc_state->mode_changed = true; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14100 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14101 | if (!needs_modeset(crtc_state)) |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14102 | continue; |
| 14103 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 14104 | if (!crtc_state->enable) { |
| 14105 | any_ms = true; |
| 14106 | continue; |
| 14107 | } |
| 14108 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14109 | /* FIXME: For only active_changed we shouldn't need to do any |
| 14110 | * state recomputation at all. */ |
| 14111 | |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 14112 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 14113 | if (ret) |
| 14114 | return ret; |
Maarten Lankhorst | b359283 | 2015-06-15 12:33:38 +0200 | [diff] [blame] | 14115 | |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14116 | ret = intel_modeset_pipe_config(crtc, pipe_config); |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 14117 | if (ret) { |
| 14118 | intel_dump_pipe_config(to_intel_crtc(crtc), |
| 14119 | pipe_config, "[failed]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14120 | return ret; |
Maarten Lankhorst | 25aa1c3 | 2016-05-03 10:30:38 +0200 | [diff] [blame] | 14121 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14122 | |
Jani Nikula | 7383123 | 2015-11-19 10:26:30 +0200 | [diff] [blame] | 14123 | if (i915.fastboot && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 14124 | intel_pipe_config_compare(dev_priv, |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14125 | to_intel_crtc_state(crtc->state), |
Daniel Vetter | 1ed51de | 2015-07-15 14:15:51 +0200 | [diff] [blame] | 14126 | pipe_config, true)) { |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14127 | crtc_state->mode_changed = false; |
Maarten Lankhorst | bfd16b2 | 2015-08-27 15:44:05 +0200 | [diff] [blame] | 14128 | to_intel_crtc_state(crtc_state)->update_pipe = true; |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14129 | } |
| 14130 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 14131 | if (needs_modeset(crtc_state)) |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14132 | any_ms = true; |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 14133 | |
Daniel Vetter | af4a879 | 2016-05-09 09:31:25 +0200 | [diff] [blame] | 14134 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 14135 | if (ret) |
| 14136 | return ret; |
Maarten Lankhorst | cfb23ed | 2015-07-14 12:17:40 +0200 | [diff] [blame] | 14137 | |
Daniel Vetter | 2649548 | 2015-07-15 14:15:52 +0200 | [diff] [blame] | 14138 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 14139 | needs_modeset(crtc_state) ? |
| 14140 | "[modeset]" : "[fastset]"); |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14141 | } |
| 14142 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 14143 | if (any_ms) { |
| 14144 | ret = intel_modeset_checks(state); |
| 14145 | |
| 14146 | if (ret) |
| 14147 | return ret; |
Ville Syrjälä | e0ca7a6 | 2016-11-14 18:35:09 +0200 | [diff] [blame] | 14148 | } else { |
| 14149 | intel_state->cdclk = dev_priv->atomic_cdclk_freq; |
| 14150 | } |
Ander Conselvan de Oliveira | c347a67 | 2015-06-01 12:50:02 +0200 | [diff] [blame] | 14151 | |
Paulo Zanoni | dd8b3bd | 2016-01-19 11:35:49 -0200 | [diff] [blame] | 14152 | ret = drm_atomic_helper_check_planes(dev, state); |
Matt Roper | aa36313 | 2015-09-24 15:53:18 -0700 | [diff] [blame] | 14153 | if (ret) |
| 14154 | return ret; |
| 14155 | |
Paulo Zanoni | f51be2e | 2016-01-19 11:35:50 -0200 | [diff] [blame] | 14156 | intel_fbc_choose_crtc(dev_priv, state); |
Matt Roper | 55994c2 | 2016-05-12 07:06:08 -0700 | [diff] [blame] | 14157 | return calc_watermark_data(state); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 14158 | } |
| 14159 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14160 | static int intel_atomic_prepare_commit(struct drm_device *dev, |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14161 | struct drm_atomic_state *state) |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14162 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14163 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14164 | struct drm_crtc_state *crtc_state; |
| 14165 | struct drm_crtc *crtc; |
| 14166 | int i, ret; |
| 14167 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14168 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 14169 | if (state->legacy_cursor_update) |
| 14170 | continue; |
| 14171 | |
| 14172 | ret = intel_crtc_wait_for_pending_flips(crtc); |
| 14173 | if (ret) |
| 14174 | return ret; |
| 14175 | |
| 14176 | if (atomic_read(&to_intel_crtc(crtc)->unpin_work_count) >= 2) |
| 14177 | flush_workqueue(dev_priv->wq); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 14178 | } |
| 14179 | |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14180 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
| 14181 | if (ret) |
| 14182 | return ret; |
| 14183 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14184 | ret = drm_atomic_helper_prepare_planes(dev, state); |
Chris Wilson | f7e5838 | 2016-04-13 17:35:07 +0100 | [diff] [blame] | 14185 | mutex_unlock(&dev->struct_mutex); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14186 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14187 | return ret; |
| 14188 | } |
| 14189 | |
Maarten Lankhorst | a299141 | 2016-05-17 15:07:48 +0200 | [diff] [blame] | 14190 | u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc) |
| 14191 | { |
| 14192 | struct drm_device *dev = crtc->base.dev; |
| 14193 | |
| 14194 | if (!dev->max_vblank_count) |
| 14195 | return drm_accurate_vblank_count(&crtc->base); |
| 14196 | |
| 14197 | return dev->driver->get_vblank_counter(dev, crtc->pipe); |
| 14198 | } |
| 14199 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14200 | static void intel_atomic_wait_for_vblanks(struct drm_device *dev, |
| 14201 | struct drm_i915_private *dev_priv, |
| 14202 | unsigned crtc_mask) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14203 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14204 | unsigned last_vblank_count[I915_MAX_PIPES]; |
| 14205 | enum pipe pipe; |
| 14206 | int ret; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14207 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14208 | if (!crtc_mask) |
| 14209 | return; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14210 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14211 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 14212 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, |
| 14213 | pipe); |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14214 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14215 | if (!((1 << pipe) & crtc_mask)) |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14216 | continue; |
| 14217 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 14218 | ret = drm_crtc_vblank_get(&crtc->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14219 | if (WARN_ON(ret != 0)) { |
| 14220 | crtc_mask &= ~(1 << pipe); |
| 14221 | continue; |
| 14222 | } |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 14223 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 14224 | last_vblank_count[pipe] = drm_crtc_vblank_count(&crtc->base); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14225 | } |
| 14226 | |
| 14227 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 14228 | struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, |
| 14229 | pipe); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14230 | long lret; |
| 14231 | |
| 14232 | if (!((1 << pipe) & crtc_mask)) |
| 14233 | continue; |
| 14234 | |
| 14235 | lret = wait_event_timeout(dev->vblank[pipe].queue, |
| 14236 | last_vblank_count[pipe] != |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 14237 | drm_crtc_vblank_count(&crtc->base), |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14238 | msecs_to_jiffies(50)); |
| 14239 | |
| 14240 | WARN(!lret, "pipe %c vblank wait timed out\n", pipe_name(pipe)); |
| 14241 | |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 14242 | drm_crtc_vblank_put(&crtc->base); |
Maarten Lankhorst | d55dbd0 | 2016-05-17 15:08:04 +0200 | [diff] [blame] | 14243 | } |
| 14244 | } |
| 14245 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14246 | static bool needs_vblank_wait(struct intel_crtc_state *crtc_state) |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 14247 | { |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14248 | /* fb updated, need to unpin old fb */ |
| 14249 | if (crtc_state->fb_changed) |
| 14250 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 14251 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14252 | /* wm changes, need vblank before final wm's */ |
| 14253 | if (crtc_state->update_wm_post) |
| 14254 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 14255 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14256 | /* |
| 14257 | * cxsr is re-enabled after vblank. |
| 14258 | * This is already handled by crtc_state->update_wm_post, |
| 14259 | * but added for clarity. |
| 14260 | */ |
| 14261 | if (crtc_state->disable_cxsr) |
| 14262 | return true; |
Maarten Lankhorst | a6747b7 | 2016-05-17 15:08:01 +0200 | [diff] [blame] | 14263 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14264 | return false; |
Maarten Lankhorst | e886167 | 2016-02-24 11:24:26 +0100 | [diff] [blame] | 14265 | } |
| 14266 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 14267 | static void intel_update_crtc(struct drm_crtc *crtc, |
| 14268 | struct drm_atomic_state *state, |
| 14269 | struct drm_crtc_state *old_crtc_state, |
| 14270 | unsigned int *crtc_vblank_mask) |
| 14271 | { |
| 14272 | struct drm_device *dev = crtc->dev; |
| 14273 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 14274 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14275 | struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc->state); |
| 14276 | bool modeset = needs_modeset(crtc->state); |
| 14277 | |
| 14278 | if (modeset) { |
| 14279 | update_scanline_offset(intel_crtc); |
| 14280 | dev_priv->display.crtc_enable(pipe_config, state); |
| 14281 | } else { |
| 14282 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 14283 | } |
| 14284 | |
| 14285 | if (drm_atomic_get_existing_plane_state(state, crtc->primary)) { |
| 14286 | intel_fbc_enable( |
| 14287 | intel_crtc, pipe_config, |
| 14288 | to_intel_plane_state(crtc->primary->state)); |
| 14289 | } |
| 14290 | |
| 14291 | drm_atomic_helper_commit_planes_on_crtc(old_crtc_state); |
| 14292 | |
| 14293 | if (needs_vblank_wait(pipe_config)) |
| 14294 | *crtc_vblank_mask |= drm_crtc_mask(crtc); |
| 14295 | } |
| 14296 | |
| 14297 | static void intel_update_crtcs(struct drm_atomic_state *state, |
| 14298 | unsigned int *crtc_vblank_mask) |
| 14299 | { |
| 14300 | struct drm_crtc *crtc; |
| 14301 | struct drm_crtc_state *old_crtc_state; |
| 14302 | int i; |
| 14303 | |
| 14304 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 14305 | if (!crtc->state->active) |
| 14306 | continue; |
| 14307 | |
| 14308 | intel_update_crtc(crtc, state, old_crtc_state, |
| 14309 | crtc_vblank_mask); |
| 14310 | } |
| 14311 | } |
| 14312 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14313 | static void skl_update_crtcs(struct drm_atomic_state *state, |
| 14314 | unsigned int *crtc_vblank_mask) |
| 14315 | { |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 14316 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14317 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 14318 | struct drm_crtc *crtc; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 14319 | struct intel_crtc *intel_crtc; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14320 | struct drm_crtc_state *old_crtc_state; |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 14321 | struct intel_crtc_state *cstate; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14322 | unsigned int updated = 0; |
| 14323 | bool progress; |
| 14324 | enum pipe pipe; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 14325 | int i; |
| 14326 | |
| 14327 | const struct skl_ddb_entry *entries[I915_MAX_PIPES] = {}; |
| 14328 | |
| 14329 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) |
| 14330 | /* ignore allocations for crtc's that have been turned off. */ |
| 14331 | if (crtc->state->active) |
| 14332 | entries[i] = &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14333 | |
| 14334 | /* |
| 14335 | * Whenever the number of active pipes changes, we need to make sure we |
| 14336 | * update the pipes in the right order so that their ddb allocations |
| 14337 | * never overlap with eachother inbetween CRTC updates. Otherwise we'll |
| 14338 | * cause pipe underruns and other bad stuff. |
| 14339 | */ |
| 14340 | do { |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14341 | progress = false; |
| 14342 | |
| 14343 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 14344 | bool vbl_wait = false; |
| 14345 | unsigned int cmask = drm_crtc_mask(crtc); |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 14346 | |
| 14347 | intel_crtc = to_intel_crtc(crtc); |
| 14348 | cstate = to_intel_crtc_state(crtc->state); |
| 14349 | pipe = intel_crtc->pipe; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14350 | |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 14351 | if (updated & cmask || !cstate->base.active) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14352 | continue; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 14353 | |
| 14354 | if (skl_ddb_allocation_overlaps(entries, &cstate->wm.skl.ddb, i)) |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14355 | continue; |
| 14356 | |
| 14357 | updated |= cmask; |
Maarten Lankhorst | 5eff503 | 2016-11-08 13:55:35 +0100 | [diff] [blame] | 14358 | entries[i] = &cstate->wm.skl.ddb; |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14359 | |
| 14360 | /* |
| 14361 | * If this is an already active pipe, it's DDB changed, |
| 14362 | * and this isn't the last pipe that needs updating |
| 14363 | * then we need to wait for a vblank to pass for the |
| 14364 | * new ddb allocation to take effect. |
| 14365 | */ |
Lyude | ce0ba28 | 2016-09-15 10:46:35 -0400 | [diff] [blame] | 14366 | if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb, |
Maarten Lankhorst | 512b552 | 2016-11-08 13:55:34 +0100 | [diff] [blame] | 14367 | &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) && |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14368 | !crtc->state->active_changed && |
| 14369 | intel_state->wm_results.dirty_pipes != updated) |
| 14370 | vbl_wait = true; |
| 14371 | |
| 14372 | intel_update_crtc(crtc, state, old_crtc_state, |
| 14373 | crtc_vblank_mask); |
| 14374 | |
| 14375 | if (vbl_wait) |
Ville Syrjälä | 0f0f74b | 2016-10-31 22:37:06 +0200 | [diff] [blame] | 14376 | intel_wait_for_vblank(dev_priv, pipe); |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 14377 | |
| 14378 | progress = true; |
| 14379 | } |
| 14380 | } while (progress); |
| 14381 | } |
| 14382 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14383 | static void intel_atomic_commit_tail(struct drm_atomic_state *state) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 14384 | { |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14385 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 14386 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14387 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 14388 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14389 | struct drm_crtc *crtc; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14390 | struct intel_crtc_state *intel_cstate; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14391 | bool hw_check = intel_state->modeset; |
| 14392 | unsigned long put_domains[I915_MAX_PIPES] = {}; |
| 14393 | unsigned crtc_vblank_mask = 0; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 14394 | int i; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 14395 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 14396 | drm_atomic_helper_wait_for_dependencies(state); |
| 14397 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 14398 | if (intel_state->modeset) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14399 | intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 14400 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 14401 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 14402 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14403 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14404 | if (needs_modeset(crtc->state) || |
| 14405 | to_intel_crtc_state(crtc->state)->update_pipe) { |
| 14406 | hw_check = true; |
| 14407 | |
| 14408 | put_domains[to_intel_crtc(crtc)->pipe] = |
| 14409 | modeset_get_crtc_power_domains(crtc, |
| 14410 | to_intel_crtc_state(crtc->state)); |
| 14411 | } |
| 14412 | |
Maarten Lankhorst | 61333b6 | 2015-06-15 12:33:50 +0200 | [diff] [blame] | 14413 | if (!needs_modeset(crtc->state)) |
| 14414 | continue; |
| 14415 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 14416 | intel_pre_plane_update(to_intel_crtc_state(old_crtc_state)); |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 14417 | |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 14418 | if (old_crtc_state->active) { |
| 14419 | intel_crtc_disable_planes(crtc, old_crtc_state->plane_mask); |
Maarten Lankhorst | 4a80655 | 2016-08-09 17:04:01 +0200 | [diff] [blame] | 14420 | dev_priv->display.crtc_disable(to_intel_crtc_state(old_crtc_state), state); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 14421 | intel_crtc->active = false; |
Paulo Zanoni | 58f9c0b | 2016-01-19 11:35:51 -0200 | [diff] [blame] | 14422 | intel_fbc_disable(intel_crtc); |
Maarten Lankhorst | eddfcbc | 2015-06-15 12:33:53 +0200 | [diff] [blame] | 14423 | intel_disable_shared_dpll(intel_crtc); |
Ville Syrjälä | 9bbc8258a | 2015-11-20 22:09:20 +0200 | [diff] [blame] | 14424 | |
| 14425 | /* |
| 14426 | * Underruns don't always raise |
| 14427 | * interrupts, so check manually. |
| 14428 | */ |
| 14429 | intel_check_cpu_fifo_underruns(dev_priv); |
| 14430 | intel_check_pch_fifo_underruns(dev_priv); |
Maarten Lankhorst | b900111 | 2015-11-19 16:07:16 +0100 | [diff] [blame] | 14431 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 14432 | if (!crtc->state->active) { |
| 14433 | /* |
| 14434 | * Make sure we don't call initial_watermarks |
| 14435 | * for ILK-style watermark updates. |
| 14436 | */ |
| 14437 | if (dev_priv->display.atomic_update_watermarks) |
| 14438 | dev_priv->display.initial_watermarks(intel_state, |
| 14439 | to_intel_crtc_state(crtc->state)); |
| 14440 | else |
| 14441 | intel_update_watermarks(intel_crtc); |
| 14442 | } |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 14443 | } |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 14444 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 14445 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 14446 | /* Only after disabling all output pipelines that will be changed can we |
| 14447 | * update the the output configuration. */ |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 14448 | intel_modeset_update_crtc_state(state); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 14449 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 14450 | if (intel_state->modeset) { |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 14451 | drm_atomic_helper_update_legacy_modeset_state(state->dev, state); |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 14452 | |
| 14453 | if (dev_priv->display.modeset_commit_cdclk && |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 14454 | (intel_state->dev_cdclk != dev_priv->cdclk_freq || |
Ville Syrjälä | 63911d7 | 2016-05-13 23:41:32 +0300 | [diff] [blame] | 14455 | intel_state->cdclk_pll_vco != dev_priv->cdclk_pll.vco)) |
Maarten Lankhorst | 33c8df89 | 2016-02-10 13:49:37 +0100 | [diff] [blame] | 14456 | dev_priv->display.modeset_commit_cdclk(state); |
Maarten Lankhorst | f6d1973 | 2016-03-23 14:58:07 +0100 | [diff] [blame] | 14457 | |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 14458 | /* |
| 14459 | * SKL workaround: bspec recommends we disable the SAGV when we |
| 14460 | * have more then one pipe enabled |
| 14461 | */ |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 14462 | if (!intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 14463 | intel_disable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 14464 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 14465 | intel_modeset_verify_disabled(dev, state); |
Maarten Lankhorst | 4740b0f | 2015-08-05 12:37:10 +0200 | [diff] [blame] | 14466 | } |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 14467 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 14468 | /* Complete the events for pipes that have now been disabled */ |
Ville Syrjälä | 29ceb0e | 2016-03-09 19:07:27 +0200 | [diff] [blame] | 14469 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | f6ac4b2 | 2015-07-13 16:30:31 +0200 | [diff] [blame] | 14470 | bool modeset = needs_modeset(crtc->state); |
Maarten Lankhorst | a539205 | 2015-06-15 12:33:52 +0200 | [diff] [blame] | 14471 | |
Daniel Vetter | 1f7528c | 2016-06-13 16:13:45 +0200 | [diff] [blame] | 14472 | /* Complete events for now disable pipes here. */ |
| 14473 | if (modeset && !crtc->state->active && crtc->state->event) { |
| 14474 | spin_lock_irq(&dev->event_lock); |
| 14475 | drm_crtc_send_vblank_event(crtc, crtc->state->event); |
| 14476 | spin_unlock_irq(&dev->event_lock); |
| 14477 | |
| 14478 | crtc->state->event = NULL; |
| 14479 | } |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 14480 | } |
| 14481 | |
Lyude | 896e5bb | 2016-08-24 07:48:09 +0200 | [diff] [blame] | 14482 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
| 14483 | dev_priv->display.update_crtcs(state, &crtc_vblank_mask); |
| 14484 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14485 | /* FIXME: We should call drm_atomic_helper_commit_hw_done() here |
| 14486 | * already, but still need the state for the delayed optimization. To |
| 14487 | * fix this: |
| 14488 | * - wrap the optimization/post_plane_update stuff into a per-crtc work. |
| 14489 | * - schedule that vblank worker _before_ calling hw_done |
| 14490 | * - at the start of commit_tail, cancel it _synchrously |
| 14491 | * - switch over to the vblank wait helper in the core after that since |
| 14492 | * we don't need out special handling any more. |
| 14493 | */ |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14494 | if (!state->legacy_cursor_update) |
| 14495 | intel_atomic_wait_for_vblanks(dev, dev_priv, crtc_vblank_mask); |
| 14496 | |
| 14497 | /* |
| 14498 | * Now that the vblank has passed, we can go ahead and program the |
| 14499 | * optimal watermarks on platforms that need two-step watermark |
| 14500 | * programming. |
| 14501 | * |
| 14502 | * TODO: Move this (and other cleanup) to an async worker eventually. |
| 14503 | */ |
| 14504 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 14505 | intel_cstate = to_intel_crtc_state(crtc->state); |
| 14506 | |
| 14507 | if (dev_priv->display.optimize_watermarks) |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14508 | dev_priv->display.optimize_watermarks(intel_state, |
| 14509 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14510 | } |
| 14511 | |
| 14512 | for_each_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 14513 | intel_post_plane_update(to_intel_crtc_state(old_crtc_state)); |
| 14514 | |
| 14515 | if (put_domains[i]) |
| 14516 | modeset_put_power_domains(dev_priv, put_domains[i]); |
| 14517 | |
Maarten Lankhorst | 677100c | 2016-11-08 13:55:41 +0100 | [diff] [blame] | 14518 | intel_modeset_verify_crtc(crtc, state, old_crtc_state, crtc->state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14519 | } |
| 14520 | |
Paulo Zanoni | 56feca9 | 2016-09-22 18:00:28 -0300 | [diff] [blame] | 14521 | if (intel_state->modeset && intel_can_enable_sagv(state)) |
Paulo Zanoni | 16dcdc4 | 2016-09-22 18:00:27 -0300 | [diff] [blame] | 14522 | intel_enable_sagv(dev_priv); |
Lyude | 656d1b8 | 2016-08-17 15:55:54 -0400 | [diff] [blame] | 14523 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14524 | drm_atomic_helper_commit_hw_done(state); |
| 14525 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14526 | if (intel_state->modeset) |
| 14527 | intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET); |
| 14528 | |
| 14529 | mutex_lock(&dev->struct_mutex); |
| 14530 | drm_atomic_helper_cleanup_planes(dev, state); |
| 14531 | mutex_unlock(&dev->struct_mutex); |
| 14532 | |
Daniel Vetter | ea0000f | 2016-06-13 16:13:46 +0200 | [diff] [blame] | 14533 | drm_atomic_helper_commit_cleanup_done(state); |
| 14534 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14535 | drm_atomic_state_put(state); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 14536 | |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 14537 | /* As one of the primary mmio accessors, KMS has a high likelihood |
| 14538 | * of triggering bugs in unclaimed access. After we finish |
| 14539 | * modesetting, see if an error has been flagged, and if so |
| 14540 | * enable debugging for the next modeset - and hope we catch |
| 14541 | * the culprit. |
| 14542 | * |
| 14543 | * XXX note that we assume display power is on at this point. |
| 14544 | * This might hold true now but we need to add pm helper to check |
| 14545 | * unclaimed only when the hardware is on, as atomic commits |
| 14546 | * can happen also when the device is completely off. |
| 14547 | */ |
| 14548 | intel_uncore_arm_unclaimed_mmio_detection(dev_priv); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14549 | } |
| 14550 | |
| 14551 | static void intel_atomic_commit_work(struct work_struct *work) |
| 14552 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14553 | struct drm_atomic_state *state = |
| 14554 | container_of(work, struct drm_atomic_state, commit_work); |
| 14555 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14556 | intel_atomic_commit_tail(state); |
| 14557 | } |
| 14558 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14559 | static int __i915_sw_fence_call |
| 14560 | intel_atomic_commit_ready(struct i915_sw_fence *fence, |
| 14561 | enum i915_sw_fence_notify notify) |
| 14562 | { |
| 14563 | struct intel_atomic_state *state = |
| 14564 | container_of(fence, struct intel_atomic_state, commit_ready); |
| 14565 | |
| 14566 | switch (notify) { |
| 14567 | case FENCE_COMPLETE: |
| 14568 | if (state->base.commit_work.func) |
| 14569 | queue_work(system_unbound_wq, &state->base.commit_work); |
| 14570 | break; |
| 14571 | |
| 14572 | case FENCE_FREE: |
| 14573 | drm_atomic_state_put(&state->base); |
| 14574 | break; |
| 14575 | } |
| 14576 | |
| 14577 | return NOTIFY_DONE; |
| 14578 | } |
| 14579 | |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 14580 | static void intel_atomic_track_fbs(struct drm_atomic_state *state) |
| 14581 | { |
| 14582 | struct drm_plane_state *old_plane_state; |
| 14583 | struct drm_plane *plane; |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 14584 | int i; |
| 14585 | |
Chris Wilson | faf5bf0 | 2016-08-04 16:32:37 +0100 | [diff] [blame] | 14586 | for_each_plane_in_state(state, plane, old_plane_state, i) |
| 14587 | i915_gem_track_fb(intel_fb_obj(old_plane_state->fb), |
| 14588 | intel_fb_obj(plane->state->fb), |
| 14589 | to_intel_plane(plane)->frontbuffer_bit); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 14590 | } |
| 14591 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14592 | /** |
| 14593 | * intel_atomic_commit - commit validated state object |
| 14594 | * @dev: DRM device |
| 14595 | * @state: the top-level driver state object |
| 14596 | * @nonblock: nonblocking commit |
| 14597 | * |
| 14598 | * This function commits a top-level state object that has been validated |
| 14599 | * with drm_atomic_helper_check(). |
| 14600 | * |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14601 | * RETURNS |
| 14602 | * Zero for success or -errno. |
| 14603 | */ |
| 14604 | static int intel_atomic_commit(struct drm_device *dev, |
| 14605 | struct drm_atomic_state *state, |
| 14606 | bool nonblock) |
| 14607 | { |
| 14608 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 14609 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14610 | int ret = 0; |
| 14611 | |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14612 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 14613 | if (ret) |
| 14614 | return ret; |
| 14615 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14616 | drm_atomic_state_get(state); |
| 14617 | i915_sw_fence_init(&intel_state->commit_ready, |
| 14618 | intel_atomic_commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14619 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14620 | ret = intel_atomic_prepare_commit(dev, state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14621 | if (ret) { |
| 14622 | DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14623 | i915_sw_fence_commit(&intel_state->commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14624 | return ret; |
| 14625 | } |
| 14626 | |
| 14627 | drm_atomic_helper_swap_state(state, true); |
| 14628 | dev_priv->wm.distrust_bios_wm = false; |
Ander Conselvan de Oliveira | 3c0fb58 | 2016-12-29 17:22:08 +0200 | [diff] [blame] | 14629 | intel_shared_dpll_swap_state(state); |
Daniel Vetter | 6c9c1b3 | 2016-06-13 16:13:48 +0200 | [diff] [blame] | 14630 | intel_atomic_track_fbs(state); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14631 | |
Maarten Lankhorst | c3b3265 | 2016-11-08 13:55:40 +0100 | [diff] [blame] | 14632 | if (intel_state->modeset) { |
| 14633 | memcpy(dev_priv->min_pixclk, intel_state->min_pixclk, |
| 14634 | sizeof(intel_state->min_pixclk)); |
| 14635 | dev_priv->active_crtcs = intel_state->active_crtcs; |
| 14636 | dev_priv->atomic_cdclk_freq = intel_state->cdclk; |
| 14637 | } |
| 14638 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14639 | drm_atomic_state_get(state); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14640 | INIT_WORK(&state->commit_work, |
| 14641 | nonblock ? intel_atomic_commit_work : NULL); |
| 14642 | |
| 14643 | i915_sw_fence_commit(&intel_state->commit_ready); |
| 14644 | if (!nonblock) { |
| 14645 | i915_sw_fence_wait(&intel_state->commit_ready); |
Daniel Vetter | 94f0502 | 2016-06-14 18:01:00 +0200 | [diff] [blame] | 14646 | intel_atomic_commit_tail(state); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14647 | } |
Mika Kuoppala | 7571494 | 2015-12-16 09:26:48 +0200 | [diff] [blame] | 14648 | |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 14649 | return 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14650 | } |
| 14651 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 14652 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 14653 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14654 | struct drm_device *dev = crtc->dev; |
| 14655 | struct drm_atomic_state *state; |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14656 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | 2bfb462 | 2015-04-21 17:13:20 +0300 | [diff] [blame] | 14657 | int ret; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14658 | |
| 14659 | state = drm_atomic_state_alloc(dev); |
| 14660 | if (!state) { |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 14661 | DRM_DEBUG_KMS("[CRTC:%d:%s] crtc restore failed, out of memory", |
| 14662 | crtc->base.id, crtc->name); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14663 | return; |
| 14664 | } |
| 14665 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14666 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14667 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14668 | retry: |
| 14669 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 14670 | ret = PTR_ERR_OR_ZERO(crtc_state); |
| 14671 | if (!ret) { |
| 14672 | if (!crtc_state->active) |
| 14673 | goto out; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14674 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14675 | crtc_state->mode_changed = true; |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 14676 | ret = drm_atomic_commit(state); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14677 | } |
| 14678 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14679 | if (ret == -EDEADLK) { |
| 14680 | drm_atomic_state_clear(state); |
| 14681 | drm_modeset_backoff(state->acquire_ctx); |
| 14682 | goto retry; |
Ander Conselvan de Oliveira | 4be0731 | 2015-04-21 17:13:01 +0300 | [diff] [blame] | 14683 | } |
| 14684 | |
Maarten Lankhorst | e694eb0 | 2015-07-14 16:19:12 +0200 | [diff] [blame] | 14685 | out: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 14686 | drm_atomic_state_put(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 14687 | } |
| 14688 | |
Bob Paauwe | a878487 | 2016-07-15 14:59:02 +0100 | [diff] [blame] | 14689 | /* |
| 14690 | * FIXME: Remove this once i915 is fully DRIVER_ATOMIC by calling |
| 14691 | * drm_atomic_helper_legacy_gamma_set() directly. |
| 14692 | */ |
| 14693 | static int intel_atomic_legacy_gamma_set(struct drm_crtc *crtc, |
| 14694 | u16 *red, u16 *green, u16 *blue, |
| 14695 | uint32_t size) |
| 14696 | { |
| 14697 | struct drm_device *dev = crtc->dev; |
| 14698 | struct drm_mode_config *config = &dev->mode_config; |
| 14699 | struct drm_crtc_state *state; |
| 14700 | int ret; |
| 14701 | |
| 14702 | ret = drm_atomic_helper_legacy_gamma_set(crtc, red, green, blue, size); |
| 14703 | if (ret) |
| 14704 | return ret; |
| 14705 | |
| 14706 | /* |
| 14707 | * Make sure we update the legacy properties so this works when |
| 14708 | * atomic is not enabled. |
| 14709 | */ |
| 14710 | |
| 14711 | state = crtc->state; |
| 14712 | |
| 14713 | drm_object_property_set_value(&crtc->base, |
| 14714 | config->degamma_lut_property, |
| 14715 | (state->degamma_lut) ? |
| 14716 | state->degamma_lut->base.id : 0); |
| 14717 | |
| 14718 | drm_object_property_set_value(&crtc->base, |
| 14719 | config->ctm_property, |
| 14720 | (state->ctm) ? |
| 14721 | state->ctm->base.id : 0); |
| 14722 | |
| 14723 | drm_object_property_set_value(&crtc->base, |
| 14724 | config->gamma_lut_property, |
| 14725 | (state->gamma_lut) ? |
| 14726 | state->gamma_lut->base.id : 0); |
| 14727 | |
| 14728 | return 0; |
| 14729 | } |
| 14730 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 14731 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Bob Paauwe | a878487 | 2016-07-15 14:59:02 +0100 | [diff] [blame] | 14732 | .gamma_set = intel_atomic_legacy_gamma_set, |
Maarten Lankhorst | 74c090b | 2015-07-13 16:30:30 +0200 | [diff] [blame] | 14733 | .set_config = drm_atomic_helper_set_config, |
Lionel Landwerlin | 82cf435 | 2016-03-16 10:57:16 +0000 | [diff] [blame] | 14734 | .set_property = drm_atomic_helper_crtc_set_property, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 14735 | .destroy = intel_crtc_destroy, |
Chris Wilson | 527b6ab | 2016-06-24 13:44:03 +0100 | [diff] [blame] | 14736 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 14737 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 14738 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 14739 | }; |
| 14740 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14741 | /** |
| 14742 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 14743 | * @plane: drm plane to prepare for |
| 14744 | * @fb: framebuffer to prepare for presentation |
| 14745 | * |
| 14746 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 14747 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 14748 | * bits. Some older platforms need special physical address handling for |
| 14749 | * cursor planes. |
| 14750 | * |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14751 | * Must be called with struct_mutex held. |
| 14752 | * |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14753 | * Returns 0 on success, negative error code on failure. |
| 14754 | */ |
| 14755 | int |
| 14756 | intel_prepare_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 14757 | struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14758 | { |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14759 | struct intel_atomic_state *intel_state = |
| 14760 | to_intel_atomic_state(new_state->state); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14761 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 14762 | struct drm_framebuffer *fb = new_state->fb; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14763 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14764 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14765 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14766 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14767 | if (!obj && !old_obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14768 | return 0; |
| 14769 | |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14770 | if (old_obj) { |
| 14771 | struct drm_crtc_state *crtc_state = |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14772 | drm_atomic_get_existing_crtc_state(new_state->state, |
| 14773 | plane->state->crtc); |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14774 | |
| 14775 | /* Big Hammer, we also need to ensure that any pending |
| 14776 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 14777 | * current scanout is retired before unpinning the old |
| 14778 | * framebuffer. Note that we rely on userspace rendering |
| 14779 | * into the buffer attached to the pipe they are waiting |
| 14780 | * on. If not, userspace generates a GPU hang with IPEHR |
| 14781 | * point to the MI_WAIT_FOR_EVENT. |
| 14782 | * |
| 14783 | * This should only fail upon a hung GPU, in which case we |
| 14784 | * can safely continue. |
| 14785 | */ |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14786 | if (needs_modeset(crtc_state)) { |
| 14787 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 14788 | old_obj->resv, NULL, |
| 14789 | false, 0, |
| 14790 | GFP_KERNEL); |
| 14791 | if (ret < 0) |
| 14792 | return ret; |
Chris Wilson | f4457ae | 2016-04-13 17:35:08 +0100 | [diff] [blame] | 14793 | } |
Maarten Lankhorst | 5008e87 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14794 | } |
| 14795 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14796 | if (new_state->fence) { /* explicit fencing */ |
| 14797 | ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready, |
| 14798 | new_state->fence, |
| 14799 | I915_FENCE_TIMEOUT, |
| 14800 | GFP_KERNEL); |
| 14801 | if (ret < 0) |
| 14802 | return ret; |
| 14803 | } |
| 14804 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 14805 | if (!obj) |
| 14806 | return 0; |
| 14807 | |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14808 | if (!new_state->fence) { /* implicit fencing */ |
| 14809 | ret = i915_sw_fence_await_reservation(&intel_state->commit_ready, |
| 14810 | obj->resv, NULL, |
| 14811 | false, I915_FENCE_TIMEOUT, |
| 14812 | GFP_KERNEL); |
| 14813 | if (ret < 0) |
| 14814 | return ret; |
Chris Wilson | 6b5e90f | 2016-11-14 20:41:05 +0000 | [diff] [blame] | 14815 | |
| 14816 | i915_gem_object_wait_priority(obj, 0, I915_PRIORITY_DISPLAY); |
Chris Wilson | c004a90 | 2016-10-28 13:58:45 +0100 | [diff] [blame] | 14817 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14818 | |
Chris Wilson | c37efb9 | 2016-06-17 08:28:47 +0100 | [diff] [blame] | 14819 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14820 | INTEL_INFO(dev_priv)->cursor_needs_physical) { |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 14821 | int align = IS_I830(dev_priv) ? 16 * 1024 : 256; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14822 | ret = i915_gem_object_attach_phys(obj, align); |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14823 | if (ret) { |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14824 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14825 | return ret; |
| 14826 | } |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14827 | } else { |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 14828 | struct i915_vma *vma; |
| 14829 | |
| 14830 | vma = intel_pin_and_fence_fb_obj(fb, new_state->rotation); |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14831 | if (IS_ERR(vma)) { |
| 14832 | DRM_DEBUG_KMS("failed to pin object\n"); |
| 14833 | return PTR_ERR(vma); |
| 14834 | } |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14835 | } |
| 14836 | |
Chris Wilson | d07f0e5 | 2016-10-28 13:58:44 +0100 | [diff] [blame] | 14837 | return 0; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 14838 | } |
| 14839 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14840 | /** |
| 14841 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 14842 | * @plane: drm plane to clean up for |
| 14843 | * @fb: old framebuffer that was on plane |
| 14844 | * |
| 14845 | * Cleans up a framebuffer that has just been removed from a plane. |
Maarten Lankhorst | f935675 | 2015-08-18 13:40:05 +0200 | [diff] [blame] | 14846 | * |
| 14847 | * Must be called with struct_mutex held. |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14848 | */ |
| 14849 | void |
| 14850 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Chris Wilson | 1832040 | 2016-08-18 19:00:16 +0100 | [diff] [blame] | 14851 | struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14852 | { |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14853 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14854 | struct intel_plane_state *old_intel_state; |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14855 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_state->fb); |
| 14856 | struct drm_i915_gem_object *obj = intel_fb_obj(plane->state->fb); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14857 | |
Maarten Lankhorst | 7580d77 | 2015-08-18 13:40:06 +0200 | [diff] [blame] | 14858 | old_intel_state = to_intel_plane_state(old_state); |
| 14859 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14860 | if (!obj && !old_obj) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 14861 | return; |
| 14862 | |
Maarten Lankhorst | 1ee4939 | 2015-09-23 13:27:08 +0200 | [diff] [blame] | 14863 | if (old_obj && (plane->type != DRM_PLANE_TYPE_CURSOR || |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 14864 | !INTEL_INFO(dev_priv)->cursor_needs_physical)) |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 14865 | intel_unpin_fb_obj(old_state->fb, old_state->rotation); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14866 | } |
| 14867 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14868 | int |
| 14869 | skl_max_scale(struct intel_crtc *intel_crtc, struct intel_crtc_state *crtc_state) |
| 14870 | { |
| 14871 | int max_scale; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14872 | int crtc_clock, cdclk; |
| 14873 | |
Maarten Lankhorst | bf8a0af | 2015-11-24 11:29:02 +0100 | [diff] [blame] | 14874 | if (!intel_crtc || !crtc_state->base.enable) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14875 | return DRM_PLANE_HELPER_NO_SCALING; |
| 14876 | |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14877 | crtc_clock = crtc_state->base.adjusted_mode.crtc_clock; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 14878 | cdclk = to_intel_atomic_state(crtc_state->base.state)->cdclk; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14879 | |
Tvrtko Ursulin | 54bf1ce | 2015-10-20 17:17:07 +0100 | [diff] [blame] | 14880 | if (WARN_ON_ONCE(!crtc_clock || cdclk < crtc_clock)) |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14881 | return DRM_PLANE_HELPER_NO_SCALING; |
| 14882 | |
| 14883 | /* |
| 14884 | * skl max scale is lower of: |
| 14885 | * close to 3 but not 3, -1 is for that purpose |
| 14886 | * or |
| 14887 | * cdclk/crtc_clock |
| 14888 | */ |
| 14889 | max_scale = min((1 << 16) * 3 - 1, (1 << 8) * ((cdclk << 8) / crtc_clock)); |
| 14890 | |
| 14891 | return max_scale; |
| 14892 | } |
| 14893 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14894 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14895 | intel_check_primary_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14896 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14897 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14898 | { |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 14899 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 14900 | struct drm_crtc *crtc = state->base.crtc; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14901 | int min_scale = DRM_PLANE_HELPER_NO_SCALING; |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 14902 | int max_scale = DRM_PLANE_HELPER_NO_SCALING; |
| 14903 | bool can_position = false; |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 14904 | int ret; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 14905 | |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 14906 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | 693bdc2 | 2016-01-15 20:46:53 +0200 | [diff] [blame] | 14907 | /* use scaler when colorkey is not required */ |
| 14908 | if (state->ckey.flags == I915_SET_COLORKEY_NONE) { |
| 14909 | min_scale = 1; |
| 14910 | max_scale = skl_max_scale(to_intel_crtc(crtc), crtc_state); |
| 14911 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 14912 | can_position = true; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 14913 | } |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 14914 | |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 14915 | ret = drm_plane_helper_check_state(&state->base, |
| 14916 | &state->clip, |
| 14917 | min_scale, max_scale, |
| 14918 | can_position, true); |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 14919 | if (ret) |
| 14920 | return ret; |
| 14921 | |
Daniel Vetter | cc92638 | 2016-08-15 10:41:47 +0200 | [diff] [blame] | 14922 | if (!state->base.fb) |
Ville Syrjälä | b63a16f | 2016-01-28 16:53:54 +0200 | [diff] [blame] | 14923 | return 0; |
| 14924 | |
| 14925 | if (INTEL_GEN(dev_priv) >= 9) { |
| 14926 | ret = skl_check_plane_surface(state); |
| 14927 | if (ret) |
| 14928 | return ret; |
| 14929 | } |
| 14930 | |
| 14931 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14932 | } |
| 14933 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14934 | static void intel_begin_crtc_commit(struct drm_crtc *crtc, |
| 14935 | struct drm_crtc_state *old_crtc_state) |
| 14936 | { |
| 14937 | struct drm_device *dev = crtc->dev; |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 14938 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14939 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Lyude | b707aa5 | 2016-09-15 10:56:06 -0400 | [diff] [blame] | 14940 | struct intel_crtc_state *intel_cstate = |
| 14941 | to_intel_crtc_state(crtc->state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14942 | struct intel_crtc_state *old_intel_cstate = |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14943 | to_intel_crtc_state(old_crtc_state); |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14944 | struct intel_atomic_state *old_intel_state = |
| 14945 | to_intel_atomic_state(old_crtc_state->state); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14946 | bool modeset = needs_modeset(crtc->state); |
| 14947 | |
| 14948 | /* Perform vblank evasion around commit operation */ |
| 14949 | intel_pipe_update_start(intel_crtc); |
| 14950 | |
| 14951 | if (modeset) |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 14952 | goto out; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14953 | |
| 14954 | if (crtc->state->color_mgmt_changed || to_intel_crtc_state(crtc->state)->update_pipe) { |
| 14955 | intel_color_set_csc(crtc->state); |
| 14956 | intel_color_load_luts(crtc->state); |
| 14957 | } |
| 14958 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14959 | if (intel_cstate->update_pipe) |
| 14960 | intel_update_pipe_config(intel_crtc, old_intel_cstate); |
| 14961 | else if (INTEL_GEN(dev_priv) >= 9) |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14962 | skl_detach_scalers(intel_crtc); |
Lyude | 62e0fb8 | 2016-08-22 12:50:08 -0400 | [diff] [blame] | 14963 | |
Maarten Lankhorst | e62929b | 2016-11-08 13:55:33 +0100 | [diff] [blame] | 14964 | out: |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 14965 | if (dev_priv->display.atomic_update_watermarks) |
| 14966 | dev_priv->display.atomic_update_watermarks(old_intel_state, |
| 14967 | intel_cstate); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 14968 | } |
| 14969 | |
| 14970 | static void intel_finish_crtc_commit(struct drm_crtc *crtc, |
| 14971 | struct drm_crtc_state *old_crtc_state) |
| 14972 | { |
| 14973 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 14974 | |
| 14975 | intel_pipe_update_end(intel_crtc, NULL); |
| 14976 | } |
| 14977 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14978 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14979 | * intel_plane_destroy - destroy a plane |
| 14980 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14981 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14982 | * Common destruction function for all types of planes (primary, cursor, |
| 14983 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 14984 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 14985 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14986 | { |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14987 | drm_plane_cleanup(plane); |
Ville Syrjälä | 69ae561 | 2016-05-27 20:59:22 +0300 | [diff] [blame] | 14988 | kfree(to_intel_plane(plane)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 14989 | } |
| 14990 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 14991 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 14992 | .update_plane = drm_atomic_helper_update_plane, |
| 14993 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 14994 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 14995 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 14996 | .atomic_get_property = intel_plane_atomic_get_property, |
| 14997 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 14998 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 14999 | .atomic_destroy_state = intel_plane_destroy_state, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15000 | }; |
| 15001 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15002 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15003 | intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15004 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15005 | struct intel_plane *primary = NULL; |
| 15006 | struct intel_plane_state *state = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15007 | const uint32_t *intel_primary_formats; |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 15008 | unsigned int supported_rotations; |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 15009 | unsigned int num_formats; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15010 | int ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15011 | |
| 15012 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15013 | if (!primary) { |
| 15014 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15015 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15016 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15017 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 15018 | state = intel_create_plane_state(&primary->base); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15019 | if (!state) { |
| 15020 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15021 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15022 | } |
| 15023 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 15024 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15025 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15026 | primary->can_scale = false; |
| 15027 | primary->max_downscale = 1; |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15028 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 15029 | primary->can_scale = true; |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 15030 | state->scaler_id = -1; |
Chandra Konduru | 6156a45 | 2015-04-27 13:48:39 -0700 | [diff] [blame] | 15031 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15032 | primary->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 15033 | /* |
| 15034 | * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS |
| 15035 | * port is hooked to pipe B. Hence we want plane A feeding pipe B. |
| 15036 | */ |
| 15037 | if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4) |
| 15038 | primary->plane = (enum plane) !pipe; |
| 15039 | else |
| 15040 | primary->plane = (enum plane) pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 15041 | primary->id = PLANE_PRIMARY; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 15042 | primary->frontbuffer_bit = INTEL_FRONTBUFFER_PRIMARY(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 15043 | primary->check_plane = intel_check_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15044 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15045 | if (INTEL_GEN(dev_priv) >= 9) { |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 15046 | intel_primary_formats = skl_primary_formats; |
| 15047 | num_formats = ARRAY_SIZE(skl_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 15048 | |
| 15049 | primary->update_plane = skylake_update_primary_plane; |
| 15050 | primary->disable_plane = skylake_disable_primary_plane; |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15051 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 15052 | intel_primary_formats = i965_primary_formats; |
| 15053 | num_formats = ARRAY_SIZE(i965_primary_formats); |
| 15054 | |
| 15055 | primary->update_plane = ironlake_update_primary_plane; |
| 15056 | primary->disable_plane = i9xx_disable_primary_plane; |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15057 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Damien Lespiau | 568db4f | 2015-05-12 16:13:18 +0100 | [diff] [blame] | 15058 | intel_primary_formats = i965_primary_formats; |
| 15059 | num_formats = ARRAY_SIZE(i965_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 15060 | |
| 15061 | primary->update_plane = i9xx_update_primary_plane; |
| 15062 | primary->disable_plane = i9xx_disable_primary_plane; |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 15063 | } else { |
| 15064 | intel_primary_formats = i8xx_primary_formats; |
| 15065 | num_formats = ARRAY_SIZE(i8xx_primary_formats); |
Maarten Lankhorst | a8d201a | 2016-01-07 11:54:11 +0100 | [diff] [blame] | 15066 | |
| 15067 | primary->update_plane = i9xx_update_primary_plane; |
| 15068 | primary->disable_plane = i9xx_disable_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15069 | } |
| 15070 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15071 | if (INTEL_GEN(dev_priv) >= 9) |
| 15072 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 15073 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 15074 | intel_primary_formats, num_formats, |
| 15075 | DRM_PLANE_TYPE_PRIMARY, |
| 15076 | "plane 1%c", pipe_name(pipe)); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15077 | else if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15078 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 15079 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 15080 | intel_primary_formats, num_formats, |
| 15081 | DRM_PLANE_TYPE_PRIMARY, |
| 15082 | "primary %c", pipe_name(pipe)); |
| 15083 | else |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15084 | ret = drm_universal_plane_init(&dev_priv->drm, &primary->base, |
| 15085 | 0, &intel_plane_funcs, |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 15086 | intel_primary_formats, num_formats, |
| 15087 | DRM_PLANE_TYPE_PRIMARY, |
| 15088 | "plane %c", plane_name(primary->plane)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15089 | if (ret) |
| 15090 | goto fail; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 15091 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 15092 | if (INTEL_GEN(dev_priv) >= 9) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 15093 | supported_rotations = |
| 15094 | DRM_ROTATE_0 | DRM_ROTATE_90 | |
| 15095 | DRM_ROTATE_180 | DRM_ROTATE_270; |
Ville Syrjälä | 4ea7be2 | 2016-11-14 18:54:00 +0200 | [diff] [blame] | 15096 | } else if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) { |
| 15097 | supported_rotations = |
| 15098 | DRM_ROTATE_0 | DRM_ROTATE_180 | |
| 15099 | DRM_REFLECT_X; |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 15100 | } else if (INTEL_GEN(dev_priv) >= 4) { |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 15101 | supported_rotations = |
| 15102 | DRM_ROTATE_0 | DRM_ROTATE_180; |
| 15103 | } else { |
| 15104 | supported_rotations = DRM_ROTATE_0; |
| 15105 | } |
| 15106 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 15107 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 15108 | drm_plane_create_rotation_property(&primary->base, |
| 15109 | DRM_ROTATE_0, |
| 15110 | supported_rotations); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 15111 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15112 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 15113 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15114 | return primary; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15115 | |
| 15116 | fail: |
| 15117 | kfree(state); |
| 15118 | kfree(primary); |
| 15119 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15120 | return ERR_PTR(ret); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 15121 | } |
| 15122 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15123 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15124 | intel_check_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 061e4b8 | 2015-06-15 12:33:46 +0200 | [diff] [blame] | 15125 | struct intel_crtc_state *crtc_state, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15126 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15127 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 15128 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15129 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 15130 | enum pipe pipe = to_intel_plane(plane)->pipe; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15131 | unsigned stride; |
| 15132 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15133 | |
Ville Syrjälä | f8856a4 | 2016-07-26 19:07:00 +0300 | [diff] [blame] | 15134 | ret = drm_plane_helper_check_state(&state->base, |
| 15135 | &state->clip, |
| 15136 | DRM_PLANE_HELPER_NO_SCALING, |
| 15137 | DRM_PLANE_HELPER_NO_SCALING, |
| 15138 | true, true); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15139 | if (ret) |
| 15140 | return ret; |
| 15141 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15142 | /* if we want to turn off the cursor ignore width and height */ |
| 15143 | if (!obj) |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 15144 | return 0; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15145 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15146 | /* Check for which cursor types we support */ |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 15147 | if (!cursor_size_ok(to_i915(plane->dev), state->base.crtc_w, |
| 15148 | state->base.crtc_h)) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15149 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 15150 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15151 | return -EINVAL; |
| 15152 | } |
| 15153 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15154 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 15155 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15156 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 15157 | return -ENOMEM; |
| 15158 | } |
| 15159 | |
Ville Syrjälä | bae781b | 2016-11-16 13:33:16 +0200 | [diff] [blame] | 15160 | if (fb->modifier != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15161 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 15162 | return -EINVAL; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15163 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 15164 | |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 15165 | /* |
| 15166 | * There's something wrong with the cursor on CHV pipe C. |
| 15167 | * If it straddles the left edge of the screen then |
| 15168 | * moving it away from the edge or disabling it often |
| 15169 | * results in a pipe underrun, and often that can lead to |
| 15170 | * dead pipe (constant underrun reported, and it scans |
| 15171 | * out just a solid color). To recover from that, the |
| 15172 | * display power well must be turned off and on again. |
| 15173 | * Refuse the put the cursor into that compromised position. |
| 15174 | */ |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15175 | if (IS_CHERRYVIEW(to_i915(plane->dev)) && pipe == PIPE_C && |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 15176 | state->base.visible && state->base.crtc_x < 0) { |
Ville Syrjälä | b29ec92 | 2015-12-18 19:24:39 +0200 | [diff] [blame] | 15177 | DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n"); |
| 15178 | return -EINVAL; |
| 15179 | } |
| 15180 | |
Maarten Lankhorst | da20eab | 2015-06-15 12:33:44 +0200 | [diff] [blame] | 15181 | return 0; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15182 | } |
| 15183 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 15184 | static void |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 15185 | intel_disable_cursor_plane(struct drm_plane *plane, |
Maarten Lankhorst | 7fabf5e | 2015-06-15 12:33:47 +0200 | [diff] [blame] | 15186 | struct drm_crtc *crtc) |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 15187 | { |
Maarten Lankhorst | f285802 | 2016-01-07 11:54:09 +0100 | [diff] [blame] | 15188 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 15189 | |
| 15190 | intel_crtc->cursor_addr = 0; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 15191 | intel_crtc_update_cursor(crtc, NULL); |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 15192 | } |
| 15193 | |
| 15194 | static void |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 15195 | intel_update_cursor_plane(struct drm_plane *plane, |
| 15196 | const struct intel_crtc_state *crtc_state, |
| 15197 | const struct intel_plane_state *state) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15198 | { |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 15199 | struct drm_crtc *crtc = crtc_state->base.crtc; |
| 15200 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15201 | struct drm_i915_private *dev_priv = to_i915(plane->dev); |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 15202 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 15203 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15204 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 15205 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 15206 | addr = 0; |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 15207 | else if (!INTEL_INFO(dev_priv)->cursor_needs_physical) |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 15208 | addr = i915_gem_object_ggtt_offset(obj, NULL); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 15209 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 15210 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 15211 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 15212 | intel_crtc->cursor_addr = addr; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 15213 | intel_crtc_update_cursor(crtc, state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15214 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 15215 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15216 | static struct intel_plane * |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15217 | intel_cursor_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15218 | { |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15219 | struct intel_plane *cursor = NULL; |
| 15220 | struct intel_plane_state *state = NULL; |
| 15221 | int ret; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15222 | |
| 15223 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15224 | if (!cursor) { |
| 15225 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15226 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15227 | } |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15228 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 15229 | state = intel_create_plane_state(&cursor->base); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15230 | if (!state) { |
| 15231 | ret = -ENOMEM; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15232 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15233 | } |
| 15234 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 15235 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15236 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15237 | cursor->can_scale = false; |
| 15238 | cursor->max_downscale = 1; |
| 15239 | cursor->pipe = pipe; |
| 15240 | cursor->plane = pipe; |
Ville Syrjälä | b14e584 | 2016-11-22 18:01:56 +0200 | [diff] [blame] | 15241 | cursor->id = PLANE_CURSOR; |
Ville Syrjälä | a9ff871 | 2015-06-24 21:59:34 +0300 | [diff] [blame] | 15242 | cursor->frontbuffer_bit = INTEL_FRONTBUFFER_CURSOR(pipe); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 15243 | cursor->check_plane = intel_check_cursor_plane; |
Maarten Lankhorst | 55a08b3f | 2016-01-07 11:54:10 +0100 | [diff] [blame] | 15244 | cursor->update_plane = intel_update_cursor_plane; |
Maarten Lankhorst | a8ad0d8 | 2015-04-21 17:12:51 +0300 | [diff] [blame] | 15245 | cursor->disable_plane = intel_disable_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15246 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15247 | ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base, |
| 15248 | 0, &intel_plane_funcs, |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15249 | intel_cursor_formats, |
| 15250 | ARRAY_SIZE(intel_cursor_formats), |
Ville Syrjälä | 38573dc | 2016-05-27 20:59:23 +0300 | [diff] [blame] | 15251 | DRM_PLANE_TYPE_CURSOR, |
| 15252 | "cursor %c", pipe_name(pipe)); |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15253 | if (ret) |
| 15254 | goto fail; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 15255 | |
Dave Airlie | 5481e27 | 2016-10-25 16:36:13 +1000 | [diff] [blame] | 15256 | if (INTEL_GEN(dev_priv) >= 4) |
Ville Syrjälä | 93ca7e0 | 2016-09-26 19:30:56 +0300 | [diff] [blame] | 15257 | drm_plane_create_rotation_property(&cursor->base, |
| 15258 | DRM_ROTATE_0, |
| 15259 | DRM_ROTATE_0 | |
| 15260 | DRM_ROTATE_180); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 15261 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15262 | if (INTEL_GEN(dev_priv) >= 9) |
Chandra Konduru | af99ced | 2015-05-11 14:35:47 -0700 | [diff] [blame] | 15263 | state->scaler_id = -1; |
| 15264 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 15265 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 15266 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15267 | return cursor; |
Ville Syrjälä | fca0ce2 | 2016-03-21 14:43:22 +0000 | [diff] [blame] | 15268 | |
| 15269 | fail: |
| 15270 | kfree(state); |
| 15271 | kfree(cursor); |
| 15272 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15273 | return ERR_PTR(ret); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15274 | } |
| 15275 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 15276 | static void skl_init_scalers(struct drm_i915_private *dev_priv, |
| 15277 | struct intel_crtc *crtc, |
| 15278 | struct intel_crtc_state *crtc_state) |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15279 | { |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 15280 | struct intel_crtc_scaler_state *scaler_state = |
| 15281 | &crtc_state->scaler_state; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15282 | int i; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15283 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 15284 | for (i = 0; i < crtc->num_scalers; i++) { |
| 15285 | struct intel_scaler *scaler = &scaler_state->scalers[i]; |
| 15286 | |
| 15287 | scaler->in_use = 0; |
| 15288 | scaler->mode = PS_SCALER_MODE_DYN; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15289 | } |
| 15290 | |
| 15291 | scaler_state->scaler_id = -1; |
| 15292 | } |
| 15293 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15294 | static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15295 | { |
| 15296 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 15297 | struct intel_crtc_state *crtc_state = NULL; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15298 | struct intel_plane *primary = NULL; |
| 15299 | struct intel_plane *cursor = NULL; |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 15300 | int sprite, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15301 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 15302 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15303 | if (!intel_crtc) |
| 15304 | return -ENOMEM; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15305 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 15306 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15307 | if (!crtc_state) { |
| 15308 | ret = -ENOMEM; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 15309 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15310 | } |
Ander Conselvan de Oliveira | 550acef | 2015-04-21 17:13:24 +0300 | [diff] [blame] | 15311 | intel_crtc->config = crtc_state; |
| 15312 | intel_crtc->base.state = &crtc_state->base; |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 15313 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 15314 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15315 | /* initialize shared scalers */ |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15316 | if (INTEL_GEN(dev_priv) >= 9) { |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15317 | if (pipe == PIPE_C) |
| 15318 | intel_crtc->num_scalers = 1; |
| 15319 | else |
| 15320 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 15321 | |
Ville Syrjälä | 65edccc | 2016-10-31 22:37:01 +0200 | [diff] [blame] | 15322 | skl_init_scalers(dev_priv, intel_crtc, crtc_state); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 15323 | } |
| 15324 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15325 | primary = intel_primary_plane_create(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15326 | if (IS_ERR(primary)) { |
| 15327 | ret = PTR_ERR(primary); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15328 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15329 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 15330 | intel_crtc->plane_ids_mask |= BIT(primary->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15331 | |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 15332 | for_each_sprite(dev_priv, pipe, sprite) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15333 | struct intel_plane *plane; |
| 15334 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15335 | plane = intel_sprite_plane_create(dev_priv, pipe, sprite); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 15336 | if (IS_ERR(plane)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15337 | ret = PTR_ERR(plane); |
| 15338 | goto fail; |
| 15339 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 15340 | intel_crtc->plane_ids_mask |= BIT(plane->id); |
Ville Syrjälä | a81d6fa | 2016-10-25 18:58:01 +0300 | [diff] [blame] | 15341 | } |
| 15342 | |
Ville Syrjälä | 580503c | 2016-10-31 22:37:00 +0200 | [diff] [blame] | 15343 | cursor = intel_cursor_plane_create(dev_priv, pipe); |
Ville Syrjälä | d2b2cbc | 2016-11-07 22:20:56 +0200 | [diff] [blame] | 15344 | if (IS_ERR(cursor)) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15345 | ret = PTR_ERR(cursor); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15346 | goto fail; |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15347 | } |
Ville Syrjälä | d97d7b4 | 2016-11-22 18:01:57 +0200 | [diff] [blame] | 15348 | intel_crtc->plane_ids_mask |= BIT(cursor->id); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15349 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 15350 | ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base, |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15351 | &primary->base, &cursor->base, |
| 15352 | &intel_crtc_funcs, |
Ville Syrjälä | 4d5d72b7 | 2016-05-27 20:59:21 +0300 | [diff] [blame] | 15353 | "pipe %c", pipe_name(pipe)); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15354 | if (ret) |
| 15355 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15356 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 15357 | intel_crtc->pipe = pipe; |
Ville Syrjälä | e3c566d | 2016-11-08 16:47:11 +0200 | [diff] [blame] | 15358 | intel_crtc->plane = primary->plane; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 15359 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 15360 | intel_crtc->cursor_base = ~0; |
| 15361 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 15362 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 15363 | |
Ville Syrjälä | 852eb00 | 2015-06-24 22:00:07 +0300 | [diff] [blame] | 15364 | intel_crtc->wm.cxsr_allowed = true; |
| 15365 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 15366 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 15367 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 15368 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = intel_crtc; |
| 15369 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = intel_crtc; |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 15370 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15371 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 15372 | |
Lionel Landwerlin | 8563b1e | 2016-03-16 10:57:14 +0000 | [diff] [blame] | 15373 | intel_color_init(&intel_crtc->base); |
| 15374 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 15375 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15376 | |
| 15377 | return 0; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15378 | |
| 15379 | fail: |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15380 | /* |
| 15381 | * drm_mode_config_cleanup() will free up any |
| 15382 | * crtcs/planes already initialized. |
| 15383 | */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 15384 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 15385 | kfree(intel_crtc); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 15386 | |
| 15387 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15388 | } |
| 15389 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 15390 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 15391 | { |
| 15392 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 15393 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 15394 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 15395 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 15396 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 15397 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 15398 | return INVALID_PIPE; |
| 15399 | |
| 15400 | return to_intel_crtc(encoder->crtc)->pipe; |
| 15401 | } |
| 15402 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15403 | 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] | 15404 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15405 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15406 | 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] | 15407 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 15408 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15409 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 15410 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Chris Wilson | 71240ed | 2016-06-24 14:00:24 +0100 | [diff] [blame] | 15411 | if (!drmmode_crtc) |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 15412 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15413 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 15414 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 15415 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15416 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 15417 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 15418 | } |
| 15419 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 15420 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15421 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 15422 | struct drm_device *dev = encoder->base.dev; |
| 15423 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15424 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15425 | int entry = 0; |
| 15426 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 15427 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 15428 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 15429 | index_mask |= (1 << entry); |
| 15430 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15431 | entry++; |
| 15432 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 15433 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15434 | return index_mask; |
| 15435 | } |
| 15436 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 15437 | static bool has_edp_a(struct drm_i915_private *dev_priv) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 15438 | { |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 15439 | if (!IS_MOBILE(dev_priv)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 15440 | return false; |
| 15441 | |
| 15442 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 15443 | return false; |
| 15444 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15445 | if (IS_GEN5(dev_priv) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 15446 | return false; |
| 15447 | |
| 15448 | return true; |
| 15449 | } |
| 15450 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15451 | static bool intel_crt_present(struct drm_i915_private *dev_priv) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 15452 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15453 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 15454 | return false; |
| 15455 | |
Tvrtko Ursulin | 50a0bc9 | 2016-10-13 11:02:58 +0100 | [diff] [blame] | 15456 | if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 15457 | return false; |
| 15458 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15459 | if (IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 15460 | return false; |
| 15461 | |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 15462 | if (HAS_PCH_LPT_H(dev_priv) && |
| 15463 | I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED) |
Ville Syrjälä | 65e472e | 2015-12-01 23:28:55 +0200 | [diff] [blame] | 15464 | return false; |
| 15465 | |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 15466 | /* DDI E can't be used if DDI A requires 4 lanes */ |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 15467 | if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) |
Ville Syrjälä | 70ac54d | 2015-12-01 23:29:56 +0200 | [diff] [blame] | 15468 | return false; |
| 15469 | |
Ville Syrjälä | e4abb73 | 2015-12-01 23:31:33 +0200 | [diff] [blame] | 15470 | if (!dev_priv->vbt.int_crt_support) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 15471 | return false; |
| 15472 | |
| 15473 | return true; |
| 15474 | } |
| 15475 | |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 15476 | void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv) |
| 15477 | { |
| 15478 | int pps_num; |
| 15479 | int pps_idx; |
| 15480 | |
| 15481 | if (HAS_DDI(dev_priv)) |
| 15482 | return; |
| 15483 | /* |
| 15484 | * This w/a is needed at least on CPT/PPT, but to be sure apply it |
| 15485 | * everywhere where registers can be write protected. |
| 15486 | */ |
| 15487 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 15488 | pps_num = 2; |
| 15489 | else |
| 15490 | pps_num = 1; |
| 15491 | |
| 15492 | for (pps_idx = 0; pps_idx < pps_num; pps_idx++) { |
| 15493 | u32 val = I915_READ(PP_CONTROL(pps_idx)); |
| 15494 | |
| 15495 | val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS; |
| 15496 | I915_WRITE(PP_CONTROL(pps_idx), val); |
| 15497 | } |
| 15498 | } |
| 15499 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 15500 | static void intel_pps_init(struct drm_i915_private *dev_priv) |
| 15501 | { |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 15502 | if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv)) |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 15503 | dev_priv->pps_mmio_base = PCH_PPS_BASE; |
| 15504 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 15505 | dev_priv->pps_mmio_base = VLV_PPS_BASE; |
| 15506 | else |
| 15507 | dev_priv->pps_mmio_base = PPS_BASE; |
Imre Deak | 8090ba8 | 2016-08-10 14:07:33 +0300 | [diff] [blame] | 15508 | |
| 15509 | intel_pps_unlock_regs_wa(dev_priv); |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 15510 | } |
| 15511 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15512 | static void intel_setup_outputs(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15513 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 15514 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 15515 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15516 | |
Imre Deak | 44cb734 | 2016-08-10 14:07:29 +0300 | [diff] [blame] | 15517 | intel_pps_init(dev_priv); |
| 15518 | |
Imre Deak | 97a824e1 | 2016-06-21 11:51:47 +0300 | [diff] [blame] | 15519 | /* |
| 15520 | * intel_edp_init_connector() depends on this completing first, to |
| 15521 | * prevent the registeration of both eDP and LVDS and the incorrect |
| 15522 | * sharing of the PPS. |
| 15523 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15524 | intel_lvds_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15525 | |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15526 | if (intel_crt_present(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15527 | intel_crt_init(dev_priv); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 15528 | |
Ander Conselvan de Oliveira | cc3f90f | 2016-12-02 10:23:49 +0200 | [diff] [blame] | 15529 | if (IS_GEN9_LP(dev_priv)) { |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame] | 15530 | /* |
| 15531 | * FIXME: Broxton doesn't support port detection via the |
| 15532 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 15533 | * detect the ports. |
| 15534 | */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15535 | intel_ddi_init(dev_priv, PORT_A); |
| 15536 | intel_ddi_init(dev_priv, PORT_B); |
| 15537 | intel_ddi_init(dev_priv, PORT_C); |
Shashank Sharma | c6c794a | 2016-03-22 12:01:50 +0200 | [diff] [blame] | 15538 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15539 | intel_dsi_init(dev_priv); |
Tvrtko Ursulin | 4f8036a | 2016-10-13 11:02:52 +0100 | [diff] [blame] | 15540 | } else if (HAS_DDI(dev_priv)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 15541 | int found; |
| 15542 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 15543 | /* |
| 15544 | * Haswell uses DDI functions to detect digital outputs. |
| 15545 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 15546 | * it's there. |
| 15547 | */ |
Ville Syrjälä | 7717940 | 2015-09-18 20:03:35 +0300 | [diff] [blame] | 15548 | found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 15549 | /* WaIgnoreDDIAStrap: skl */ |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 15550 | if (found || IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15551 | intel_ddi_init(dev_priv, PORT_A); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 15552 | |
| 15553 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 15554 | * register */ |
| 15555 | found = I915_READ(SFUSE_STRAP); |
| 15556 | |
| 15557 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15558 | intel_ddi_init(dev_priv, PORT_B); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 15559 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15560 | intel_ddi_init(dev_priv, PORT_C); |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 15561 | if (found & SFUSE_STRAP_DDID_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15562 | intel_ddi_init(dev_priv, PORT_D); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 15563 | /* |
| 15564 | * On SKL we don't have a way to detect DDI-E so we rely on VBT. |
| 15565 | */ |
Tvrtko Ursulin | 0853723 | 2016-10-13 11:03:02 +0100 | [diff] [blame] | 15566 | if ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) && |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 15567 | (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp || |
| 15568 | dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi || |
| 15569 | dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15570 | intel_ddi_init(dev_priv, PORT_E); |
Rodrigo Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 15571 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 15572 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 15573 | int found; |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 15574 | dpd_is_edp = intel_dp_is_edp(dev_priv, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 15575 | |
Ville Syrjälä | 646d577 | 2016-10-31 22:37:14 +0200 | [diff] [blame] | 15576 | if (has_edp_a(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15577 | intel_dp_init(dev_priv, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 15578 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 15579 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 15580 | /* PCH SDVOB multiplex with HDMIB */ |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15581 | found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 15582 | if (!found) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15583 | intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 15584 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15585 | intel_dp_init(dev_priv, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 15586 | } |
| 15587 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 15588 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15589 | intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 15590 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 15591 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15592 | intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 15593 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 15594 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15595 | intel_dp_init(dev_priv, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 15596 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 15597 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15598 | intel_dp_init(dev_priv, PCH_DP_D, PORT_D); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15599 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15600 | bool has_edp, has_port; |
Chris Wilson | 457c52d | 2016-06-01 08:27:50 +0100 | [diff] [blame] | 15601 | |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 15602 | /* |
| 15603 | * The DP_DETECTED bit is the latched state of the DDC |
| 15604 | * SDA pin at boot. However since eDP doesn't require DDC |
| 15605 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 15606 | * eDP ports may have been muxed to an alternate function. |
| 15607 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 15608 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 15609 | * detect eDP ports. |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15610 | * |
| 15611 | * Sadly the straps seem to be missing sometimes even for HDMI |
| 15612 | * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap |
| 15613 | * and VBT for the presence of the port. Additionally we can't |
| 15614 | * trust the port type the VBT declares as we've seen at least |
| 15615 | * HDMI ports that the VBT claim are DP or eDP. |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 15616 | */ |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 15617 | has_edp = intel_dp_is_edp(dev_priv, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15618 | has_port = intel_bios_is_port_present(dev_priv, PORT_B); |
| 15619 | if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15620 | has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15621 | if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15622 | intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 15623 | |
Tvrtko Ursulin | dd11bc1 | 2016-11-16 08:55:41 +0000 | [diff] [blame] | 15624 | has_edp = intel_dp_is_edp(dev_priv, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15625 | has_port = intel_bios_is_port_present(dev_priv, PORT_C); |
| 15626 | if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15627 | has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15628 | if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15629 | intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 15630 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15631 | if (IS_CHERRYVIEW(dev_priv)) { |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15632 | /* |
| 15633 | * eDP not supported on port D, |
| 15634 | * so no need to worry about it |
| 15635 | */ |
| 15636 | has_port = intel_bios_is_port_present(dev_priv, PORT_D); |
| 15637 | if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15638 | intel_dp_init(dev_priv, CHV_DP_D, PORT_D); |
Ville Syrjälä | 22f35042 | 2016-06-03 12:17:43 +0300 | [diff] [blame] | 15639 | if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15640 | intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 15641 | } |
| 15642 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15643 | intel_dsi_init(dev_priv); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15644 | } else if (!IS_GEN2(dev_priv) && !IS_PINEVIEW(dev_priv)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 15645 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 15646 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 15647 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15648 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15649 | found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B); |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15650 | if (!found && IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15651 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15652 | intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15653 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 15654 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15655 | if (!found && IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15656 | intel_dp_init(dev_priv, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 15657 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 15658 | |
| 15659 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 15660 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 15661 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15662 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15663 | found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15664 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 15665 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 15666 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 15667 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15668 | if (IS_G4X(dev_priv)) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15669 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15670 | intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 15671 | } |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15672 | if (IS_G4X(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15673 | intel_dp_init(dev_priv, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 15674 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 15675 | |
Tvrtko Ursulin | 9beb5fe | 2016-10-13 11:03:06 +0100 | [diff] [blame] | 15676 | if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15677 | intel_dp_init(dev_priv, DP_D, PORT_D); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 15678 | } else if (IS_GEN2(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15679 | intel_dvo_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15680 | |
Tvrtko Ursulin | 56b857a | 2016-11-07 09:29:20 +0000 | [diff] [blame] | 15681 | if (SUPPORTS_TV(dev_priv)) |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15682 | intel_tv_init(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15683 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15684 | intel_psr_init(dev_priv); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 15685 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15686 | for_each_intel_encoder(&dev_priv->drm, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 15687 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 15688 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 15689 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15690 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 15691 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15692 | intel_init_pch_refclk(dev_priv); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 15693 | |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 15694 | drm_helper_move_panel_connectors_to_head(&dev_priv->drm); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15695 | } |
| 15696 | |
| 15697 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 15698 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 15699 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15700 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15701 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 15702 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 15703 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 15704 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 15705 | i915_gem_object_put(intel_fb->obj); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 15706 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15707 | kfree(intel_fb); |
| 15708 | } |
| 15709 | |
| 15710 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 15711 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15712 | unsigned int *handle) |
| 15713 | { |
| 15714 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 15715 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15716 | |
Chris Wilson | cc917ab | 2015-10-13 14:22:26 +0100 | [diff] [blame] | 15717 | if (obj->userptr.mm) { |
| 15718 | DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n"); |
| 15719 | return -EINVAL; |
| 15720 | } |
| 15721 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 15722 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15723 | } |
| 15724 | |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 15725 | static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb, |
| 15726 | struct drm_file *file, |
| 15727 | unsigned flags, unsigned color, |
| 15728 | struct drm_clip_rect *clips, |
| 15729 | unsigned num_clips) |
| 15730 | { |
| 15731 | struct drm_device *dev = fb->dev; |
| 15732 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 15733 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 15734 | |
| 15735 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | a6a7cc4 | 2016-11-18 21:17:46 +0000 | [diff] [blame] | 15736 | if (obj->pin_display && obj->cache_dirty) |
| 15737 | i915_gem_clflush_object(obj, true); |
Paulo Zanoni | 74b4ea1 | 2015-07-14 16:29:14 -0300 | [diff] [blame] | 15738 | intel_fb_obj_flush(obj, false, ORIGIN_DIRTYFB); |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 15739 | mutex_unlock(&dev->struct_mutex); |
| 15740 | |
| 15741 | return 0; |
| 15742 | } |
| 15743 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15744 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 15745 | .destroy = intel_user_framebuffer_destroy, |
| 15746 | .create_handle = intel_user_framebuffer_create_handle, |
Rodrigo Vivi | 86c9858 | 2015-07-08 16:22:45 -0700 | [diff] [blame] | 15747 | .dirty = intel_user_framebuffer_dirty, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15748 | }; |
| 15749 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15750 | static |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15751 | u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv, |
| 15752 | uint64_t fb_modifier, uint32_t pixel_format) |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15753 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15754 | u32 gen = INTEL_INFO(dev_priv)->gen; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15755 | |
| 15756 | if (gen >= 9) { |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 15757 | int cpp = drm_format_plane_cpp(pixel_format, 0); |
| 15758 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15759 | /* "The stride in bytes must not exceed the of the size of 8K |
| 15760 | * pixels and 32K bytes." |
| 15761 | */ |
Ville Syrjälä | ac48496 | 2016-01-20 21:05:26 +0200 | [diff] [blame] | 15762 | return min(8192 * cpp, 32768); |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15763 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev_priv) && |
| 15764 | !IS_CHERRYVIEW(dev_priv)) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15765 | return 32*1024; |
| 15766 | } else if (gen >= 4) { |
| 15767 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 15768 | return 16*1024; |
| 15769 | else |
| 15770 | return 32*1024; |
| 15771 | } else if (gen >= 3) { |
| 15772 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 15773 | return 8*1024; |
| 15774 | else |
| 15775 | return 16*1024; |
| 15776 | } else { |
| 15777 | /* XXX DSPC is limited to 4k tiled */ |
| 15778 | return 8*1024; |
| 15779 | } |
| 15780 | } |
| 15781 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 15782 | static int intel_framebuffer_init(struct drm_device *dev, |
| 15783 | struct intel_framebuffer *intel_fb, |
| 15784 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 15785 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15786 | { |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 15787 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15788 | unsigned int tiling = i915_gem_object_get_tiling(obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15789 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15790 | u32 pitch_limit, stride_alignment; |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15791 | struct drm_format_name_buf format_name; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15792 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 15793 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 15794 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 15795 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15796 | /* |
| 15797 | * If there's a fence, enforce that |
| 15798 | * the fb modifier and tiling mode match. |
| 15799 | */ |
| 15800 | if (tiling != I915_TILING_NONE && |
| 15801 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 15802 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 15803 | return -EINVAL; |
| 15804 | } |
| 15805 | } else { |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15806 | if (tiling == I915_TILING_X) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 15807 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15808 | } else if (tiling == I915_TILING_Y) { |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 15809 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 15810 | return -EINVAL; |
| 15811 | } |
| 15812 | } |
| 15813 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 15814 | /* Passed in modifier sanity checking. */ |
| 15815 | switch (mode_cmd->modifier[0]) { |
| 15816 | case I915_FORMAT_MOD_Y_TILED: |
| 15817 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15818 | if (INTEL_GEN(dev_priv) < 9) { |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 15819 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 15820 | mode_cmd->modifier[0]); |
| 15821 | return -EINVAL; |
| 15822 | } |
| 15823 | case DRM_FORMAT_MOD_NONE: |
| 15824 | case I915_FORMAT_MOD_X_TILED: |
| 15825 | break; |
| 15826 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 15827 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 15828 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15829 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15830 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15831 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15832 | /* |
| 15833 | * gen2/3 display engine uses the fence if present, |
| 15834 | * so the tiling mode must match the fb modifier exactly. |
| 15835 | */ |
| 15836 | if (INTEL_INFO(dev_priv)->gen < 4 && |
| 15837 | tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) { |
| 15838 | DRM_DEBUG("tiling_mode must match fb modifier exactly on gen2/3\n"); |
| 15839 | return -EINVAL; |
| 15840 | } |
| 15841 | |
Ville Syrjälä | 7b49f94 | 2016-01-12 21:08:32 +0200 | [diff] [blame] | 15842 | stride_alignment = intel_fb_stride_alignment(dev_priv, |
| 15843 | mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15844 | mode_cmd->pixel_format); |
| 15845 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 15846 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 15847 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15848 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15849 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15850 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15851 | pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->modifier[0], |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15852 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 15853 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 15854 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 15855 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 15856 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 15857 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 15858 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15859 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 15860 | |
Ville Syrjälä | c2ff737 | 2016-02-11 19:16:37 +0200 | [diff] [blame] | 15861 | /* |
| 15862 | * If there's a fence, enforce that |
| 15863 | * the fb pitch and fence stride match. |
| 15864 | */ |
| 15865 | if (tiling != I915_TILING_NONE && |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 15866 | mode_cmd->pitches[0] != i915_gem_object_get_stride(obj)) { |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15867 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 15868 | mode_cmd->pitches[0], |
| 15869 | i915_gem_object_get_stride(obj)); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 15870 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15871 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 15872 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15873 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 15874 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15875 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 15876 | case DRM_FORMAT_RGB565: |
| 15877 | case DRM_FORMAT_XRGB8888: |
| 15878 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15879 | break; |
| 15880 | case DRM_FORMAT_XRGB1555: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15881 | if (INTEL_GEN(dev_priv) > 3) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15882 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15883 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15884 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15885 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15886 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15887 | case DRM_FORMAT_ABGR8888: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15888 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) && |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15889 | INTEL_GEN(dev_priv) < 9) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15890 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15891 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Damien Lespiau | 6c0fd45 | 2015-05-19 12:29:16 +0100 | [diff] [blame] | 15892 | return -EINVAL; |
| 15893 | } |
| 15894 | break; |
| 15895 | case DRM_FORMAT_XBGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 15896 | case DRM_FORMAT_XRGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15897 | case DRM_FORMAT_XBGR2101010: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15898 | if (INTEL_GEN(dev_priv) < 4) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15899 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15900 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15901 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15902 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 15903 | break; |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 15904 | case DRM_FORMAT_ABGR2101010: |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 15905 | if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15906 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15907 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Damien Lespiau | 7531208 | 2015-05-15 19:06:01 +0100 | [diff] [blame] | 15908 | return -EINVAL; |
| 15909 | } |
| 15910 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 15911 | case DRM_FORMAT_YUYV: |
| 15912 | case DRM_FORMAT_UYVY: |
| 15913 | case DRM_FORMAT_YVYU: |
| 15914 | case DRM_FORMAT_VYUY: |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 15915 | if (INTEL_GEN(dev_priv) < 5) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15916 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15917 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 15918 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 15919 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15920 | break; |
| 15921 | default: |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 15922 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 15923 | drm_get_format_name(mode_cmd->pixel_format, &format_name)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 15924 | return -EINVAL; |
| 15925 | } |
| 15926 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 15927 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 15928 | if (mode_cmd->offsets[0] != 0) |
| 15929 | return -EINVAL; |
| 15930 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 15931 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 15932 | intel_fb->obj = obj; |
| 15933 | |
Ville Syrjälä | 6687c90 | 2015-09-15 13:16:41 +0300 | [diff] [blame] | 15934 | ret = intel_fill_fb_info(dev_priv, &intel_fb->base); |
| 15935 | if (ret) |
| 15936 | return ret; |
Ville Syrjälä | 2d7a215 | 2016-02-15 22:54:47 +0200 | [diff] [blame] | 15937 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15938 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 15939 | if (ret) { |
| 15940 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 15941 | return ret; |
| 15942 | } |
| 15943 | |
Ville Syrjälä | 0b05e1e | 2016-01-14 15:22:09 +0200 | [diff] [blame] | 15944 | intel_fb->obj->framebuffer_references++; |
| 15945 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15946 | return 0; |
| 15947 | } |
| 15948 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15949 | static struct drm_framebuffer * |
| 15950 | intel_user_framebuffer_create(struct drm_device *dev, |
| 15951 | struct drm_file *filp, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 15952 | const struct drm_mode_fb_cmd2 *user_mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15953 | { |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 15954 | struct drm_framebuffer *fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 15955 | struct drm_i915_gem_object *obj; |
Ville Syrjälä | 76dc376 | 2015-11-11 19:11:28 +0200 | [diff] [blame] | 15956 | struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15957 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 15958 | obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]); |
| 15959 | if (!obj) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 15960 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15961 | |
Daniel Vetter | 92907cb | 2015-11-23 09:04:05 +0100 | [diff] [blame] | 15962 | fb = intel_framebuffer_create(dev, &mode_cmd, obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 15963 | if (IS_ERR(fb)) |
Chris Wilson | f0cd518 | 2016-10-28 13:58:43 +0100 | [diff] [blame] | 15964 | i915_gem_object_put(obj); |
Lukas Wunner | dcb1394 | 2015-07-04 11:50:58 +0200 | [diff] [blame] | 15965 | |
| 15966 | return fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15967 | } |
| 15968 | |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 15969 | static void intel_atomic_state_free(struct drm_atomic_state *state) |
| 15970 | { |
| 15971 | struct intel_atomic_state *intel_state = to_intel_atomic_state(state); |
| 15972 | |
| 15973 | drm_atomic_state_default_release(state); |
| 15974 | |
| 15975 | i915_sw_fence_fini(&intel_state->commit_ready); |
| 15976 | |
| 15977 | kfree(state); |
| 15978 | } |
| 15979 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15980 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15981 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 15982 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 15983 | .atomic_check = intel_atomic_check, |
| 15984 | .atomic_commit = intel_atomic_commit, |
Maarten Lankhorst | de419ab | 2015-06-04 10:21:28 +0200 | [diff] [blame] | 15985 | .atomic_state_alloc = intel_atomic_state_alloc, |
| 15986 | .atomic_state_clear = intel_atomic_state_clear, |
Chris Wilson | 778e23a | 2016-12-05 14:29:39 +0000 | [diff] [blame] | 15987 | .atomic_state_free = intel_atomic_state_free, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 15988 | }; |
| 15989 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15990 | /** |
| 15991 | * intel_init_display_hooks - initialize the display modesetting hooks |
| 15992 | * @dev_priv: device private |
| 15993 | */ |
| 15994 | void intel_init_display_hooks(struct drm_i915_private *dev_priv) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 15995 | { |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 15996 | if (INTEL_INFO(dev_priv)->gen >= 9) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 15997 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 15998 | dev_priv->display.get_initial_plane_config = |
| 15999 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 16000 | dev_priv->display.crtc_compute_clock = |
| 16001 | haswell_crtc_compute_clock; |
| 16002 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 16003 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16004 | } else if (HAS_DDI(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 16005 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 16006 | dev_priv->display.get_initial_plane_config = |
| 16007 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 16008 | dev_priv->display.crtc_compute_clock = |
| 16009 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 16010 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 16011 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16012 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 16013 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 16014 | dev_priv->display.get_initial_plane_config = |
| 16015 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 16016 | dev_priv->display.crtc_compute_clock = |
| 16017 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 16018 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 16019 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 16020 | } else if (IS_CHERRYVIEW(dev_priv)) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 16021 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 16022 | dev_priv->display.get_initial_plane_config = |
| 16023 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | 65b3d6a | 2016-03-21 18:00:13 +0200 | [diff] [blame] | 16024 | dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock; |
| 16025 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 16026 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 16027 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 16028 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 16029 | dev_priv->display.get_initial_plane_config = |
| 16030 | i9xx_get_initial_plane_config; |
| 16031 | dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 16032 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 16033 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 19ec669 | 2016-03-21 18:00:15 +0200 | [diff] [blame] | 16034 | } else if (IS_G4X(dev_priv)) { |
| 16035 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 16036 | dev_priv->display.get_initial_plane_config = |
| 16037 | i9xx_get_initial_plane_config; |
| 16038 | dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock; |
| 16039 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 16040 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 70e8aa2 | 2016-03-21 18:00:16 +0200 | [diff] [blame] | 16041 | } else if (IS_PINEVIEW(dev_priv)) { |
| 16042 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 16043 | dev_priv->display.get_initial_plane_config = |
| 16044 | i9xx_get_initial_plane_config; |
| 16045 | dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock; |
| 16046 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 16047 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 16048 | } else if (!IS_GEN2(dev_priv)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 16049 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 16050 | dev_priv->display.get_initial_plane_config = |
| 16051 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 16052 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 16053 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 16054 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Ander Conselvan de Oliveira | 81c97f5 | 2016-03-22 15:35:23 +0200 | [diff] [blame] | 16055 | } else { |
| 16056 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
| 16057 | dev_priv->display.get_initial_plane_config = |
| 16058 | i9xx_get_initial_plane_config; |
| 16059 | dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock; |
| 16060 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 16061 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 16062 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16063 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16064 | /* Returns the core display clock speed */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16065 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 16066 | dev_priv->display.get_display_clock_speed = |
| 16067 | skylake_get_display_clock_speed; |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 16068 | else if (IS_GEN9_LP(dev_priv)) |
Bob Paauwe | acd3f3d | 2015-06-23 14:14:26 -0700 | [diff] [blame] | 16069 | dev_priv->display.get_display_clock_speed = |
| 16070 | broxton_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16071 | else if (IS_BROADWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 16072 | dev_priv->display.get_display_clock_speed = |
| 16073 | broadwell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16074 | else if (IS_HASWELL(dev_priv)) |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 16075 | dev_priv->display.get_display_clock_speed = |
| 16076 | haswell_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16077 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 16078 | dev_priv->display.get_display_clock_speed = |
| 16079 | valleyview_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16080 | else if (IS_GEN5(dev_priv)) |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 16081 | dev_priv->display.get_display_clock_speed = |
| 16082 | ilk_get_display_clock_speed; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 16083 | else if (IS_I945G(dev_priv) || IS_I965G(dev_priv) || |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16084 | IS_GEN6(dev_priv) || IS_IVYBRIDGE(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16085 | dev_priv->display.get_display_clock_speed = |
| 16086 | i945_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16087 | else if (IS_GM45(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 16088 | dev_priv->display.get_display_clock_speed = |
| 16089 | gm45_get_display_clock_speed; |
Jani Nikula | c0f8683 | 2016-12-07 12:13:04 +0200 | [diff] [blame] | 16090 | else if (IS_I965GM(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 16091 | dev_priv->display.get_display_clock_speed = |
| 16092 | i965gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16093 | else if (IS_PINEVIEW(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 16094 | dev_priv->display.get_display_clock_speed = |
| 16095 | pnv_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16096 | else if (IS_G33(dev_priv) || IS_G4X(dev_priv)) |
Ville Syrjälä | 34edce2 | 2015-05-22 11:22:33 +0300 | [diff] [blame] | 16097 | dev_priv->display.get_display_clock_speed = |
| 16098 | g33_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16099 | else if (IS_I915G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16100 | dev_priv->display.get_display_clock_speed = |
| 16101 | i915_get_display_clock_speed; |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 16102 | else if (IS_I945GM(dev_priv) || IS_I845G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16103 | dev_priv->display.get_display_clock_speed = |
| 16104 | i9xx_misc_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16105 | else if (IS_I915GM(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16106 | dev_priv->display.get_display_clock_speed = |
| 16107 | i915gm_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16108 | else if (IS_I865G(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16109 | dev_priv->display.get_display_clock_speed = |
| 16110 | i865_get_display_clock_speed; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16111 | else if (IS_I85X(dev_priv)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16112 | dev_priv->display.get_display_clock_speed = |
Ville Syrjälä | 1b1d271 | 2015-05-22 11:22:31 +0300 | [diff] [blame] | 16113 | i85x_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 16114 | else { /* 830 */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16115 | WARN(!IS_I830(dev_priv), "Unknown platform. Assuming 133 MHz CDCLK\n"); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16116 | dev_priv->display.get_display_clock_speed = |
| 16117 | i830_get_display_clock_speed; |
Ville Syrjälä | 623e01e | 2015-05-22 11:22:34 +0300 | [diff] [blame] | 16118 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16119 | |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16120 | if (IS_GEN5(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 16121 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16122 | } else if (IS_GEN6(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 16123 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16124 | } else if (IS_IVYBRIDGE(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 16125 | /* FIXME: detect B0+ stepping and use auto training */ |
| 16126 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16127 | } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 16128 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Ville Syrjälä | 445e780 | 2016-05-11 22:44:42 +0300 | [diff] [blame] | 16129 | } |
| 16130 | |
| 16131 | if (IS_BROADWELL(dev_priv)) { |
| 16132 | dev_priv->display.modeset_commit_cdclk = |
| 16133 | broadwell_modeset_commit_cdclk; |
| 16134 | dev_priv->display.modeset_calc_cdclk = |
| 16135 | broadwell_modeset_calc_cdclk; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 16136 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 16137 | dev_priv->display.modeset_commit_cdclk = |
| 16138 | valleyview_modeset_commit_cdclk; |
| 16139 | dev_priv->display.modeset_calc_cdclk = |
| 16140 | valleyview_modeset_calc_cdclk; |
Ander Conselvan de Oliveira | 89b3c3c | 2016-12-02 10:23:54 +0200 | [diff] [blame] | 16141 | } else if (IS_GEN9_LP(dev_priv)) { |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 16142 | dev_priv->display.modeset_commit_cdclk = |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 16143 | bxt_modeset_commit_cdclk; |
Maarten Lankhorst | 27c329e | 2015-06-15 12:33:56 +0200 | [diff] [blame] | 16144 | dev_priv->display.modeset_calc_cdclk = |
Imre Deak | 324513c | 2016-06-13 16:44:36 +0300 | [diff] [blame] | 16145 | bxt_modeset_calc_cdclk; |
Clint Taylor | c89e39f | 2016-05-13 23:41:21 +0300 | [diff] [blame] | 16146 | } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) { |
| 16147 | dev_priv->display.modeset_commit_cdclk = |
| 16148 | skl_modeset_commit_cdclk; |
| 16149 | dev_priv->display.modeset_calc_cdclk = |
| 16150 | skl_modeset_calc_cdclk; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16151 | } |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 16152 | |
Lyude | 2708249 | 2016-08-24 07:48:10 +0200 | [diff] [blame] | 16153 | if (dev_priv->info.gen >= 9) |
| 16154 | dev_priv->display.update_crtcs = skl_update_crtcs; |
| 16155 | else |
| 16156 | dev_priv->display.update_crtcs = intel_update_crtcs; |
| 16157 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 16158 | switch (INTEL_INFO(dev_priv)->gen) { |
| 16159 | case 2: |
| 16160 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 16161 | break; |
| 16162 | |
| 16163 | case 3: |
| 16164 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 16165 | break; |
| 16166 | |
| 16167 | case 4: |
| 16168 | case 5: |
| 16169 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 16170 | break; |
| 16171 | |
| 16172 | case 6: |
| 16173 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 16174 | break; |
| 16175 | case 7: |
| 16176 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
| 16177 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 16178 | break; |
| 16179 | case 9: |
| 16180 | /* Drop through - unsupported since execlist only. */ |
| 16181 | default: |
| 16182 | /* Default just returns -ENODEV to indicate unsupported */ |
| 16183 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 16184 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 16185 | } |
| 16186 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16187 | /* |
| 16188 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 16189 | * resume, or other times. This quirk makes sure that's the case for |
| 16190 | * affected systems. |
| 16191 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 16192 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16193 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16194 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16195 | |
| 16196 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 16197 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16198 | } |
| 16199 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 16200 | static void quirk_pipeb_force(struct drm_device *dev) |
| 16201 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16202 | struct drm_i915_private *dev_priv = to_i915(dev); |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 16203 | |
| 16204 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 16205 | DRM_INFO("applying pipe b force quirk\n"); |
| 16206 | } |
| 16207 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 16208 | /* |
| 16209 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 16210 | */ |
| 16211 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 16212 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16213 | struct drm_i915_private *dev_priv = to_i915(dev); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 16214 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 16215 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 16216 | } |
| 16217 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 16218 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 16219 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 16220 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 16221 | */ |
| 16222 | static void quirk_invert_brightness(struct drm_device *dev) |
| 16223 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16224 | struct drm_i915_private *dev_priv = to_i915(dev); |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 16225 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 16226 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16227 | } |
| 16228 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 16229 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 16230 | static void quirk_backlight_present(struct drm_device *dev) |
| 16231 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16232 | struct drm_i915_private *dev_priv = to_i915(dev); |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 16233 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 16234 | DRM_INFO("applying backlight present quirk\n"); |
| 16235 | } |
| 16236 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16237 | struct intel_quirk { |
| 16238 | int device; |
| 16239 | int subsystem_vendor; |
| 16240 | int subsystem_device; |
| 16241 | void (*hook)(struct drm_device *dev); |
| 16242 | }; |
| 16243 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 16244 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 16245 | struct intel_dmi_quirk { |
| 16246 | void (*hook)(struct drm_device *dev); |
| 16247 | const struct dmi_system_id (*dmi_id_list)[]; |
| 16248 | }; |
| 16249 | |
| 16250 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 16251 | { |
| 16252 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 16253 | return 1; |
| 16254 | } |
| 16255 | |
| 16256 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 16257 | { |
| 16258 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 16259 | { |
| 16260 | .callback = intel_dmi_reverse_brightness, |
| 16261 | .ident = "NCR Corporation", |
| 16262 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 16263 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 16264 | }, |
| 16265 | }, |
| 16266 | { } /* terminating entry */ |
| 16267 | }, |
| 16268 | .hook = quirk_invert_brightness, |
| 16269 | }, |
| 16270 | }; |
| 16271 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 16272 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16273 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 16274 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 16275 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16276 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 16277 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 16278 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 16279 | /* 830 needs to leave pipe A & dpll A up */ |
| 16280 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 16281 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 16282 | /* 830 needs to leave pipe B & dpll B up */ |
| 16283 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 16284 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 16285 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 16286 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 16287 | |
| 16288 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 16289 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 16290 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 16291 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 16292 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 16293 | |
| 16294 | /* Acer/eMachines G725 */ |
| 16295 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 16296 | |
| 16297 | /* Acer/eMachines e725 */ |
| 16298 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 16299 | |
| 16300 | /* Acer/Packard Bell NCL20 */ |
| 16301 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 16302 | |
| 16303 | /* Acer Aspire 4736Z */ |
| 16304 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 16305 | |
| 16306 | /* Acer Aspire 5336 */ |
| 16307 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 16308 | |
| 16309 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 16310 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 16311 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 16312 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 16313 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 16314 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 16315 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 16316 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 16317 | |
Jani Nikula | 1b9448b0 | 2015-11-05 11:49:59 +0200 | [diff] [blame] | 16318 | /* Apple Macbook 4,1 */ |
| 16319 | { 0x2a02, 0x106b, 0x00a1, quirk_backlight_present }, |
| 16320 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 16321 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 16322 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 16323 | |
| 16324 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 16325 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 16326 | |
| 16327 | /* Dell Chromebook 11 */ |
| 16328 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jani Nikula | 9be64ee | 2015-10-30 14:50:24 +0200 | [diff] [blame] | 16329 | |
| 16330 | /* Dell Chromebook 11 (2015 version) */ |
| 16331 | { 0x0a16, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16332 | }; |
| 16333 | |
| 16334 | static void intel_init_quirks(struct drm_device *dev) |
| 16335 | { |
| 16336 | struct pci_dev *d = dev->pdev; |
| 16337 | int i; |
| 16338 | |
| 16339 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 16340 | struct intel_quirk *q = &intel_quirks[i]; |
| 16341 | |
| 16342 | if (d->device == q->device && |
| 16343 | (d->subsystem_vendor == q->subsystem_vendor || |
| 16344 | q->subsystem_vendor == PCI_ANY_ID) && |
| 16345 | (d->subsystem_device == q->subsystem_device || |
| 16346 | q->subsystem_device == PCI_ANY_ID)) |
| 16347 | q->hook(dev); |
| 16348 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 16349 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 16350 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 16351 | intel_dmi_quirks[i].hook(dev); |
| 16352 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16353 | } |
| 16354 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16355 | /* Disable the VGA plane that we never use */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16356 | static void i915_disable_vga(struct drm_i915_private *dev_priv) |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16357 | { |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 16358 | struct pci_dev *pdev = dev_priv->drm.pdev; |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16359 | u8 sr1; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 16360 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16361 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 16362 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 16363 | vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 16364 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16365 | sr1 = inb(VGA_SR_DATA); |
| 16366 | outb(sr1 | 1<<5, VGA_SR_DATA); |
David Weinehall | 52a05c3 | 2016-08-22 13:32:44 +0300 | [diff] [blame] | 16367 | vga_put(pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16368 | udelay(300); |
| 16369 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 16370 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16371 | POSTING_READ(vga_reg); |
| 16372 | } |
| 16373 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 16374 | void intel_modeset_init_hw(struct drm_device *dev) |
| 16375 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16376 | struct drm_i915_private *dev_priv = to_i915(dev); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 16377 | |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 16378 | intel_update_cdclk(dev_priv); |
Maarten Lankhorst | 1a617b7 | 2015-12-03 14:31:06 +0100 | [diff] [blame] | 16379 | |
| 16380 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; |
| 16381 | |
Ville Syrjälä | 46f16e6 | 2016-10-31 22:37:22 +0200 | [diff] [blame] | 16382 | intel_init_clock_gating(dev_priv); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 16383 | } |
| 16384 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16385 | /* |
| 16386 | * Calculate what we think the watermarks should be for the state we've read |
| 16387 | * out of the hardware and then immediately program those watermarks so that |
| 16388 | * we ensure the hardware settings match our internal state. |
| 16389 | * |
| 16390 | * We can calculate what we think WM's should be by creating a duplicate of the |
| 16391 | * current state (which was constructed during hardware readout) and running it |
| 16392 | * through the atomic check code to calculate new watermark values in the |
| 16393 | * state object. |
| 16394 | */ |
| 16395 | static void sanitize_watermarks(struct drm_device *dev) |
| 16396 | { |
| 16397 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 16398 | struct drm_atomic_state *state; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 16399 | struct intel_atomic_state *intel_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16400 | struct drm_crtc *crtc; |
| 16401 | struct drm_crtc_state *cstate; |
| 16402 | struct drm_modeset_acquire_ctx ctx; |
| 16403 | int ret; |
| 16404 | int i; |
| 16405 | |
| 16406 | /* Only supported on platforms that use atomic watermark design */ |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 16407 | if (!dev_priv->display.optimize_watermarks) |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16408 | return; |
| 16409 | |
| 16410 | /* |
| 16411 | * We need to hold connection_mutex before calling duplicate_state so |
| 16412 | * that the connector loop is protected. |
| 16413 | */ |
| 16414 | drm_modeset_acquire_init(&ctx, 0); |
| 16415 | retry: |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 16416 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16417 | if (ret == -EDEADLK) { |
| 16418 | drm_modeset_backoff(&ctx); |
| 16419 | goto retry; |
| 16420 | } else if (WARN_ON(ret)) { |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 16421 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16422 | } |
| 16423 | |
| 16424 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 16425 | if (WARN_ON(IS_ERR(state))) |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 16426 | goto fail; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16427 | |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 16428 | intel_state = to_intel_atomic_state(state); |
| 16429 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 16430 | /* |
| 16431 | * Hardware readout is the only time we don't want to calculate |
| 16432 | * intermediate watermarks (since we don't trust the current |
| 16433 | * watermarks). |
| 16434 | */ |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 16435 | intel_state->skip_intermediate_wm = true; |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 16436 | |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16437 | ret = intel_atomic_check(dev, state); |
| 16438 | if (ret) { |
| 16439 | /* |
| 16440 | * If we fail here, it means that the hardware appears to be |
| 16441 | * programmed in a way that shouldn't be possible, given our |
| 16442 | * understanding of watermark requirements. This might mean a |
| 16443 | * mistake in the hardware readout code or a mistake in the |
| 16444 | * watermark calculations for a given platform. Raise a WARN |
| 16445 | * so that this is noticeable. |
| 16446 | * |
| 16447 | * If this actually happens, we'll have to just leave the |
| 16448 | * BIOS-programmed watermarks untouched and hope for the best. |
| 16449 | */ |
| 16450 | WARN(true, "Could not determine valid watermarks for inherited state\n"); |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 16451 | goto put_state; |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16452 | } |
| 16453 | |
| 16454 | /* Write calculated watermark values back */ |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16455 | for_each_crtc_in_state(state, crtc, cstate, i) { |
| 16456 | struct intel_crtc_state *cs = to_intel_crtc_state(cstate); |
| 16457 | |
Matt Roper | ed4a6a7 | 2016-02-23 17:20:13 -0800 | [diff] [blame] | 16458 | cs->wm.need_postvbl_update = true; |
Maarten Lankhorst | ccf010f | 2016-11-08 13:55:32 +0100 | [diff] [blame] | 16459 | dev_priv->display.optimize_watermarks(intel_state, cs); |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16460 | } |
| 16461 | |
Arnd Bergmann | b9a1b71 | 2016-10-18 17:16:23 +0200 | [diff] [blame] | 16462 | put_state: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 16463 | drm_atomic_state_put(state); |
Matt Roper | 0cd1262 | 2016-01-12 07:13:37 -0800 | [diff] [blame] | 16464 | fail: |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16465 | drm_modeset_drop_locks(&ctx); |
| 16466 | drm_modeset_acquire_fini(&ctx); |
| 16467 | } |
| 16468 | |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 16469 | int intel_modeset_init(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16470 | { |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 16471 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 16472 | struct i915_ggtt *ggtt = &dev_priv->ggtt; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 16473 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16474 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16475 | |
| 16476 | drm_mode_config_init(dev); |
| 16477 | |
| 16478 | dev->mode_config.min_width = 0; |
| 16479 | dev->mode_config.min_height = 0; |
| 16480 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 16481 | dev->mode_config.preferred_depth = 24; |
| 16482 | dev->mode_config.prefer_shadow = 1; |
| 16483 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 16484 | dev->mode_config.allow_fb_modifiers = true; |
| 16485 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 16486 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16487 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 16488 | intel_init_quirks(dev); |
| 16489 | |
Ville Syrjälä | 62d75df | 2016-10-31 22:37:25 +0200 | [diff] [blame] | 16490 | intel_init_pm(dev_priv); |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 16491 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16492 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 16493 | return 0; |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 16494 | |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 16495 | /* |
| 16496 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 16497 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 16498 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 16499 | * indicates as much. |
| 16500 | */ |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 16501 | if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) { |
Lukas Wunner | 69f92f6 | 2015-07-15 13:57:35 +0200 | [diff] [blame] | 16502 | bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 16503 | DREF_SSC1_ENABLE); |
| 16504 | |
| 16505 | if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) { |
| 16506 | DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n", |
| 16507 | bios_lvds_use_ssc ? "en" : "dis", |
| 16508 | dev_priv->vbt.lvds_use_ssc ? "en" : "dis"); |
| 16509 | dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc; |
| 16510 | } |
| 16511 | } |
| 16512 | |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 16513 | if (IS_GEN2(dev_priv)) { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 16514 | dev->mode_config.max_width = 2048; |
| 16515 | dev->mode_config.max_height = 2048; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 16516 | } else if (IS_GEN3(dev_priv)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 16517 | dev->mode_config.max_width = 4096; |
| 16518 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16519 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 16520 | dev->mode_config.max_width = 8192; |
| 16521 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16522 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 16523 | |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 16524 | if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) { |
| 16525 | dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 16526 | dev->mode_config.cursor_height = 1023; |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 16527 | } else if (IS_GEN2(dev_priv)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 16528 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 16529 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 16530 | } else { |
| 16531 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 16532 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 16533 | } |
| 16534 | |
Joonas Lahtinen | 72e96d6 | 2016-03-30 16:57:10 +0300 | [diff] [blame] | 16535 | dev->mode_config.fb_base = ggtt->mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16536 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 16537 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16538 | INTEL_INFO(dev_priv)->num_pipes, |
| 16539 | INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16540 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 16541 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 16542 | int ret; |
| 16543 | |
Ville Syrjälä | 5ab0d85 | 2016-10-31 22:37:11 +0200 | [diff] [blame] | 16544 | ret = intel_crtc_init(dev_priv, pipe); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 16545 | if (ret) { |
| 16546 | drm_mode_config_cleanup(dev); |
| 16547 | return ret; |
| 16548 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 16549 | } |
| 16550 | |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 16551 | intel_update_czclk(dev_priv); |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 16552 | intel_update_cdclk(dev_priv); |
Ville Syrjälä | 6a259b1 | 2016-11-29 16:13:57 +0200 | [diff] [blame] | 16553 | dev_priv->atomic_cdclk_freq = dev_priv->cdclk_freq; |
Ville Syrjälä | bfa7df0 | 2015-09-24 23:29:18 +0300 | [diff] [blame] | 16554 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 16555 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 16556 | |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 16557 | if (dev_priv->max_cdclk_freq == 0) |
Ville Syrjälä | 4c75b94 | 2016-10-31 22:37:12 +0200 | [diff] [blame] | 16558 | intel_update_max_cdclk(dev_priv); |
Ville Syrjälä | b204535 | 2016-05-13 23:41:27 +0300 | [diff] [blame] | 16559 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 16560 | /* Just disable it once at startup */ |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16561 | i915_disable_vga(dev_priv); |
Ander Conselvan de Oliveira | c39055b | 2016-11-23 16:21:44 +0200 | [diff] [blame] | 16562 | intel_setup_outputs(dev_priv); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 16563 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 16564 | drm_modeset_lock_all(dev); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 16565 | intel_modeset_setup_hw_state(dev); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 16566 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16567 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 16568 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 16569 | struct intel_initial_plane_config plane_config = {}; |
| 16570 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16571 | if (!crtc->active) |
| 16572 | continue; |
| 16573 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16574 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16575 | * Note that reserving the BIOS fb up front prevents us |
| 16576 | * from stuffing other stolen allocations like the ring |
| 16577 | * on top. This prevents some ugliness at boot time, and |
| 16578 | * can even allow for smooth boot transitions if the BIOS |
| 16579 | * fb is large enough for the active pipe configuration. |
| 16580 | */ |
Maarten Lankhorst | eeebeac | 2015-07-14 12:33:29 +0200 | [diff] [blame] | 16581 | dev_priv->display.get_initial_plane_config(crtc, |
| 16582 | &plane_config); |
| 16583 | |
| 16584 | /* |
| 16585 | * If the fb is shared between multiple heads, we'll |
| 16586 | * just get the first one. |
| 16587 | */ |
| 16588 | intel_find_initial_plane_obj(crtc, &plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 16589 | } |
Matt Roper | d93c037 | 2015-12-03 11:37:41 -0800 | [diff] [blame] | 16590 | |
| 16591 | /* |
| 16592 | * Make sure hardware watermarks really match the state we read out. |
| 16593 | * Note that we need to do this after reconstructing the BIOS fb's |
| 16594 | * since the watermark calculation done here will use pstate->fb. |
| 16595 | */ |
| 16596 | sanitize_watermarks(dev); |
Ville Syrjälä | b079bd17 | 2016-10-25 18:58:02 +0300 | [diff] [blame] | 16597 | |
| 16598 | return 0; |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 16599 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 16600 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 16601 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 16602 | { |
| 16603 | struct intel_connector *connector; |
| 16604 | struct drm_connector *crt = NULL; |
| 16605 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 16606 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 16607 | |
| 16608 | /* We can't just switch on the pipe A, we need to set things up with a |
| 16609 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 16610 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 16611 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 16612 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 16613 | crt = &connector->base; |
| 16614 | break; |
| 16615 | } |
| 16616 | } |
| 16617 | |
| 16618 | if (!crt) |
| 16619 | return; |
| 16620 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 16621 | 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] | 16622 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 16623 | } |
| 16624 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 16625 | static bool |
| 16626 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 16627 | { |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16628 | struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 16629 | u32 val; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 16630 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 16631 | if (INTEL_INFO(dev_priv)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 16632 | return true; |
| 16633 | |
Ville Syrjälä | 649636e | 2015-09-22 19:50:01 +0300 | [diff] [blame] | 16634 | val = I915_READ(DSPCNTR(!crtc->plane)); |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 16635 | |
| 16636 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 16637 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 16638 | return false; |
| 16639 | |
| 16640 | return true; |
| 16641 | } |
| 16642 | |
Ville Syrjälä | 02e93c3 | 2015-08-26 19:39:19 +0300 | [diff] [blame] | 16643 | static bool intel_crtc_has_encoders(struct intel_crtc *crtc) |
| 16644 | { |
| 16645 | struct drm_device *dev = crtc->base.dev; |
| 16646 | struct intel_encoder *encoder; |
| 16647 | |
| 16648 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
| 16649 | return true; |
| 16650 | |
| 16651 | return false; |
| 16652 | } |
| 16653 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 16654 | static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder) |
| 16655 | { |
| 16656 | struct drm_device *dev = encoder->base.dev; |
| 16657 | struct intel_connector *connector; |
| 16658 | |
| 16659 | for_each_connector_on_encoder(dev, &encoder->base, connector) |
| 16660 | return connector; |
| 16661 | |
| 16662 | return NULL; |
| 16663 | } |
| 16664 | |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 16665 | static bool has_pch_trancoder(struct drm_i915_private *dev_priv, |
| 16666 | enum transcoder pch_transcoder) |
| 16667 | { |
| 16668 | return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || |
| 16669 | (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == TRANSCODER_A); |
| 16670 | } |
| 16671 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16672 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 16673 | { |
| 16674 | struct drm_device *dev = crtc->base.dev; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16675 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16676 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16677 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16678 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 16679 | if (!transcoder_is_dsi(cpu_transcoder)) { |
| 16680 | i915_reg_t reg = PIPECONF(cpu_transcoder); |
| 16681 | |
| 16682 | I915_WRITE(reg, |
| 16683 | I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 16684 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16685 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 16686 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 16687 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 16688 | if (crtc->active) { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16689 | struct intel_plane *plane; |
| 16690 | |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 16691 | drm_crtc_vblank_on(&crtc->base); |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16692 | |
| 16693 | /* Disable everything but the primary plane */ |
| 16694 | for_each_intel_plane_on_crtc(dev, crtc, plane) { |
| 16695 | if (plane->base.type == DRM_PLANE_TYPE_PRIMARY) |
| 16696 | continue; |
| 16697 | |
| 16698 | plane->disable_plane(&plane->base, &crtc->base); |
| 16699 | } |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 16700 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 16701 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16702 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 16703 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 16704 | * that gen4+ has a fixed plane -> pipe mapping. */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 16705 | if (INTEL_GEN(dev_priv) < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16706 | bool plane; |
| 16707 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 16708 | DRM_DEBUG_KMS("[CRTC:%d:%s] wrong plane connection detected!\n", |
| 16709 | crtc->base.base.id, crtc->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16710 | |
| 16711 | /* Pipe has the wrong plane attached and the plane is active. |
| 16712 | * Temporarily change the plane mapping and disable everything |
| 16713 | * ... */ |
| 16714 | plane = crtc->plane; |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 16715 | to_intel_plane_state(crtc->base.primary->state)->base.visible = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16716 | crtc->plane = !plane; |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 16717 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16718 | crtc->plane = plane; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16719 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16720 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 16721 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 16722 | crtc->pipe == PIPE_A && !crtc->active) { |
| 16723 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 16724 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 16725 | * call below we restore the pipe to the right state, but leave |
| 16726 | * the required bits on. */ |
| 16727 | intel_enable_pipe_a(dev); |
| 16728 | } |
| 16729 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16730 | /* Adjust the state of the output pipe according to whether we |
| 16731 | * have active connectors/encoders. */ |
Maarten Lankhorst | 842e030 | 2016-03-02 15:48:01 +0100 | [diff] [blame] | 16732 | if (crtc->active && !intel_crtc_has_encoders(crtc)) |
Maarten Lankhorst | b17d48e | 2015-06-12 11:15:39 +0200 | [diff] [blame] | 16733 | intel_crtc_disable_noatomic(&crtc->base); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16734 | |
Tvrtko Ursulin | 49cff96 | 2016-10-13 11:02:54 +0100 | [diff] [blame] | 16735 | if (crtc->active || HAS_GMCH_DISPLAY(dev_priv)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 16736 | /* |
| 16737 | * We start out with underrun reporting disabled to avoid races. |
| 16738 | * For correct bookkeeping mark this on active crtcs. |
| 16739 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 16740 | * Also on gmch platforms we dont have any hardware bits to |
| 16741 | * disable the underrun reporting. Which means we need to start |
| 16742 | * out with underrun reporting disabled also on inactive pipes, |
| 16743 | * since otherwise we'll complain about the garbage we read when |
| 16744 | * e.g. coming up after runtime pm. |
| 16745 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 16746 | * No protection against concurrent access is required - at |
| 16747 | * worst a fifo underrun happens which also sets this to false. |
| 16748 | */ |
| 16749 | crtc->cpu_fifo_underrun_disabled = true; |
Ville Syrjälä | a168f5b | 2016-08-05 20:00:17 +0300 | [diff] [blame] | 16750 | /* |
| 16751 | * We track the PCH trancoder underrun reporting state |
| 16752 | * within the crtc. With crtc for pipe A housing the underrun |
| 16753 | * reporting state for PCH transcoder A, crtc for pipe B housing |
| 16754 | * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A, |
| 16755 | * and marking underrun reporting as disabled for the non-existing |
| 16756 | * PCH transcoders B and C would prevent enabling the south |
| 16757 | * error interrupt (see cpt_can_enable_serr_int()). |
| 16758 | */ |
| 16759 | if (has_pch_trancoder(dev_priv, (enum transcoder)crtc->pipe)) |
| 16760 | crtc->pch_fifo_underrun_disabled = true; |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 16761 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16762 | } |
| 16763 | |
| 16764 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 16765 | { |
| 16766 | struct intel_connector *connector; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16767 | |
| 16768 | /* We need to check both for a crtc link (meaning that the |
| 16769 | * encoder is active and trying to read from a pipe) and the |
| 16770 | * pipe itself being active. */ |
| 16771 | bool has_active_crtc = encoder->base.crtc && |
| 16772 | to_intel_crtc(encoder->base.crtc)->active; |
| 16773 | |
Maarten Lankhorst | 496b0fc | 2016-08-23 16:18:07 +0200 | [diff] [blame] | 16774 | connector = intel_encoder_find_connector(encoder); |
| 16775 | if (connector && !has_active_crtc) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16776 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 16777 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 16778 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16779 | |
| 16780 | /* Connector is active, but has no active pipe. This is |
| 16781 | * fallout from our resume register restoring. Disable |
| 16782 | * the encoder manually again. */ |
| 16783 | if (encoder->base.crtc) { |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 16784 | struct drm_crtc_state *crtc_state = encoder->base.crtc->state; |
| 16785 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16786 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 16787 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 16788 | encoder->base.name); |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 16789 | encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 16790 | if (encoder->post_disable) |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 16791 | encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16792 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 16793 | encoder->base.crtc = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16794 | |
| 16795 | /* Inconsistent output/port/pipe state happens presumably due to |
| 16796 | * a bug in one of the get_hw_state functions. Or someplace else |
| 16797 | * in our code, like the register restore mess on resume. Clamp |
| 16798 | * things to off as a safer default. */ |
Maarten Lankhorst | fd6bbda | 2016-08-09 17:04:04 +0200 | [diff] [blame] | 16799 | |
| 16800 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 16801 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16802 | } |
| 16803 | /* Enabled encoders without active connectors will be fixed in |
| 16804 | * the crtc fixup. */ |
| 16805 | } |
| 16806 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16807 | void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 16808 | { |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 16809 | i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 16810 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 16811 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 16812 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16813 | i915_disable_vga(dev_priv); |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 16814 | } |
| 16815 | } |
| 16816 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16817 | void i915_redisable_vga(struct drm_i915_private *dev_priv) |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 16818 | { |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 16819 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 16820 | * at a very early point in our resume sequence, where the power well |
| 16821 | * structures are not yet restored. Since this function is at a very |
| 16822 | * paranoid "someone might have enabled VGA while we were not looking" |
| 16823 | * level, just check if the power well is enabled instead of trying to |
| 16824 | * follow the "don't touch the power well if we don't need it" policy |
| 16825 | * the rest of the driver uses. */ |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 16826 | if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 16827 | return; |
| 16828 | |
Tvrtko Ursulin | 29b74b7 | 2016-11-16 08:55:39 +0000 | [diff] [blame] | 16829 | i915_redisable_vga_power_on(dev_priv); |
Imre Deak | 6392f84 | 2016-02-12 18:55:13 +0200 | [diff] [blame] | 16830 | |
| 16831 | intel_display_power_put(dev_priv, POWER_DOMAIN_VGA); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 16832 | } |
| 16833 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16834 | static bool primary_get_hw_state(struct intel_plane *plane) |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 16835 | { |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16836 | struct drm_i915_private *dev_priv = to_i915(plane->base.dev); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 16837 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16838 | return I915_READ(DSPCNTR(plane->plane)) & DISPLAY_PLANE_ENABLE; |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 16839 | } |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 16840 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16841 | /* FIXME read out full plane state for all planes */ |
| 16842 | static void readout_plane_state(struct intel_crtc *crtc) |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 16843 | { |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 16844 | struct drm_plane *primary = crtc->base.primary; |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16845 | struct intel_plane_state *plane_state = |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 16846 | to_intel_plane_state(primary->state); |
Maarten Lankhorst | d032ffa | 2015-06-15 12:33:51 +0200 | [diff] [blame] | 16847 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 16848 | plane_state->base.visible = crtc->active && |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 16849 | primary_get_hw_state(to_intel_plane(primary)); |
| 16850 | |
Ville Syrjälä | 936e71e | 2016-07-26 19:06:59 +0300 | [diff] [blame] | 16851 | if (plane_state->base.visible) |
Maarten Lankhorst | b26d3ea | 2015-09-23 16:11:41 +0200 | [diff] [blame] | 16852 | crtc->base.state->plane_mask |= 1 << drm_plane_index(primary); |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 16853 | } |
| 16854 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 16855 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16856 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 16857 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16858 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16859 | struct intel_crtc *crtc; |
| 16860 | struct intel_encoder *encoder; |
| 16861 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 16862 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16863 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 16864 | dev_priv->active_crtcs = 0; |
| 16865 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 16866 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 16867 | struct intel_crtc_state *crtc_state = crtc->config; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 16868 | |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 16869 | __drm_atomic_helper_crtc_destroy_state(&crtc_state->base); |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 16870 | memset(crtc_state, 0, sizeof(*crtc_state)); |
| 16871 | crtc_state->base.crtc = &crtc->base; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16872 | |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 16873 | crtc_state->base.active = crtc_state->base.enable = |
| 16874 | dev_priv->display.get_pipe_config(crtc, crtc_state); |
| 16875 | |
| 16876 | crtc->base.enabled = crtc_state->base.enable; |
| 16877 | crtc->active = crtc_state->base.active; |
| 16878 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16879 | if (crtc_state->base.active) |
Maarten Lankhorst | 565602d | 2015-12-10 12:33:57 +0100 | [diff] [blame] | 16880 | dev_priv->active_crtcs |= 1 << crtc->pipe; |
| 16881 | |
Ville Syrjälä | f9cd7b8 | 2015-09-10 18:59:08 +0300 | [diff] [blame] | 16882 | readout_plane_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16883 | |
Ville Syrjälä | 78108b7 | 2016-05-27 20:59:19 +0300 | [diff] [blame] | 16884 | DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n", |
| 16885 | crtc->base.base.id, crtc->base.name, |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 16886 | enableddisabled(crtc->active)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16887 | } |
| 16888 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 16889 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 16890 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 16891 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 16892 | pll->on = pll->funcs.get_hw_state(dev_priv, pll, |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 16893 | &pll->state.hw_state); |
| 16894 | pll->state.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 16895 | for_each_intel_crtc(dev, crtc) { |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 16896 | if (crtc->active && crtc->config->shared_dpll == pll) |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 16897 | pll->state.crtc_mask |= 1 << crtc->pipe; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 16898 | } |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 16899 | pll->active_mask = pll->state.crtc_mask; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 16900 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 16901 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
Ander Conselvan de Oliveira | 2c42e53 | 2016-12-29 17:22:09 +0200 | [diff] [blame] | 16902 | pll->name, pll->state.crtc_mask, pll->on); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 16903 | } |
| 16904 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 16905 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16906 | pipe = 0; |
| 16907 | |
| 16908 | if (encoder->get_hw_state(encoder, &pipe)) { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 16909 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 16910 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 16911 | encoder->base.crtc = &crtc->base; |
Ville Syrjälä | 253c84c | 2016-06-22 21:57:01 +0300 | [diff] [blame] | 16912 | crtc->config->output_types |= 1 << encoder->type; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 16913 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16914 | } else { |
| 16915 | encoder->base.crtc = NULL; |
| 16916 | } |
| 16917 | |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 16918 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 16919 | encoder->base.base.id, encoder->base.name, |
| 16920 | enableddisabled(encoder->base.crtc), |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 16921 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16922 | } |
| 16923 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 16924 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16925 | if (connector->get_hw_state(connector)) { |
| 16926 | connector->base.dpms = DRM_MODE_DPMS_ON; |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 16927 | |
| 16928 | encoder = connector->encoder; |
| 16929 | connector->base.encoder = &encoder->base; |
| 16930 | |
| 16931 | if (encoder->base.crtc && |
| 16932 | encoder->base.crtc->state->active) { |
| 16933 | /* |
| 16934 | * This has to be done during hardware readout |
| 16935 | * because anything calling .crtc_disable may |
| 16936 | * rely on the connector_mask being accurate. |
| 16937 | */ |
| 16938 | encoder->base.crtc->state->connector_mask |= |
| 16939 | 1 << drm_connector_index(&connector->base); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 16940 | encoder->base.crtc->state->encoder_mask |= |
| 16941 | 1 << drm_encoder_index(&encoder->base); |
Maarten Lankhorst | 2aa974c | 2016-01-06 14:53:25 +0100 | [diff] [blame] | 16942 | } |
| 16943 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16944 | } else { |
| 16945 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 16946 | connector->base.encoder = NULL; |
| 16947 | } |
| 16948 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
Tvrtko Ursulin | 08c4d7f | 2016-11-17 12:30:14 +0000 | [diff] [blame] | 16949 | connector->base.base.id, connector->base.name, |
| 16950 | enableddisabled(connector->base.encoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 16951 | } |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16952 | |
| 16953 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16954 | int pixclk = 0; |
| 16955 | |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16956 | crtc->base.hwmode = crtc->config->base.adjusted_mode; |
| 16957 | |
| 16958 | memset(&crtc->base.mode, 0, sizeof(crtc->base.mode)); |
| 16959 | if (crtc->base.state->active) { |
| 16960 | intel_mode_from_pipe_config(&crtc->base.mode, crtc->config); |
| 16961 | intel_mode_from_pipe_config(&crtc->base.state->adjusted_mode, crtc->config); |
| 16962 | WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode)); |
| 16963 | |
| 16964 | /* |
| 16965 | * The initial mode needs to be set in order to keep |
| 16966 | * the atomic core happy. It wants a valid mode if the |
| 16967 | * crtc's enabled, so we do the above call. |
| 16968 | * |
| 16969 | * At this point some state updated by the connectors |
| 16970 | * in their ->detect() callback has not run yet, so |
| 16971 | * no recalculation can be done yet. |
| 16972 | * |
| 16973 | * Even if we could do a recalculation and modeset |
| 16974 | * right now it would cause a double modeset if |
| 16975 | * fbdev or userspace chooses a different initial mode. |
| 16976 | * |
| 16977 | * If that happens, someone indicated they wanted a |
| 16978 | * mode change, which means it's safe to do a full |
| 16979 | * recalculation. |
| 16980 | */ |
| 16981 | crtc->base.state->mode.private_flags = I915_MODE_FLAG_INHERITED; |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 16982 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16983 | if (INTEL_GEN(dev_priv) >= 9 || IS_BROADWELL(dev_priv)) |
| 16984 | pixclk = ilk_pipe_pixel_rate(crtc->config); |
| 16985 | else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
| 16986 | pixclk = crtc->config->base.adjusted_mode.crtc_clock; |
| 16987 | else |
| 16988 | WARN_ON(dev_priv->display.modeset_calc_cdclk); |
| 16989 | |
| 16990 | /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */ |
| 16991 | if (IS_BROADWELL(dev_priv) && crtc->config->ips_enabled) |
| 16992 | pixclk = DIV_ROUND_UP(pixclk * 100, 95); |
| 16993 | |
Ville Syrjälä | 9eca6832 | 2015-09-10 18:59:10 +0300 | [diff] [blame] | 16994 | drm_calc_timestamping_constants(&crtc->base, &crtc->base.hwmode); |
| 16995 | update_scanline_offset(crtc); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 16996 | } |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 16997 | |
Ville Syrjälä | aca1ebf | 2016-12-20 17:39:02 +0200 | [diff] [blame] | 16998 | dev_priv->min_pixclk[crtc->pipe] = pixclk; |
| 16999 | |
Ville Syrjälä | e3b247d | 2016-02-17 21:41:09 +0200 | [diff] [blame] | 17000 | intel_pipe_config_sanity_check(dev_priv, crtc->config); |
Ville Syrjälä | 7f4c628 | 2015-09-10 18:59:07 +0300 | [diff] [blame] | 17001 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 17002 | } |
| 17003 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17004 | /* Scan out the current hw modeset state, |
| 17005 | * and sanitizes it to the current state |
| 17006 | */ |
| 17007 | static void |
| 17008 | intel_modeset_setup_hw_state(struct drm_device *dev) |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 17009 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 17010 | struct drm_i915_private *dev_priv = to_i915(dev); |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 17011 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 17012 | struct intel_crtc *crtc; |
| 17013 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 17014 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 17015 | |
| 17016 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 17017 | |
| 17018 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 17019 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 17020 | intel_sanitize_encoder(encoder); |
| 17021 | } |
| 17022 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 17023 | for_each_pipe(dev_priv, pipe) { |
Ville Syrjälä | 9818783 | 2016-10-31 22:37:10 +0200 | [diff] [blame] | 17024 | crtc = intel_get_crtc_for_pipe(dev_priv, pipe); |
Ville Syrjälä | e2af48c | 2016-10-31 22:37:05 +0200 | [diff] [blame] | 17025 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 17026 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 17027 | intel_dump_pipe_config(crtc, crtc->config, |
| 17028 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 17029 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 17030 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 17031 | intel_modeset_update_connector_atomic_state(dev); |
| 17032 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 17033 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 17034 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 17035 | |
Maarten Lankhorst | 2dd66ebd | 2016-03-14 09:27:52 +0100 | [diff] [blame] | 17036 | if (!pll->on || pll->active_mask) |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 17037 | continue; |
| 17038 | |
| 17039 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 17040 | |
Ander Conselvan de Oliveira | 2edd644 | 2016-03-08 17:46:21 +0200 | [diff] [blame] | 17041 | pll->funcs.disable(dev_priv, pll); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 17042 | pll->on = false; |
| 17043 | } |
| 17044 | |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 17045 | if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) |
Ville Syrjälä | 6eb1a68 | 2015-06-24 22:00:03 +0300 | [diff] [blame] | 17046 | vlv_wm_get_hw_state(dev); |
Tvrtko Ursulin | 5db9401 | 2016-10-13 11:03:10 +0100 | [diff] [blame] | 17047 | else if (IS_GEN9(dev_priv)) |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 17048 | skl_wm_get_hw_state(dev); |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 17049 | else if (HAS_PCH_SPLIT(dev_priv)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 17050 | ilk_wm_get_hw_state(dev); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 17051 | |
| 17052 | for_each_intel_crtc(dev, crtc) { |
| 17053 | unsigned long put_domains; |
| 17054 | |
Maarten Lankhorst | 74bff5f | 2016-02-10 13:49:36 +0100 | [diff] [blame] | 17055 | put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc->config); |
Maarten Lankhorst | 292b990 | 2015-07-13 16:30:27 +0200 | [diff] [blame] | 17056 | if (WARN_ON(put_domains)) |
| 17057 | modeset_put_power_domains(dev_priv, put_domains); |
| 17058 | } |
| 17059 | intel_display_set_init_power(dev_priv, false); |
Paulo Zanoni | 010cf73 | 2016-01-19 11:35:48 -0200 | [diff] [blame] | 17060 | |
| 17061 | intel_fbc_init_pipe_state(dev_priv); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17062 | } |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 17063 | |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17064 | void intel_display_resume(struct drm_device *dev) |
| 17065 | { |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17066 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 17067 | struct drm_atomic_state *state = dev_priv->modeset_restore_state; |
| 17068 | struct drm_modeset_acquire_ctx ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17069 | int ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 17070 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17071 | dev_priv->modeset_restore_state = NULL; |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 17072 | if (state) |
| 17073 | state->acquire_ctx = &ctx; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17074 | |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 17075 | /* |
| 17076 | * This is a cludge because with real atomic modeset mode_config.mutex |
| 17077 | * won't be taken. Unfortunately some probed state like |
| 17078 | * audio_codec_enable is still protected by mode_config.mutex, so lock |
| 17079 | * it here for now. |
| 17080 | */ |
| 17081 | mutex_lock(&dev->mode_config.mutex); |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17082 | drm_modeset_acquire_init(&ctx, 0); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17083 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 17084 | while (1) { |
| 17085 | ret = drm_modeset_lock_all_ctx(dev, &ctx); |
| 17086 | if (ret != -EDEADLK) |
| 17087 | break; |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17088 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17089 | drm_modeset_backoff(&ctx); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17090 | } |
| 17091 | |
Maarten Lankhorst | 7397489 | 2016-08-05 23:28:27 +0300 | [diff] [blame] | 17092 | if (!ret) |
| 17093 | ret = __intel_display_resume(dev, state); |
| 17094 | |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17095 | drm_modeset_drop_locks(&ctx); |
| 17096 | drm_modeset_acquire_fini(&ctx); |
Maarten Lankhorst | ea49c9a | 2016-02-16 15:27:42 +0100 | [diff] [blame] | 17097 | mutex_unlock(&dev->mode_config.mutex); |
Maarten Lankhorst | 043e9bd | 2015-07-13 16:30:25 +0200 | [diff] [blame] | 17098 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 17099 | if (ret) |
Maarten Lankhorst | e2c8b87 | 2016-02-16 10:06:14 +0100 | [diff] [blame] | 17100 | DRM_ERROR("Restoring old state failed with %i\n", ret); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 17101 | drm_atomic_state_put(state); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 17102 | } |
| 17103 | |
| 17104 | void intel_modeset_gem_init(struct drm_device *dev) |
| 17105 | { |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 17106 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17107 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 17108 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17109 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 17110 | intel_init_gt_powersave(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 17111 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 17112 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 17113 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 17114 | intel_setup_overlay(dev_priv); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17115 | |
| 17116 | /* |
| 17117 | * Make sure any fbs we allocated at startup are properly |
| 17118 | * pinned & fenced. When we do the allocation it's too early |
| 17119 | * for this. |
| 17120 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 17121 | for_each_crtc(dev, c) { |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 17122 | struct i915_vma *vma; |
| 17123 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 17124 | obj = intel_fb_obj(c->primary->fb); |
| 17125 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17126 | continue; |
| 17127 | |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 17128 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 17129 | vma = intel_pin_and_fence_fb_obj(c->primary->fb, |
Ville Syrjälä | 3465c58 | 2016-02-15 22:54:43 +0200 | [diff] [blame] | 17130 | c->primary->state->rotation); |
Tvrtko Ursulin | e0d6149 | 2015-04-13 16:03:03 +0100 | [diff] [blame] | 17131 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | 058d88c | 2016-08-15 10:49:06 +0100 | [diff] [blame] | 17132 | if (IS_ERR(vma)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17133 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 17134 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 17135 | drm_framebuffer_unreference(c->primary->fb); |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 17136 | c->primary->fb = NULL; |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 17137 | c->primary->crtc = c->primary->state->crtc = NULL; |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 17138 | update_state_fb(c->primary); |
Maarten Lankhorst | 36750f2 | 2015-06-01 12:49:54 +0200 | [diff] [blame] | 17139 | c->state->plane_mask &= ~(1 << drm_plane_index(c->primary)); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 17140 | } |
| 17141 | } |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 17142 | } |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 17143 | |
Chris Wilson | 1ebaa0b | 2016-06-24 14:00:15 +0100 | [diff] [blame] | 17144 | int intel_connector_register(struct drm_connector *connector) |
| 17145 | { |
| 17146 | struct intel_connector *intel_connector = to_intel_connector(connector); |
| 17147 | int ret; |
| 17148 | |
| 17149 | ret = intel_backlight_device_register(intel_connector); |
| 17150 | if (ret) |
| 17151 | goto err; |
| 17152 | |
| 17153 | return 0; |
| 17154 | |
| 17155 | err: |
| 17156 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 17157 | } |
| 17158 | |
Chris Wilson | c191eca | 2016-06-17 11:40:33 +0100 | [diff] [blame] | 17159 | void intel_connector_unregister(struct drm_connector *connector) |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 17160 | { |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 17161 | struct intel_connector *intel_connector = to_intel_connector(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 17162 | |
Chris Wilson | e63d87c | 2016-06-17 11:40:34 +0100 | [diff] [blame] | 17163 | intel_backlight_device_unregister(intel_connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 17164 | intel_panel_destroy_backlight(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 17165 | } |
| 17166 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 17167 | void intel_modeset_cleanup(struct drm_device *dev) |
| 17168 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 17169 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 17170 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 17171 | intel_disable_gt_powersave(dev_priv); |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 17172 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 17173 | /* |
| 17174 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 17175 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 17176 | * experience fancy races otherwise. |
| 17177 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 17178 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 17179 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 17180 | /* |
| 17181 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 17182 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 17183 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 17184 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 17185 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 17186 | intel_unregister_dsm_handler(); |
| 17187 | |
Paulo Zanoni | c937ab3e5 | 2016-01-19 11:35:46 -0200 | [diff] [blame] | 17188 | intel_fbc_global_disable(dev_priv); |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 17189 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 17190 | /* flush any delayed tasks or pending work */ |
| 17191 | flush_scheduled_work(); |
| 17192 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 17193 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 17194 | |
Chris Wilson | 1ee8da6 | 2016-05-12 12:43:23 +0100 | [diff] [blame] | 17195 | intel_cleanup_overlay(dev_priv); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 17196 | |
Chris Wilson | dc97997 | 2016-05-10 14:10:04 +0100 | [diff] [blame] | 17197 | intel_cleanup_gt_powersave(dev_priv); |
Daniel Vetter | f594914 | 2016-01-13 11:55:28 +0100 | [diff] [blame] | 17198 | |
Tvrtko Ursulin | 4019644 | 2016-12-01 14:16:42 +0000 | [diff] [blame] | 17199 | intel_teardown_gmbus(dev_priv); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 17200 | } |
| 17201 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 17202 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 17203 | struct intel_encoder *encoder) |
| 17204 | { |
| 17205 | connector->encoder = encoder; |
| 17206 | drm_mode_connector_attach_encoder(&connector->base, |
| 17207 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 17208 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 17209 | |
| 17210 | /* |
| 17211 | * set vga decode state - true == enable VGA decode |
| 17212 | */ |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 17213 | int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state) |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 17214 | { |
Tvrtko Ursulin | 6315b5d | 2016-11-16 12:32:42 +0000 | [diff] [blame] | 17215 | unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 17216 | u16 gmch_ctrl; |
| 17217 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 17218 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 17219 | DRM_ERROR("failed to read control word\n"); |
| 17220 | return -EIO; |
| 17221 | } |
| 17222 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 17223 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 17224 | return 0; |
| 17225 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 17226 | if (state) |
| 17227 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 17228 | else |
| 17229 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 17230 | |
| 17231 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 17232 | DRM_ERROR("failed to write control word\n"); |
| 17233 | return -EIO; |
| 17234 | } |
| 17235 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 17236 | return 0; |
| 17237 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17238 | |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 17239 | #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) |
| 17240 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17241 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 17242 | |
| 17243 | u32 power_well_driver; |
| 17244 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17245 | int num_transcoders; |
| 17246 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17247 | struct intel_cursor_error_state { |
| 17248 | u32 control; |
| 17249 | u32 position; |
| 17250 | u32 base; |
| 17251 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 17252 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17253 | |
| 17254 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17255 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17256 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 17257 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 17258 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17259 | |
| 17260 | struct intel_plane_error_state { |
| 17261 | u32 control; |
| 17262 | u32 stride; |
| 17263 | u32 size; |
| 17264 | u32 pos; |
| 17265 | u32 addr; |
| 17266 | u32 surface; |
| 17267 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 17268 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17269 | |
| 17270 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17271 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17272 | enum transcoder cpu_transcoder; |
| 17273 | |
| 17274 | u32 conf; |
| 17275 | |
| 17276 | u32 htotal; |
| 17277 | u32 hblank; |
| 17278 | u32 hsync; |
| 17279 | u32 vtotal; |
| 17280 | u32 vblank; |
| 17281 | u32 vsync; |
| 17282 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17283 | }; |
| 17284 | |
| 17285 | struct intel_display_error_state * |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17286 | intel_display_capture_error_state(struct drm_i915_private *dev_priv) |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17287 | { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17288 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17289 | int transcoders[] = { |
| 17290 | TRANSCODER_A, |
| 17291 | TRANSCODER_B, |
| 17292 | TRANSCODER_C, |
| 17293 | TRANSCODER_EDP, |
| 17294 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17295 | int i; |
| 17296 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17297 | if (INTEL_INFO(dev_priv)->num_pipes == 0) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17298 | return NULL; |
| 17299 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 17300 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17301 | if (error == NULL) |
| 17302 | return NULL; |
| 17303 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17304 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 17305 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 17306 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 17307 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17308 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 17309 | __intel_display_power_is_enabled(dev_priv, |
| 17310 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17311 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 17312 | continue; |
| 17313 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 17314 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 17315 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 17316 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17317 | |
| 17318 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 17319 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17320 | if (INTEL_GEN(dev_priv) <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 17321 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 17322 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 17323 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17324 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 17325 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17326 | if (INTEL_GEN(dev_priv) >= 4) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17327 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 17328 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 17329 | } |
| 17330 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17331 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 17332 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17333 | if (HAS_GMCH_DISPLAY(dev_priv)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 17334 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17335 | } |
| 17336 | |
Jani Nikula | 4d1de97 | 2016-03-18 17:05:42 +0200 | [diff] [blame] | 17337 | /* Note: this does not include DSI transcoders. */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 17338 | error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes; |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 17339 | if (HAS_DDI(dev_priv)) |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17340 | error->num_transcoders++; /* Account for eDP. */ |
| 17341 | |
| 17342 | for (i = 0; i < error->num_transcoders; i++) { |
| 17343 | enum transcoder cpu_transcoder = transcoders[i]; |
| 17344 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17345 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 17346 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 17347 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17348 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 17349 | continue; |
| 17350 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17351 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 17352 | |
| 17353 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 17354 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 17355 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 17356 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 17357 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 17358 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 17359 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17360 | } |
| 17361 | |
| 17362 | return error; |
| 17363 | } |
| 17364 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17365 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 17366 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17367 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17368 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 17369 | struct drm_i915_private *dev_priv, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17370 | struct intel_display_error_state *error) |
| 17371 | { |
| 17372 | int i; |
| 17373 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17374 | if (!error) |
| 17375 | return; |
| 17376 | |
Tvrtko Ursulin | b7f05d4 | 2016-11-09 11:30:45 +0000 | [diff] [blame] | 17377 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes); |
Tvrtko Ursulin | 8652744 | 2016-10-13 11:03:00 +0100 | [diff] [blame] | 17378 | if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17379 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 17380 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 17381 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17382 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17383 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 17384 | onoff(error->pipe[i].power_domain_on)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17385 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 17386 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17387 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17388 | err_printf(m, "Plane [%d]:\n", i); |
| 17389 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 17390 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 17391 | if (INTEL_GEN(dev_priv) <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17392 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 17393 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 17394 | } |
Tvrtko Ursulin | 772c2a5 | 2016-10-13 11:03:01 +0100 | [diff] [blame] | 17395 | if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17396 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Tvrtko Ursulin | 5f56d5f | 2016-11-16 08:55:37 +0000 | [diff] [blame] | 17397 | if (INTEL_GEN(dev_priv) >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17398 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 17399 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17400 | } |
| 17401 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 17402 | err_printf(m, "Cursor [%d]:\n", i); |
| 17403 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 17404 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 17405 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17406 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17407 | |
| 17408 | for (i = 0; i < error->num_transcoders; i++) { |
Jani Nikula | da20563 | 2016-03-15 21:51:10 +0200 | [diff] [blame] | 17409 | err_printf(m, "CPU transcoder: %s\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17410 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 17411 | err_printf(m, " Power: %s\n", |
Jani Nikula | 87ad321 | 2016-01-14 12:53:34 +0200 | [diff] [blame] | 17412 | onoff(error->transcoder[i].power_domain_on)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 17413 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 17414 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 17415 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 17416 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 17417 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 17418 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 17419 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 17420 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 17421 | } |
Chris Wilson | 98a2f41 | 2016-10-12 10:05:18 +0100 | [diff] [blame] | 17422 | |
| 17423 | #endif |