blob: 699ee6946891222bd9e5b5e2d68ce05860e82085 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006-2007 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 */
26
Jesse Barnesc1c7af62009-09-10 15:28:03 -070027#include <linux/module.h>
28#include <linux/input.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080029#include <linux/i2c.h>
Shaohua Li7662c8b2009-06-26 11:23:55 +080030#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Jesse Barnes9cce37f2010-08-13 15:11:26 -070032#include <linux/vgaarb.h>
Wu Fengguange0dac652011-09-05 14:25:34 +080033#include <drm/drm_edid.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "intel_drv.h"
Chris Wilson5d723d72016-08-04 16:32:35 +010036#include "intel_frontbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "i915_drv.h"
Chris Wilson57822dc2017-02-22 11:40:48 +000039#include "i915_gem_clflush.h"
Imre Deakdb18b6a2016-03-24 12:41:40 +020040#include "intel_dsi.h"
Jesse Barnese5510fa2010-07-01 16:48:37 -070041#include "i915_trace.h"
Xi Ruoyao319c1d42015-03-12 20:16:32 +080042#include <drm/drm_atomic.h>
Matt Roperc196e1d2015-01-21 16:35:48 -080043#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010044#include <drm/drm_dp_helper.h>
45#include <drm/drm_crtc_helper.h>
Matt Roper465c1202014-05-29 08:06:54 -070046#include <drm/drm_plane_helper.h>
47#include <drm/drm_rect.h>
Daniel Vetter72fdb402018-09-05 15:57:11 +020048#include <drm/drm_atomic_uapi.h>
Keith Packardc0f372b32011-11-16 22:24:52 -080049#include <linux/dma_remapping.h>
Alex Goinsfd8e0582015-11-25 18:43:38 -080050#include <linux/reservation.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080051
Matt Roper465c1202014-05-29 08:06:54 -070052/* Primary plane formats for gen <= 3 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010053static const uint32_t i8xx_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010054 DRM_FORMAT_C8,
55 DRM_FORMAT_RGB565,
Matt Roper465c1202014-05-29 08:06:54 -070056 DRM_FORMAT_XRGB1555,
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010057 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070058};
59
60/* Primary plane formats for gen >= 4 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010061static const uint32_t i965_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010062 DRM_FORMAT_C8,
63 DRM_FORMAT_RGB565,
64 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070065 DRM_FORMAT_XBGR8888,
Damien Lespiau6c0fd452015-05-19 12:29:16 +010066 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
68};
69
Ben Widawsky714244e2017-08-01 09:58:16 -070070static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
74};
75
Matt Roper3d7d6512014-06-10 08:28:13 -070076/* Cursor formats */
77static const uint32_t intel_cursor_formats[] = {
78 DRM_FORMAT_ARGB8888,
79};
80
Ben Widawsky714244e2017-08-01 09:58:16 -070081static const uint64_t cursor_format_modifiers[] = {
82 DRM_FORMAT_MOD_LINEAR,
83 DRM_FORMAT_MOD_INVALID
84};
85
Jesse Barnesf1f644d2013-06-27 00:39:25 +030086static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020087 struct intel_crtc_state *pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +030088static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020089 struct intel_crtc_state *pipe_config);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030090
Chris Wilson24dbf512017-02-15 10:59:18 +000091static int intel_framebuffer_init(struct intel_framebuffer *ifb,
92 struct drm_i915_gem_object *obj,
93 struct drm_mode_fb_cmd2 *mode_cmd);
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +020094static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
95static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
Maarten Lankhorst4c354752018-10-11 12:04:49 +020096static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
97 const struct intel_link_m_n *m_n,
98 const struct intel_link_m_n *m2_n2);
Maarten Lankhorstfdf73512018-10-04 11:45:52 +020099static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
100static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
101static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
102static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200103static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200104 const struct intel_crtc_state *pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200105static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200106 const struct intel_crtc_state *pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200107static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
108static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
Nabendu Maiti1c74eea2016-11-29 11:23:14 +0530109static void intel_crtc_init_scalers(struct intel_crtc *crtc,
110 struct intel_crtc_state *crtc_state);
Maarten Lankhorstb2562712018-10-04 11:45:53 +0200111static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
112static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
113static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +0300114static void intel_modeset_setup_hw_state(struct drm_device *dev,
115 struct drm_modeset_acquire_ctx *ctx);
Ville Syrjälä2622a082016-03-09 19:07:26 +0200116static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
Damien Lespiaue7457a92013-08-08 22:28:59 +0100117
Ma Lingd4906092009-03-18 20:13:27 +0800118struct intel_limit {
Ander Conselvan de Oliveira4c5def92016-05-04 12:11:58 +0300119 struct {
120 int min, max;
121 } dot, vco, n, m, m1, m2, p, p1;
122
123 struct {
124 int dot_limit;
125 int p2_slow, p2_fast;
126 } p2;
Ma Lingd4906092009-03-18 20:13:27 +0800127};
Jesse Barnes79e53942008-11-07 14:24:08 -0800128
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300129/* returns HPLL frequency in kHz */
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200130int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300131{
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
133
134 /* Obtain SKU information */
135 mutex_lock(&dev_priv->sb_lock);
136 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
137 CCK_FUSE_HPLL_FREQ_MASK;
138 mutex_unlock(&dev_priv->sb_lock);
139
140 return vco_freq[hpll_freq] * 1000;
141}
142
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200143int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
144 const char *name, u32 reg, int ref_freq)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300145{
146 u32 val;
147 int divider;
148
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300149 mutex_lock(&dev_priv->sb_lock);
150 val = vlv_cck_read(dev_priv, reg);
151 mutex_unlock(&dev_priv->sb_lock);
152
153 divider = val & CCK_FREQUENCY_VALUES;
154
155 WARN((val & CCK_FREQUENCY_STATUS) !=
156 (divider << CCK_FREQUENCY_STATUS_SHIFT),
157 "%s change in progress\n", name);
158
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200159 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
160}
161
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +0200162int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
163 const char *name, u32 reg)
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200164{
165 if (dev_priv->hpll_freq == 0)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200166 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200167
168 return vlv_get_cck_clock(dev_priv, name, reg,
169 dev_priv->hpll_freq);
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300170}
171
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300172static void intel_update_czclk(struct drm_i915_private *dev_priv)
173{
Wayne Boyer666a4532015-12-09 12:29:35 -0800174 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300175 return;
176
177 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
178 CCK_CZ_CLOCK_CONTROL);
179
180 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
181}
182
Chris Wilson021357a2010-09-07 20:54:59 +0100183static inline u32 /* units of 100MHz */
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200184intel_fdi_link_freq(struct drm_i915_private *dev_priv,
185 const struct intel_crtc_state *pipe_config)
Chris Wilson021357a2010-09-07 20:54:59 +0100186{
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200187 if (HAS_DDI(dev_priv))
188 return pipe_config->port_clock; /* SPLL */
Ville Syrjäläe3b247d2016-02-17 21:41:09 +0200189 else
Chris Wilson58ecd9d2017-11-05 13:49:05 +0000190 return dev_priv->fdi_pll_freq;
Chris Wilson021357a2010-09-07 20:54:59 +0100191}
192
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300193static const struct intel_limit intel_limits_i8xx_dac = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400194 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200195 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200196 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400197 .m = { .min = 96, .max = 140 },
198 .m1 = { .min = 18, .max = 26 },
199 .m2 = { .min = 6, .max = 16 },
200 .p = { .min = 4, .max = 128 },
201 .p1 = { .min = 2, .max = 33 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700202 .p2 = { .dot_limit = 165000,
203 .p2_slow = 4, .p2_fast = 2 },
Keith Packarde4b36692009-06-05 19:22:17 -0700204};
205
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300206static const struct intel_limit intel_limits_i8xx_dvo = {
Daniel Vetter5d536e22013-07-06 12:52:06 +0200207 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200208 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200209 .n = { .min = 2, .max = 16 },
Daniel Vetter5d536e22013-07-06 12:52:06 +0200210 .m = { .min = 96, .max = 140 },
211 .m1 = { .min = 18, .max = 26 },
212 .m2 = { .min = 6, .max = 16 },
213 .p = { .min = 4, .max = 128 },
214 .p1 = { .min = 2, .max = 33 },
215 .p2 = { .dot_limit = 165000,
216 .p2_slow = 4, .p2_fast = 4 },
217};
218
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300219static const struct intel_limit intel_limits_i8xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400220 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200221 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200222 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400223 .m = { .min = 96, .max = 140 },
224 .m1 = { .min = 18, .max = 26 },
225 .m2 = { .min = 6, .max = 16 },
226 .p = { .min = 4, .max = 128 },
227 .p1 = { .min = 1, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700228 .p2 = { .dot_limit = 165000,
229 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700230};
Eric Anholt273e27c2011-03-30 13:01:10 -0700231
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300232static const struct intel_limit intel_limits_i9xx_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400233 .dot = { .min = 20000, .max = 400000 },
234 .vco = { .min = 1400000, .max = 2800000 },
235 .n = { .min = 1, .max = 6 },
236 .m = { .min = 70, .max = 120 },
Patrik Jakobsson4f7dfb62013-02-13 22:20:22 +0100237 .m1 = { .min = 8, .max = 18 },
238 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400239 .p = { .min = 5, .max = 80 },
240 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700241 .p2 = { .dot_limit = 200000,
242 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700243};
244
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300245static const struct intel_limit intel_limits_i9xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400246 .dot = { .min = 20000, .max = 400000 },
247 .vco = { .min = 1400000, .max = 2800000 },
248 .n = { .min = 1, .max = 6 },
249 .m = { .min = 70, .max = 120 },
Patrik Jakobsson53a7d2d2013-02-13 22:20:21 +0100250 .m1 = { .min = 8, .max = 18 },
251 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400252 .p = { .min = 7, .max = 98 },
253 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700254 .p2 = { .dot_limit = 112000,
255 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700256};
257
Eric Anholt273e27c2011-03-30 13:01:10 -0700258
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300259static const struct intel_limit intel_limits_g4x_sdvo = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700260 .dot = { .min = 25000, .max = 270000 },
261 .vco = { .min = 1750000, .max = 3500000},
262 .n = { .min = 1, .max = 4 },
263 .m = { .min = 104, .max = 138 },
264 .m1 = { .min = 17, .max = 23 },
265 .m2 = { .min = 5, .max = 11 },
266 .p = { .min = 10, .max = 30 },
267 .p1 = { .min = 1, .max = 3},
268 .p2 = { .dot_limit = 270000,
269 .p2_slow = 10,
270 .p2_fast = 10
Ma Ling044c7c42009-03-18 20:13:23 +0800271 },
Keith Packarde4b36692009-06-05 19:22:17 -0700272};
273
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300274static const struct intel_limit intel_limits_g4x_hdmi = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700275 .dot = { .min = 22000, .max = 400000 },
276 .vco = { .min = 1750000, .max = 3500000},
277 .n = { .min = 1, .max = 4 },
278 .m = { .min = 104, .max = 138 },
279 .m1 = { .min = 16, .max = 23 },
280 .m2 = { .min = 5, .max = 11 },
281 .p = { .min = 5, .max = 80 },
282 .p1 = { .min = 1, .max = 8},
283 .p2 = { .dot_limit = 165000,
284 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700285};
286
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300287static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700288 .dot = { .min = 20000, .max = 115000 },
289 .vco = { .min = 1750000, .max = 3500000 },
290 .n = { .min = 1, .max = 3 },
291 .m = { .min = 104, .max = 138 },
292 .m1 = { .min = 17, .max = 23 },
293 .m2 = { .min = 5, .max = 11 },
294 .p = { .min = 28, .max = 112 },
295 .p1 = { .min = 2, .max = 8 },
296 .p2 = { .dot_limit = 0,
297 .p2_slow = 14, .p2_fast = 14
Ma Ling044c7c42009-03-18 20:13:23 +0800298 },
Keith Packarde4b36692009-06-05 19:22:17 -0700299};
300
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300301static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700302 .dot = { .min = 80000, .max = 224000 },
303 .vco = { .min = 1750000, .max = 3500000 },
304 .n = { .min = 1, .max = 3 },
305 .m = { .min = 104, .max = 138 },
306 .m1 = { .min = 17, .max = 23 },
307 .m2 = { .min = 5, .max = 11 },
308 .p = { .min = 14, .max = 42 },
309 .p1 = { .min = 2, .max = 6 },
310 .p2 = { .dot_limit = 0,
311 .p2_slow = 7, .p2_fast = 7
Ma Ling044c7c42009-03-18 20:13:23 +0800312 },
Keith Packarde4b36692009-06-05 19:22:17 -0700313};
314
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300315static const struct intel_limit intel_limits_pineview_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400316 .dot = { .min = 20000, .max = 400000},
317 .vco = { .min = 1700000, .max = 3500000 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700318 /* Pineview's Ncounter is a ring counter */
Akshay Joshi0206e352011-08-16 15:34:10 -0400319 .n = { .min = 3, .max = 6 },
320 .m = { .min = 2, .max = 256 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700321 /* Pineview only has one combined m divider, which we treat as m2. */
Akshay Joshi0206e352011-08-16 15:34:10 -0400322 .m1 = { .min = 0, .max = 0 },
323 .m2 = { .min = 0, .max = 254 },
324 .p = { .min = 5, .max = 80 },
325 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700326 .p2 = { .dot_limit = 200000,
327 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700328};
329
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300330static const struct intel_limit intel_limits_pineview_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400331 .dot = { .min = 20000, .max = 400000 },
332 .vco = { .min = 1700000, .max = 3500000 },
333 .n = { .min = 3, .max = 6 },
334 .m = { .min = 2, .max = 256 },
335 .m1 = { .min = 0, .max = 0 },
336 .m2 = { .min = 0, .max = 254 },
337 .p = { .min = 7, .max = 112 },
338 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700339 .p2 = { .dot_limit = 112000,
340 .p2_slow = 14, .p2_fast = 14 },
Keith Packarde4b36692009-06-05 19:22:17 -0700341};
342
Eric Anholt273e27c2011-03-30 13:01:10 -0700343/* Ironlake / Sandybridge
344 *
345 * We calculate clock using (register_value + 2) for N/M1/M2, so here
346 * the range value for them is (actual_value - 2).
347 */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300348static const struct intel_limit intel_limits_ironlake_dac = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700349 .dot = { .min = 25000, .max = 350000 },
350 .vco = { .min = 1760000, .max = 3510000 },
351 .n = { .min = 1, .max = 5 },
352 .m = { .min = 79, .max = 127 },
353 .m1 = { .min = 12, .max = 22 },
354 .m2 = { .min = 5, .max = 9 },
355 .p = { .min = 5, .max = 80 },
356 .p1 = { .min = 1, .max = 8 },
357 .p2 = { .dot_limit = 225000,
358 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700359};
360
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300361static const struct intel_limit intel_limits_ironlake_single_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700362 .dot = { .min = 25000, .max = 350000 },
363 .vco = { .min = 1760000, .max = 3510000 },
364 .n = { .min = 1, .max = 3 },
365 .m = { .min = 79, .max = 118 },
366 .m1 = { .min = 12, .max = 22 },
367 .m2 = { .min = 5, .max = 9 },
368 .p = { .min = 28, .max = 112 },
369 .p1 = { .min = 2, .max = 8 },
370 .p2 = { .dot_limit = 225000,
371 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800372};
373
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300374static const struct intel_limit intel_limits_ironlake_dual_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700375 .dot = { .min = 25000, .max = 350000 },
376 .vco = { .min = 1760000, .max = 3510000 },
377 .n = { .min = 1, .max = 3 },
378 .m = { .min = 79, .max = 127 },
379 .m1 = { .min = 12, .max = 22 },
380 .m2 = { .min = 5, .max = 9 },
381 .p = { .min = 14, .max = 56 },
382 .p1 = { .min = 2, .max = 8 },
383 .p2 = { .dot_limit = 225000,
384 .p2_slow = 7, .p2_fast = 7 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800385};
386
Eric Anholt273e27c2011-03-30 13:01:10 -0700387/* LVDS 100mhz refclk limits. */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300388static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700389 .dot = { .min = 25000, .max = 350000 },
390 .vco = { .min = 1760000, .max = 3510000 },
391 .n = { .min = 1, .max = 2 },
392 .m = { .min = 79, .max = 126 },
393 .m1 = { .min = 12, .max = 22 },
394 .m2 = { .min = 5, .max = 9 },
395 .p = { .min = 28, .max = 112 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400396 .p1 = { .min = 2, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700397 .p2 = { .dot_limit = 225000,
398 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800399};
400
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300401static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700402 .dot = { .min = 25000, .max = 350000 },
403 .vco = { .min = 1760000, .max = 3510000 },
404 .n = { .min = 1, .max = 3 },
405 .m = { .min = 79, .max = 126 },
406 .m1 = { .min = 12, .max = 22 },
407 .m2 = { .min = 5, .max = 9 },
408 .p = { .min = 14, .max = 42 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400409 .p1 = { .min = 2, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700410 .p2 = { .dot_limit = 225000,
411 .p2_slow = 7, .p2_fast = 7 },
Zhao Yakui45476682009-12-31 16:06:04 +0800412};
413
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300414static const struct intel_limit intel_limits_vlv = {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300415 /*
416 * These are the data rate limits (measured in fast clocks)
417 * since those are the strictest limits we have. The fast
418 * clock and actual rate limits are more relaxed, so checking
419 * them would make no difference.
420 */
421 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
Daniel Vetter75e53982013-04-18 21:10:43 +0200422 .vco = { .min = 4000000, .max = 6000000 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700423 .n = { .min = 1, .max = 7 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700424 .m1 = { .min = 2, .max = 3 },
425 .m2 = { .min = 11, .max = 156 },
Ville Syrjäläb99ab662013-09-24 21:26:26 +0300426 .p1 = { .min = 2, .max = 3 },
Ville Syrjälä5fdc9c492013-09-24 21:26:29 +0300427 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700428};
429
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300430static const struct intel_limit intel_limits_chv = {
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300431 /*
432 * These are the data rate limits (measured in fast clocks)
433 * since those are the strictest limits we have. The fast
434 * clock and actual rate limits are more relaxed, so checking
435 * them would make no difference.
436 */
437 .dot = { .min = 25000 * 5, .max = 540000 * 5},
Ville Syrjälä17fe1022015-02-26 21:01:52 +0200438 .vco = { .min = 4800000, .max = 6480000 },
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300439 .n = { .min = 1, .max = 1 },
440 .m1 = { .min = 2, .max = 2 },
441 .m2 = { .min = 24 << 22, .max = 175 << 22 },
442 .p1 = { .min = 2, .max = 4 },
443 .p2 = { .p2_slow = 1, .p2_fast = 14 },
444};
445
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300446static const struct intel_limit intel_limits_bxt = {
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200447 /* FIXME: find real dot limits */
448 .dot = { .min = 0, .max = INT_MAX },
Vandana Kannane6292552015-07-01 17:02:57 +0530449 .vco = { .min = 4800000, .max = 6700000 },
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 /* FIXME: find real m2 limits */
453 .m2 = { .min = 2 << 22, .max = 255 << 22 },
454 .p1 = { .min = 2, .max = 4 },
455 .p2 = { .p2_slow = 1, .p2_fast = 20 },
456};
457
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530458static void
459skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
460{
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530461 if (enable)
462 I915_WRITE(CLKGATE_DIS_PSL(pipe),
463 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
464 else
465 I915_WRITE(CLKGATE_DIS_PSL(pipe),
466 I915_READ(CLKGATE_DIS_PSL(pipe)) &
467 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
468}
469
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200470static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100471needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200472{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200473 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200474}
475
Imre Deakdccbea32015-06-22 23:35:51 +0300476/*
477 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
478 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
479 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
480 * The helpers' return value is the rate of the clock that is fed to the
481 * display engine's pipe which can be the above fast dot clock rate or a
482 * divided-down version of it.
483 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500484/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300485static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800486{
Shaohua Li21778322009-02-23 15:19:16 +0800487 clock->m = clock->m2 + 2;
488 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200489 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300490 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300491 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
492 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300493
494 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800495}
496
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200497static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
498{
499 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
500}
501
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300502static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800503{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200504 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800505 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200506 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300507 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300508 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
509 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300510
511 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800512}
513
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300514static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300515{
516 clock->m = clock->m1 * clock->m2;
517 clock->p = clock->p1 * clock->p2;
518 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300519 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300520 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
521 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300522
523 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300524}
525
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300526int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300527{
528 clock->m = clock->m1 * clock->m2;
529 clock->p = clock->p1 * clock->p2;
530 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300531 return 0;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300532 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
533 clock->n << 22);
534 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300535
536 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300537}
538
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800539#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000540
541/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800542 * Returns whether the given set of divisors are valid for a given refclk with
543 * the given connectors.
544 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100545static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300546 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300547 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800548{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300549 if (clock->n < limit->n.min || limit->n.max < clock->n)
550 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800551 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400552 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800553 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400554 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400556 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300557
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100558 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200559 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300560 if (clock->m1 <= clock->m2)
561 INTELPllInvalid("m1 <= m2\n");
562
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100563 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200564 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300565 if (clock->p < limit->p.min || limit->p.max < clock->p)
566 INTELPllInvalid("p out of range\n");
567 if (clock->m < limit->m.min || limit->m.max < clock->m)
568 INTELPllInvalid("m out of range\n");
569 }
570
Jesse Barnes79e53942008-11-07 14:24:08 -0800571 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400572 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800573 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
574 * connector, etc., rather than just a single range.
575 */
576 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400577 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800578
579 return true;
580}
581
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300582static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300583i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300584 const struct intel_crtc_state *crtc_state,
585 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800586{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300587 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800588
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300589 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800590 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100591 * For LVDS just rely on its current settings for dual-channel.
592 * We haven't figured out how to reliably set up different
593 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100595 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300596 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300598 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800599 } else {
600 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300601 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800602 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300603 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800604 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300605}
606
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200607/*
608 * Returns a set of divisors for the desired target clock with the given
609 * refclk, or FALSE. The returned values represent the clock equation:
610 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
611 *
612 * Target and reference clocks are specified in kHz.
613 *
614 * If match_clock is provided, then best_clock P divider must match the P
615 * divider from @match_clock used for LVDS downclocking.
616 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300617static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300618i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300619 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300620 int target, int refclk, struct dpll *match_clock,
621 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300622{
623 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300624 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300625 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800626
Akshay Joshi0206e352011-08-16 15:34:10 -0400627 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800628
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300629 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
630
Zhao Yakui42158662009-11-20 11:24:18 +0800631 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
632 clock.m1++) {
633 for (clock.m2 = limit->m2.min;
634 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200635 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800636 break;
637 for (clock.n = limit->n.min;
638 clock.n <= limit->n.max; clock.n++) {
639 for (clock.p1 = limit->p1.min;
640 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800641 int this_err;
642
Imre Deakdccbea32015-06-22 23:35:51 +0300643 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100644 if (!intel_PLL_is_valid(to_i915(dev),
645 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000646 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800647 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800648 if (match_clock &&
649 clock.p != match_clock->p)
650 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800651
652 this_err = abs(clock.dot - target);
653 if (this_err < err) {
654 *best_clock = clock;
655 err = this_err;
656 }
657 }
658 }
659 }
660 }
661
662 return (err != target);
663}
664
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200665/*
666 * Returns a set of divisors for the desired target clock with the given
667 * refclk, or FALSE. The returned values represent the clock equation:
668 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
669 *
670 * Target and reference clocks are specified in kHz.
671 *
672 * If match_clock is provided, then best_clock P divider must match the P
673 * divider from @match_clock used for LVDS downclocking.
674 */
Ma Lingd4906092009-03-18 20:13:27 +0800675static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300676pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200677 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300678 int target, int refclk, struct dpll *match_clock,
679 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200680{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300681 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300682 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200683 int err = target;
684
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200685 memset(best_clock, 0, sizeof(*best_clock));
686
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300687 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
688
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200689 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
690 clock.m1++) {
691 for (clock.m2 = limit->m2.min;
692 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200693 for (clock.n = limit->n.min;
694 clock.n <= limit->n.max; clock.n++) {
695 for (clock.p1 = limit->p1.min;
696 clock.p1 <= limit->p1.max; clock.p1++) {
697 int this_err;
698
Imre Deakdccbea32015-06-22 23:35:51 +0300699 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100700 if (!intel_PLL_is_valid(to_i915(dev),
701 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800702 &clock))
703 continue;
704 if (match_clock &&
705 clock.p != match_clock->p)
706 continue;
707
708 this_err = abs(clock.dot - target);
709 if (this_err < err) {
710 *best_clock = clock;
711 err = this_err;
712 }
713 }
714 }
715 }
716 }
717
718 return (err != target);
719}
720
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200721/*
722 * Returns a set of divisors for the desired target clock with the given
723 * refclk, or FALSE. The returned values represent the clock equation:
724 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200725 *
726 * Target and reference clocks are specified in kHz.
727 *
728 * If match_clock is provided, then best_clock P divider must match the P
729 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200730 */
Ma Lingd4906092009-03-18 20:13:27 +0800731static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300732g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200733 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300734 int target, int refclk, struct dpll *match_clock,
735 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800736{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300737 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300738 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800739 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300740 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400741 /* approximately equals target * 0.00585 */
742 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800743
744 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300745
746 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
747
Ma Lingd4906092009-03-18 20:13:27 +0800748 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200749 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800750 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200751 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800752 for (clock.m1 = limit->m1.max;
753 clock.m1 >= limit->m1.min; clock.m1--) {
754 for (clock.m2 = limit->m2.max;
755 clock.m2 >= limit->m2.min; clock.m2--) {
756 for (clock.p1 = limit->p1.max;
757 clock.p1 >= limit->p1.min; clock.p1--) {
758 int this_err;
759
Imre Deakdccbea32015-06-22 23:35:51 +0300760 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100761 if (!intel_PLL_is_valid(to_i915(dev),
762 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000763 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800764 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000765
766 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800767 if (this_err < err_most) {
768 *best_clock = clock;
769 err_most = this_err;
770 max_n = clock.n;
771 found = true;
772 }
773 }
774 }
775 }
776 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800777 return found;
778}
Ma Lingd4906092009-03-18 20:13:27 +0800779
Imre Deakd5dd62b2015-03-17 11:40:03 +0200780/*
781 * Check if the calculated PLL configuration is more optimal compared to the
782 * best configuration and error found so far. Return the calculated error.
783 */
784static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300785 const struct dpll *calculated_clock,
786 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200787 unsigned int best_error_ppm,
788 unsigned int *error_ppm)
789{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200790 /*
791 * For CHV ignore the error and consider only the P value.
792 * Prefer a bigger P value based on HW requirements.
793 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100794 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200795 *error_ppm = 0;
796
797 return calculated_clock->p > best_clock->p;
798 }
799
Imre Deak24be4e42015-03-17 11:40:04 +0200800 if (WARN_ON_ONCE(!target_freq))
801 return false;
802
Imre Deakd5dd62b2015-03-17 11:40:03 +0200803 *error_ppm = div_u64(1000000ULL *
804 abs(target_freq - calculated_clock->dot),
805 target_freq);
806 /*
807 * Prefer a better P value over a better (smaller) error if the error
808 * is small. Ensure this preference for future configurations too by
809 * setting the error to 0.
810 */
811 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
812 *error_ppm = 0;
813
814 return true;
815 }
816
817 return *error_ppm + 10 < best_error_ppm;
818}
819
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200820/*
821 * Returns a set of divisors for the desired target clock with the given
822 * refclk, or FALSE. The returned values represent the clock equation:
823 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
824 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800825static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300826vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200827 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300828 int target, int refclk, struct dpll *match_clock,
829 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700830{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200831 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300832 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300833 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300834 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300835 /* min update 19.2 MHz */
836 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300837 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700838
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300839 target *= 5; /* fast clock */
840
841 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700842
843 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300844 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300845 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300846 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300847 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300848 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700849 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300850 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200851 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300852
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300853 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
854 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300855
Imre Deakdccbea32015-06-22 23:35:51 +0300856 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300857
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100858 if (!intel_PLL_is_valid(to_i915(dev),
859 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300860 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300861 continue;
862
Imre Deakd5dd62b2015-03-17 11:40:03 +0200863 if (!vlv_PLL_is_optimal(dev, target,
864 &clock,
865 best_clock,
866 bestppm, &ppm))
867 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300868
Imre Deakd5dd62b2015-03-17 11:40:03 +0200869 *best_clock = clock;
870 bestppm = ppm;
871 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700872 }
873 }
874 }
875 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700876
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300877 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700878}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700879
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200880/*
881 * Returns a set of divisors for the desired target clock with the given
882 * refclk, or FALSE. The returned values represent the clock equation:
883 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
884 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300885static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300886chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200887 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300888 int target, int refclk, struct dpll *match_clock,
889 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300890{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200891 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300892 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200893 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300894 struct dpll clock;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300895 uint64_t m2;
896 int found = false;
897
898 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200899 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300900
901 /*
902 * Based on hardware doc, the n always set to 1, and m1 always
903 * set to 2. If requires to support 200Mhz refclk, we need to
904 * revisit this because n may not 1 anymore.
905 */
906 clock.n = 1, clock.m1 = 2;
907 target *= 5; /* fast clock */
908
909 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
910 for (clock.p2 = limit->p2.p2_fast;
911 clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200913 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300914
915 clock.p = clock.p1 * clock.p2;
916
917 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
918 clock.n) << 22, refclk * clock.m1);
919
920 if (m2 > INT_MAX/clock.m1)
921 continue;
922
923 clock.m2 = m2;
924
Imre Deakdccbea32015-06-22 23:35:51 +0300925 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300926
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100927 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300928 continue;
929
Imre Deak9ca3ba02015-03-17 11:40:05 +0200930 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
931 best_error_ppm, &error_ppm))
932 continue;
933
934 *best_clock = clock;
935 best_error_ppm = error_ppm;
936 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300937 }
938 }
939
940 return found;
941}
942
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200943bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300944 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200945{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200946 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300947 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200948
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200949 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200950 target_clock, refclk, NULL, best_clock);
951}
952
Ville Syrjälä525b9312016-10-31 22:37:02 +0200953bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300954{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300955 /* Be paranoid as we can arrive here with only partial
956 * state retrieved from the hardware during setup.
957 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100958 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300959 * as Haswell has gained clock readout/fastboot support.
960 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300961 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300962 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700963 *
964 * FIXME: The intel_crtc->active here should be switched to
965 * crtc->state->active once we have proper CRTC states wired up
966 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300967 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200968 return crtc->active && crtc->base.primary->state->fb &&
969 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300970}
971
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200972enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
973 enum pipe pipe)
974{
Ville Syrjälä98187832016-10-31 22:37:10 +0200975 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200976
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200977 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200978}
979
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200980static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
981 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300982{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200983 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300984 u32 line1, line2;
985 u32 line_mask;
986
Lucas De Marchicf819ef2018-12-12 10:10:43 -0800987 if (IS_GEN(dev_priv, 2))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300988 line_mask = DSL_LINEMASK_GEN2;
989 else
990 line_mask = DSL_LINEMASK_GEN3;
991
992 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +0200993 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300994 line2 = I915_READ(reg) & line_mask;
995
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200996 return line1 != line2;
997}
998
999static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1000{
1001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1002 enum pipe pipe = crtc->pipe;
1003
1004 /* Wait for the display line to settle/start moving */
1005 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1006 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1007 pipe_name(pipe), onoff(state));
1008}
1009
1010static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1011{
1012 wait_for_pipe_scanline_moving(crtc, false);
1013}
1014
1015static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1016{
1017 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001018}
1019
Ville Syrjälä4972f702017-11-29 17:37:32 +02001020static void
1021intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001022{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001023 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001024 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001025
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001026 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001027 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001028 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001029
Keith Packardab7ad7f2010-10-03 00:33:06 -07001030 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001031 if (intel_wait_for_register(dev_priv,
1032 reg, I965_PIPECONF_ACTIVE, 0,
1033 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001034 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001035 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001036 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001037 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001038}
1039
Jesse Barnesb24e7172011-01-04 15:09:30 -08001040/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001041void assert_pll(struct drm_i915_private *dev_priv,
1042 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001043{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001044 u32 val;
1045 bool cur_state;
1046
Ville Syrjälä649636e2015-09-22 19:50:01 +03001047 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001048 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001049 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001050 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001051 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001052}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001053
Jani Nikula23538ef2013-08-27 15:12:22 +03001054/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001055void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001056{
1057 u32 val;
1058 bool cur_state;
1059
Ville Syrjäläa5805162015-05-26 20:42:30 +03001060 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001061 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001062 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001063
1064 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001065 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001066 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001067 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001068}
Jani Nikula23538ef2013-08-27 15:12:22 +03001069
Jesse Barnes040484a2011-01-03 12:14:26 -08001070static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1071 enum pipe pipe, bool state)
1072{
Jesse Barnes040484a2011-01-03 12:14:26 -08001073 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001074 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1075 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001076
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001077 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001078 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001079 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001080 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001081 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001082 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001083 cur_state = !!(val & FDI_TX_ENABLE);
1084 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001085 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001086 "FDI TX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001087 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001088}
1089#define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1090#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1091
1092static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1093 enum pipe pipe, bool state)
1094{
Jesse Barnes040484a2011-01-03 12:14:26 -08001095 u32 val;
1096 bool cur_state;
1097
Ville Syrjälä649636e2015-09-22 19:50:01 +03001098 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001099 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001100 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001101 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001102 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001103}
1104#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1105#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1106
1107static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1108 enum pipe pipe)
1109{
Jesse Barnes040484a2011-01-03 12:14:26 -08001110 u32 val;
1111
1112 /* ILK FDI PLL is always enabled */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001113 if (IS_GEN(dev_priv, 5))
Jesse Barnes040484a2011-01-03 12:14:26 -08001114 return;
1115
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001116 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001117 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001118 return;
1119
Ville Syrjälä649636e2015-09-22 19:50:01 +03001120 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001121 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
Jesse Barnes040484a2011-01-03 12:14:26 -08001122}
1123
Daniel Vetter55607e82013-06-16 21:42:39 +02001124void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1125 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001126{
Jesse Barnes040484a2011-01-03 12:14:26 -08001127 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001128 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001129
Ville Syrjälä649636e2015-09-22 19:50:01 +03001130 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001131 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001132 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001133 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001134 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001135}
1136
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001137void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001138{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001139 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001140 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001141 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001142 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001143
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001144 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001145 return;
1146
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001147 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001148 u32 port_sel;
1149
Imre Deak44cb7342016-08-10 14:07:29 +03001150 pp_reg = PP_CONTROL(0);
1151 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001152
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001153 switch (port_sel) {
1154 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001155 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001156 break;
1157 case PANEL_PORT_SELECT_DPA:
1158 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1159 break;
1160 case PANEL_PORT_SELECT_DPC:
1161 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1162 break;
1163 case PANEL_PORT_SELECT_DPD:
1164 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1165 break;
1166 default:
1167 MISSING_CASE(port_sel);
1168 break;
1169 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001170 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001171 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001172 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001173 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001174 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001175 u32 port_sel;
1176
Imre Deak44cb7342016-08-10 14:07:29 +03001177 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001178 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1179
1180 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001181 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001182 }
1183
1184 val = I915_READ(pp_reg);
1185 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001186 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001187 locked = false;
1188
Rob Clarke2c719b2014-12-15 13:56:32 -05001189 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001190 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001191 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001192}
1193
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001194void assert_pipe(struct drm_i915_private *dev_priv,
1195 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001196{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001197 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001198 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1199 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001200 enum intel_display_power_domain power_domain;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001201
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001202 /* we keep both pipes enabled on 830 */
1203 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001204 state = true;
1205
Imre Deak4feed0e2016-02-12 18:55:14 +02001206 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1207 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001208 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001209 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001210
1211 intel_display_power_put(dev_priv, power_domain);
1212 } else {
1213 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001214 }
1215
Rob Clarke2c719b2014-12-15 13:56:32 -05001216 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001217 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001218 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001219}
1220
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001221static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001222{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001223 enum pipe pipe;
1224 bool cur_state;
1225
1226 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001227
Rob Clarke2c719b2014-12-15 13:56:32 -05001228 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001229 "%s assertion failure (expected %s, current %s)\n",
1230 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001231}
1232
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001233#define assert_plane_enabled(p) assert_plane(p, true)
1234#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001235
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001236static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001237{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1239 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001240
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001241 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1242 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001243}
1244
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001245static void assert_vblank_disabled(struct drm_crtc *crtc)
1246{
Rob Clarke2c719b2014-12-15 13:56:32 -05001247 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001248 drm_crtc_vblank_put(crtc);
1249}
1250
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001251void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1252 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001253{
Jesse Barnes92f25842011-01-04 15:09:34 -08001254 u32 val;
1255 bool enabled;
1256
Ville Syrjälä649636e2015-09-22 19:50:01 +03001257 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001258 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001259 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001260 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1261 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001262}
1263
Jesse Barnes291906f2011-02-02 12:28:03 -08001264static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001265 enum pipe pipe, enum port port,
1266 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001267{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001268 enum pipe port_pipe;
1269 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001270
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001271 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1272
1273 I915_STATE_WARN(state && port_pipe == pipe,
1274 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1275 port_name(port), pipe_name(pipe));
1276
1277 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1278 "IBX PCH DP %c still using transcoder B\n",
1279 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001280}
1281
1282static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001283 enum pipe pipe, enum port port,
1284 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001285{
Ville Syrjälä76203462018-05-14 20:24:21 +03001286 enum pipe port_pipe;
1287 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001288
Ville Syrjälä76203462018-05-14 20:24:21 +03001289 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1290
1291 I915_STATE_WARN(state && port_pipe == pipe,
1292 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1293 port_name(port), pipe_name(pipe));
1294
1295 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1296 "IBX PCH HDMI %c still using transcoder B\n",
1297 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001298}
1299
1300static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1301 enum pipe pipe)
1302{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001303 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001304
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001305 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1306 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1307 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001308
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001309 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1310 port_pipe == pipe,
1311 "PCH VGA enabled on transcoder %c, should be disabled\n",
1312 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001313
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001314 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1315 port_pipe == pipe,
1316 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1317 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001318
Ville Syrjälä3aefb672018-11-08 16:36:35 +02001319 /* PCH SDVOB multiplex with HDMIB */
Ville Syrjälä76203462018-05-14 20:24:21 +03001320 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1321 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1322 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001323}
1324
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001325static void _vlv_enable_pll(struct intel_crtc *crtc,
1326 const struct intel_crtc_state *pipe_config)
1327{
1328 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1329 enum pipe pipe = crtc->pipe;
1330
1331 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1332 POSTING_READ(DPLL(pipe));
1333 udelay(150);
1334
Chris Wilson2c30b432016-06-30 15:32:54 +01001335 if (intel_wait_for_register(dev_priv,
1336 DPLL(pipe),
1337 DPLL_LOCK_VLV,
1338 DPLL_LOCK_VLV,
1339 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001340 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1341}
1342
Ville Syrjäläd288f652014-10-28 13:20:22 +02001343static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001344 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001345{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001346 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001347 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001348
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001349 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001350
Daniel Vetter87442f72013-06-06 00:52:17 +02001351 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001352 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001353
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001354 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1355 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001356
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001357 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1358 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001359}
1360
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001361
1362static void _chv_enable_pll(struct intel_crtc *crtc,
1363 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001364{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001365 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001366 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001367 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001368 u32 tmp;
1369
Ville Syrjäläa5805162015-05-26 20:42:30 +03001370 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001371
1372 /* Enable back the 10bit clock to display controller */
1373 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1374 tmp |= DPIO_DCLKP_EN;
1375 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1376
Ville Syrjälä54433e92015-05-26 20:42:31 +03001377 mutex_unlock(&dev_priv->sb_lock);
1378
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001379 /*
1380 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1381 */
1382 udelay(1);
1383
1384 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001385 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001386
1387 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001388 if (intel_wait_for_register(dev_priv,
1389 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1390 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001391 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001392}
1393
1394static void chv_enable_pll(struct intel_crtc *crtc,
1395 const struct intel_crtc_state *pipe_config)
1396{
1397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1398 enum pipe pipe = crtc->pipe;
1399
1400 assert_pipe_disabled(dev_priv, pipe);
1401
1402 /* PLL is protected by panel, make sure we can write it */
1403 assert_panel_unlocked(dev_priv, pipe);
1404
1405 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1406 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001407
Ville Syrjäläc2317752016-03-15 16:39:56 +02001408 if (pipe != PIPE_A) {
1409 /*
1410 * WaPixelRepeatModeFixForC0:chv
1411 *
1412 * DPLLCMD is AWOL. Use chicken bits to propagate
1413 * the value from DPLLBMD to either pipe B or C.
1414 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001415 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001416 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1417 I915_WRITE(CBR4_VLV, 0);
1418 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1419
1420 /*
1421 * DPLLB VGA mode also seems to cause problems.
1422 * We should always have it disabled.
1423 */
1424 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1425 } else {
1426 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1427 POSTING_READ(DPLL_MD(pipe));
1428 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001429}
1430
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001431static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001432{
1433 struct intel_crtc *crtc;
1434 int count = 0;
1435
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001436 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001437 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001438 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1439 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001440
1441 return count;
1442}
1443
Ville Syrjälä939994d2017-09-13 17:08:56 +03001444static void i9xx_enable_pll(struct intel_crtc *crtc,
1445 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001446{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001447 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001448 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001449 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001450 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001451
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001452 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001453
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001454 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001455 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001456 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001457
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001458 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001459 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001460 /*
1461 * It appears to be important that we don't enable this
1462 * for the current pipe before otherwise configuring the
1463 * PLL. No idea how this should be handled if multiple
1464 * DVO outputs are enabled simultaneosly.
1465 */
1466 dpll |= DPLL_DVO_2X_MODE;
1467 I915_WRITE(DPLL(!crtc->pipe),
1468 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1469 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001470
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001471 /*
1472 * Apparently we need to have VGA mode enabled prior to changing
1473 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1474 * dividers, even though the register value does change.
1475 */
1476 I915_WRITE(reg, 0);
1477
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001478 I915_WRITE(reg, dpll);
1479
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001480 /* Wait for the clocks to stabilize. */
1481 POSTING_READ(reg);
1482 udelay(150);
1483
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001484 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001485 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001486 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001487 } else {
1488 /* The pixel multiplier can only be updated once the
1489 * DPLL is enabled and the clocks are stable.
1490 *
1491 * So write it again.
1492 */
1493 I915_WRITE(reg, dpll);
1494 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001495
1496 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001497 for (i = 0; i < 3; i++) {
1498 I915_WRITE(reg, dpll);
1499 POSTING_READ(reg);
1500 udelay(150); /* wait for warmup */
1501 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001502}
1503
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001504static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001505{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001506 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001508 enum pipe pipe = crtc->pipe;
1509
1510 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001511 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001512 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001513 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001514 I915_WRITE(DPLL(PIPE_B),
1515 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1516 I915_WRITE(DPLL(PIPE_A),
1517 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1518 }
1519
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001520 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001521 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001522 return;
1523
1524 /* Make sure the pipe isn't still relying on us */
1525 assert_pipe_disabled(dev_priv, pipe);
1526
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001527 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001528 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001529}
1530
Jesse Barnesf6071162013-10-01 10:41:38 -07001531static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1532{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001533 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001534
1535 /* Make sure the pipe isn't still relying on us */
1536 assert_pipe_disabled(dev_priv, pipe);
1537
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001538 val = DPLL_INTEGRATED_REF_CLK_VLV |
1539 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1540 if (pipe != PIPE_A)
1541 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1542
Jesse Barnesf6071162013-10-01 10:41:38 -07001543 I915_WRITE(DPLL(pipe), val);
1544 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001545}
1546
1547static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1548{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001549 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001550 u32 val;
1551
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001552 /* Make sure the pipe isn't still relying on us */
1553 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001554
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001555 val = DPLL_SSC_REF_CLK_CHV |
1556 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001557 if (pipe != PIPE_A)
1558 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001559
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001560 I915_WRITE(DPLL(pipe), val);
1561 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001562
Ville Syrjäläa5805162015-05-26 20:42:30 +03001563 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001564
1565 /* Disable 10bit clock to display controller */
1566 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1567 val &= ~DPIO_DCLKP_EN;
1568 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1569
Ville Syrjäläa5805162015-05-26 20:42:30 +03001570 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001571}
1572
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001573void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001574 struct intel_digital_port *dport,
1575 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001576{
1577 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001578 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001579
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001580 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001581 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001582 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001583 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001584 break;
1585 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001586 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001587 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001588 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001589 break;
1590 case PORT_D:
1591 port_mask = DPLL_PORTD_READY_MASK;
1592 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001593 break;
1594 default:
1595 BUG();
1596 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001597
Chris Wilson370004d2016-06-30 15:32:56 +01001598 if (intel_wait_for_register(dev_priv,
1599 dpll_reg, port_mask, expected_mask,
1600 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001601 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001602 port_name(dport->base.port),
1603 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001604}
1605
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001606static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001607{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1610 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001611 i915_reg_t reg;
1612 uint32_t val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001613
Jesse Barnes040484a2011-01-03 12:14:26 -08001614 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001615 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001616
1617 /* FDI must be feeding us bits for PCH ports */
1618 assert_fdi_tx_enabled(dev_priv, pipe);
1619 assert_fdi_rx_enabled(dev_priv, pipe);
1620
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001621 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001622 /* Workaround: Set the timing override bit before enabling the
1623 * pch transcoder. */
1624 reg = TRANS_CHICKEN2(pipe);
1625 val = I915_READ(reg);
1626 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1627 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001628 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001629
Daniel Vetterab9412b2013-05-03 11:49:46 +02001630 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001631 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001632 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001633
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001634 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001635 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001636 * Make the BPC in transcoder be consistent with
1637 * that in pipeconf reg. For HDMI we must use 8bpc
1638 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001639 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001640 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001641 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001642 val |= PIPECONF_8BPC;
1643 else
1644 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001645 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001646
1647 val &= ~TRANS_INTERLACE_MASK;
1648 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001649 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001650 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001651 val |= TRANS_LEGACY_INTERLACED_ILK;
1652 else
1653 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001654 else
1655 val |= TRANS_PROGRESSIVE;
1656
Jesse Barnes040484a2011-01-03 12:14:26 -08001657 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001658 if (intel_wait_for_register(dev_priv,
1659 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1660 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001661 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001662}
1663
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001664static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001665 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001666{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001667 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001668
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001669 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001670 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001671 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001672
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001673 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001674 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001675 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001676 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001677
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001678 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001679 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001680
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001681 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1682 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001683 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001684 else
1685 val |= TRANS_PROGRESSIVE;
1686
Daniel Vetterab9412b2013-05-03 11:49:46 +02001687 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001688 if (intel_wait_for_register(dev_priv,
1689 LPT_TRANSCONF,
1690 TRANS_STATE_ENABLE,
1691 TRANS_STATE_ENABLE,
1692 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001693 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001694}
1695
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001696static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1697 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001698{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001699 i915_reg_t reg;
1700 uint32_t val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001701
1702 /* FDI relies on the transcoder */
1703 assert_fdi_tx_disabled(dev_priv, pipe);
1704 assert_fdi_rx_disabled(dev_priv, pipe);
1705
Jesse Barnes291906f2011-02-02 12:28:03 -08001706 /* Ports must be off as well */
1707 assert_pch_ports_disabled(dev_priv, pipe);
1708
Daniel Vetterab9412b2013-05-03 11:49:46 +02001709 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001710 val = I915_READ(reg);
1711 val &= ~TRANS_ENABLE;
1712 I915_WRITE(reg, val);
1713 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001714 if (intel_wait_for_register(dev_priv,
1715 reg, TRANS_STATE_ENABLE, 0,
1716 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001717 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001718
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001719 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001720 /* Workaround: Clear the timing override chicken bit again. */
1721 reg = TRANS_CHICKEN2(pipe);
1722 val = I915_READ(reg);
1723 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1724 I915_WRITE(reg, val);
1725 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001726}
1727
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001728void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001729{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001730 u32 val;
1731
Daniel Vetterab9412b2013-05-03 11:49:46 +02001732 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001733 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001734 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001735 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001736 if (intel_wait_for_register(dev_priv,
1737 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1738 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001739 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001740
1741 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001742 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001743 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001744 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001745}
1746
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001747enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001748{
1749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1750
Ville Syrjälä65f21302016-10-14 20:02:53 +03001751 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001752 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001753 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001754 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001755}
1756
Ville Syrjälä4972f702017-11-29 17:37:32 +02001757static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001758{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001759 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1761 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001762 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001763 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001764 u32 val;
1765
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001766 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1767
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001768 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001769
Jesse Barnesb24e7172011-01-04 15:09:30 -08001770 /*
1771 * A pipe without a PLL won't actually be able to drive bits from
1772 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1773 * need the check.
1774 */
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001775 if (HAS_GMCH_DISPLAY(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001776 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001777 assert_dsi_pll_enabled(dev_priv);
1778 else
1779 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001780 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001781 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001782 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001783 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001784 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001785 assert_fdi_tx_pll_enabled(dev_priv,
1786 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001787 }
1788 /* FIXME: assert CPU port conditions for SNB+ */
1789 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001790
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001791 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001792 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001793 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001794 /* we keep both pipes enabled on 830 */
1795 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001796 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001797 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001798
1799 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001800 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001801
1802 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001803 * Until the pipe starts PIPEDSL reads will return a stale value,
1804 * which causes an apparent vblank timestamp jump when PIPEDSL
1805 * resets to its proper value. That also messes up the frame count
1806 * when it's derived from the timestamps. So let's wait for the
1807 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001808 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001809 if (dev_priv->drm.max_vblank_count == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001810 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001811}
1812
Ville Syrjälä4972f702017-11-29 17:37:32 +02001813static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001814{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001815 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001817 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001818 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001819 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001820 u32 val;
1821
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001822 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1823
Jesse Barnesb24e7172011-01-04 15:09:30 -08001824 /*
1825 * Make sure planes won't keep trying to pump pixels to us,
1826 * or we might hang the display.
1827 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001828 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001829
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001830 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001831 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001832 if ((val & PIPECONF_ENABLE) == 0)
1833 return;
1834
Ville Syrjälä67adc642014-08-15 01:21:57 +03001835 /*
1836 * Double wide has implications for planes
1837 * so best keep it disabled when not needed.
1838 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001839 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001840 val &= ~PIPECONF_DOUBLE_WIDE;
1841
1842 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001843 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001844 val &= ~PIPECONF_ENABLE;
1845
1846 I915_WRITE(reg, val);
1847 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001848 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001849}
1850
Ville Syrjälä832be822016-01-12 21:08:33 +02001851static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1852{
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001853 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
Ville Syrjälä832be822016-01-12 21:08:33 +02001854}
1855
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001856static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001857intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001858{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001859 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001860 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001861
1862 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001863 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001864 return cpp;
1865 case I915_FORMAT_MOD_X_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001866 if (IS_GEN(dev_priv, 2))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001867 return 128;
1868 else
1869 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001870 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001871 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001872 return 128;
1873 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001874 case I915_FORMAT_MOD_Y_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001875 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001876 return 128;
1877 else
1878 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001879 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001880 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001881 return 128;
1882 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001883 case I915_FORMAT_MOD_Yf_TILED:
1884 switch (cpp) {
1885 case 1:
1886 return 64;
1887 case 2:
1888 case 4:
1889 return 128;
1890 case 8:
1891 case 16:
1892 return 256;
1893 default:
1894 MISSING_CASE(cpp);
1895 return cpp;
1896 }
1897 break;
1898 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001899 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001900 return cpp;
1901 }
1902}
1903
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001904static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001905intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001906{
Ben Widawsky2f075562017-03-24 14:29:48 -07001907 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001908 return 1;
1909 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001910 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001911 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001912}
1913
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001914/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001915static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001916 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001917 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001918{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001919 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1920 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001921
1922 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001923 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001924}
1925
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001926unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001927intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001928 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001929{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001930 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001931
1932 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001933}
1934
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001935unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1936{
1937 unsigned int size = 0;
1938 int i;
1939
1940 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1941 size += rot_info->plane[i].width * rot_info->plane[i].height;
1942
1943 return size;
1944}
1945
Daniel Vetter75c82a52015-10-14 16:51:04 +02001946static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001947intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1948 const struct drm_framebuffer *fb,
1949 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001950{
Chris Wilson7b92c042017-01-14 00:28:26 +00001951 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001952 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001953 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001954 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001955 }
1956}
1957
Ville Syrjäläfabac482017-03-27 21:55:43 +03001958static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1959{
1960 if (IS_I830(dev_priv))
1961 return 16 * 1024;
1962 else if (IS_I85X(dev_priv))
1963 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03001964 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1965 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03001966 else
1967 return 4 * 1024;
1968}
1969
Ville Syrjälä603525d2016-01-12 21:08:37 +02001970static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001971{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001972 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001973 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02001974 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08001975 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001976 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001977 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001978 return 4 * 1024;
1979 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03001980 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001981}
1982
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001983static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001984 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001985{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001986 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1987
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001988 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001989 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001990 return 4096;
1991
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001992 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001993 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02001994 return intel_linear_alignment(dev_priv);
1995 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001996 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001997 return 256 * 1024;
1998 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001999 case I915_FORMAT_MOD_Y_TILED_CCS:
2000 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002001 case I915_FORMAT_MOD_Y_TILED:
2002 case I915_FORMAT_MOD_Yf_TILED:
2003 return 1 * 1024 * 1024;
2004 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002005 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002006 return 0;
2007 }
2008}
2009
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002010static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2011{
2012 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2013 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2014
Ville Syrjälä32febd92018-02-21 18:02:33 +02002015 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002016}
2017
Chris Wilson058d88c2016-08-15 10:49:06 +01002018struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002019intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002020 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002021 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002022 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002023{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002024 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002025 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002026 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson058d88c2016-08-15 10:49:06 +01002027 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002028 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002029 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002030
Matt Roperebcdd392014-07-09 16:22:11 -07002031 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2032
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002033 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002034
Chris Wilson693db182013-03-05 14:52:39 +00002035 /* Note that the w/a also requires 64 PTE of padding following the
2036 * bo. We currently fill all unused PTE with the shadow page and so
2037 * we should always have valid PTE following the scanout preventing
2038 * the VT-d warning.
2039 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002040 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002041 alignment = 256 * 1024;
2042
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002043 /*
2044 * Global gtt pte registers are special registers which actually forward
2045 * writes to a chunk of system memory. Which means that there is no risk
2046 * that the register values disappear as soon as we call
2047 * intel_runtime_pm_put(), so it is correct to wrap only the
2048 * pin/unpin/fence and not more.
2049 */
2050 intel_runtime_pm_get(dev_priv);
2051
Daniel Vetter9db529a2017-08-08 10:08:28 +02002052 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2053
Chris Wilson59354852018-02-20 13:42:06 +00002054 pinctl = 0;
2055
2056 /* Valleyview is definitely limited to scanning out the first
2057 * 512MiB. Lets presume this behaviour was inherited from the
2058 * g4x display engine and that all earlier gen are similarly
2059 * limited. Testing suggests that it is a little more
2060 * complicated than this. For example, Cherryview appears quite
2061 * happy to scanout from anywhere within its global aperture.
2062 */
2063 if (HAS_GMCH_DISPLAY(dev_priv))
2064 pinctl |= PIN_MAPPABLE;
2065
2066 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002067 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002068 if (IS_ERR(vma))
2069 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002070
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002071 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002072 int ret;
2073
Chris Wilson49ef5292016-08-18 17:17:00 +01002074 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2075 * fence, whereas 965+ only requires a fence if using
2076 * framebuffer compression. For simplicity, we always, when
2077 * possible, install a fence as the cost is not that onerous.
2078 *
2079 * If we fail to fence the tiled scanout, then either the
2080 * modeset will reject the change (which is highly unlikely as
2081 * the affected systems, all but one, do not have unmappable
2082 * space) or we will not be able to enable full powersaving
2083 * techniques (also likely not to apply due to various limits
2084 * FBC and the like impose on the size of the buffer, which
2085 * presumably we violated anyway with this unmappable buffer).
2086 * Anyway, it is presumably better to stumble onwards with
2087 * something and try to run the system in a "less than optimal"
2088 * mode that matches the user configuration.
2089 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002090 ret = i915_vma_pin_fence(vma);
2091 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002092 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002093 vma = ERR_PTR(ret);
2094 goto err;
2095 }
2096
2097 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002098 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002099 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002100
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002101 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002102err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002103 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2104
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002105 intel_runtime_pm_put(dev_priv);
Chris Wilson058d88c2016-08-15 10:49:06 +01002106 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002107}
2108
Chris Wilson59354852018-02-20 13:42:06 +00002109void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002110{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002111 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002112
Chris Wilson59354852018-02-20 13:42:06 +00002113 if (flags & PLANE_HAS_FENCE)
2114 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002115 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002116 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002117}
2118
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002119static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002120 unsigned int rotation)
2121{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002122 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002123 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002124 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002125 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002126}
2127
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002128/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002129 * Convert the x/y offsets into a linear offset.
2130 * Only valid with 0/180 degree rotation, which is fine since linear
2131 * offset is only used with linear buffers on pre-hsw and tiled buffers
2132 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2133 */
2134u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002135 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002136 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002137{
Ville Syrjälä29490562016-01-20 18:02:50 +02002138 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002139 unsigned int cpp = fb->format->cpp[color_plane];
2140 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002141
2142 return y * pitch + x * cpp;
2143}
2144
2145/*
2146 * Add the x/y offsets derived from fb->offsets[] to the user
2147 * specified plane src x/y offsets. The resulting x/y offsets
2148 * specify the start of scanout from the beginning of the gtt mapping.
2149 */
2150void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002151 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002152 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002153
2154{
Ville Syrjälä29490562016-01-20 18:02:50 +02002155 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2156 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002157
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002158 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002159 *x += intel_fb->rotated[color_plane].x;
2160 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002161 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002162 *x += intel_fb->normal[color_plane].x;
2163 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002164 }
2165}
2166
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002167static u32 intel_adjust_tile_offset(int *x, int *y,
2168 unsigned int tile_width,
2169 unsigned int tile_height,
2170 unsigned int tile_size,
2171 unsigned int pitch_tiles,
2172 u32 old_offset,
2173 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002174{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002175 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002176 unsigned int tiles;
2177
2178 WARN_ON(old_offset & (tile_size - 1));
2179 WARN_ON(new_offset & (tile_size - 1));
2180 WARN_ON(new_offset > old_offset);
2181
2182 tiles = (old_offset - new_offset) / tile_size;
2183
2184 *y += tiles / pitch_tiles * tile_height;
2185 *x += tiles % pitch_tiles * tile_width;
2186
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002187 /* minimize x in case it got needlessly big */
2188 *y += *x / pitch_pixels * tile_height;
2189 *x %= pitch_pixels;
2190
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002191 return new_offset;
2192}
2193
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002194static bool is_surface_linear(u64 modifier, int color_plane)
2195{
2196 return modifier == DRM_FORMAT_MOD_LINEAR;
2197}
2198
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002199static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002200 const struct drm_framebuffer *fb,
2201 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002202 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002203 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002204 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002205{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002206 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002207 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002208
2209 WARN_ON(new_offset > old_offset);
2210
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002211 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002212 unsigned int tile_size, tile_width, tile_height;
2213 unsigned int pitch_tiles;
2214
2215 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002216 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002217
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002218 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002219 pitch_tiles = pitch / tile_height;
2220 swap(tile_width, tile_height);
2221 } else {
2222 pitch_tiles = pitch / (tile_width * cpp);
2223 }
2224
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002225 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2226 tile_size, pitch_tiles,
2227 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002228 } else {
2229 old_offset += *y * pitch + *x * cpp;
2230
2231 *y = (old_offset - new_offset) / pitch;
2232 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2233 }
2234
2235 return new_offset;
2236}
2237
2238/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002239 * Adjust the tile offset by moving the difference into
2240 * the x/y offsets.
2241 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002242static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2243 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002244 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002245 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002246{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002247 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002248 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002249 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002250 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002251}
2252
2253/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002254 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002255 * x, y. bytes per pixel is assumed to be a power-of-two.
2256 *
2257 * In the 90/270 rotated case, x and y are assumed
2258 * to be already rotated to match the rotated GTT view, and
2259 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002260 *
2261 * This function is used when computing the derived information
2262 * under intel_framebuffer, so using any of that information
2263 * here is not allowed. Anything under drm_framebuffer can be
2264 * used. This is why the user has to pass in the pitch since it
2265 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002266 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002267static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2268 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002269 const struct drm_framebuffer *fb,
2270 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002271 unsigned int pitch,
2272 unsigned int rotation,
2273 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002274{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002275 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002276 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002277
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002278 if (alignment)
2279 alignment--;
2280
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002281 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002282 unsigned int tile_size, tile_width, tile_height;
2283 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002284
Ville Syrjäläd8433102016-01-12 21:08:35 +02002285 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002286 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002287
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002288 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002289 pitch_tiles = pitch / tile_height;
2290 swap(tile_width, tile_height);
2291 } else {
2292 pitch_tiles = pitch / (tile_width * cpp);
2293 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002294
Ville Syrjäläd8433102016-01-12 21:08:35 +02002295 tile_rows = *y / tile_height;
2296 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002297
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002298 tiles = *x / tile_width;
2299 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002300
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002301 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2302 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002303
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002304 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2305 tile_size, pitch_tiles,
2306 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002307 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002308 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002309 offset_aligned = offset & ~alignment;
2310
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002311 *y = (offset & alignment) / pitch;
2312 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002313 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002314
2315 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002316}
2317
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002318static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2319 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002320 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002321{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002322 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2323 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002324 const struct drm_framebuffer *fb = state->base.fb;
2325 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002326 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002327 u32 alignment;
2328
2329 if (intel_plane->id == PLANE_CURSOR)
2330 alignment = intel_cursor_alignment(dev_priv);
2331 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002332 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002333
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002334 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002335 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002336}
2337
Ville Syrjälä303ba692017-08-24 22:10:49 +03002338/* Convert the fb->offset[] into x/y offsets */
2339static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002340 const struct drm_framebuffer *fb,
2341 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002342{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002343 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002344 unsigned int height;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002345
Ville Syrjälä303ba692017-08-24 22:10:49 +03002346 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002347 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2348 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2349 fb->offsets[color_plane], color_plane);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002350 return -EINVAL;
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002351 }
2352
2353 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2354 height = ALIGN(height, intel_tile_height(fb, color_plane));
2355
2356 /* Catch potential overflows early */
2357 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2358 fb->offsets[color_plane])) {
2359 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2360 fb->offsets[color_plane], fb->pitches[color_plane],
2361 color_plane);
2362 return -ERANGE;
2363 }
Ville Syrjälä303ba692017-08-24 22:10:49 +03002364
2365 *x = 0;
2366 *y = 0;
2367
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002368 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002369 fb, color_plane, DRM_MODE_ROTATE_0,
2370 fb->pitches[color_plane],
2371 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002372
2373 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002374}
2375
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002376static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2377{
2378 switch (fb_modifier) {
2379 case I915_FORMAT_MOD_X_TILED:
2380 return I915_TILING_X;
2381 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002382 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002383 return I915_TILING_Y;
2384 default:
2385 return I915_TILING_NONE;
2386 }
2387}
2388
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002389/*
2390 * From the Sky Lake PRM:
2391 * "The Color Control Surface (CCS) contains the compression status of
2392 * the cache-line pairs. The compression state of the cache-line pair
2393 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2394 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2395 * cache-line-pairs. CCS is always Y tiled."
2396 *
2397 * Since cache line pairs refers to horizontally adjacent cache lines,
2398 * each cache line in the CCS corresponds to an area of 32x16 cache
2399 * lines on the main surface. Since each pixel is 4 bytes, this gives
2400 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2401 * main surface.
2402 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002403static const struct drm_format_info ccs_formats[] = {
2404 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2405 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2406 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2407 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2408};
2409
2410static const struct drm_format_info *
2411lookup_format_info(const struct drm_format_info formats[],
2412 int num_formats, u32 format)
2413{
2414 int i;
2415
2416 for (i = 0; i < num_formats; i++) {
2417 if (formats[i].format == format)
2418 return &formats[i];
2419 }
2420
2421 return NULL;
2422}
2423
2424static const struct drm_format_info *
2425intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2426{
2427 switch (cmd->modifier[0]) {
2428 case I915_FORMAT_MOD_Y_TILED_CCS:
2429 case I915_FORMAT_MOD_Yf_TILED_CCS:
2430 return lookup_format_info(ccs_formats,
2431 ARRAY_SIZE(ccs_formats),
2432 cmd->pixel_format);
2433 default:
2434 return NULL;
2435 }
2436}
2437
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002438bool is_ccs_modifier(u64 modifier)
2439{
2440 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2441 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2442}
2443
Ville Syrjälä6687c902015-09-15 13:16:41 +03002444static int
2445intel_fill_fb_info(struct drm_i915_private *dev_priv,
2446 struct drm_framebuffer *fb)
2447{
2448 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2449 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002450 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002451 u32 gtt_offset_rotated = 0;
2452 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002453 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002454 unsigned int tile_size = intel_tile_size(dev_priv);
2455
2456 for (i = 0; i < num_planes; i++) {
2457 unsigned int width, height;
2458 unsigned int cpp, size;
2459 u32 offset;
2460 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002461 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002462
Ville Syrjälä353c8592016-12-14 23:30:57 +02002463 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002464 width = drm_framebuffer_plane_width(fb->width, fb, i);
2465 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002466
Ville Syrjälä303ba692017-08-24 22:10:49 +03002467 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2468 if (ret) {
2469 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2470 i, fb->offsets[i]);
2471 return ret;
2472 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002473
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002474 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002475 int hsub = fb->format->hsub;
2476 int vsub = fb->format->vsub;
2477 int tile_width, tile_height;
2478 int main_x, main_y;
2479 int ccs_x, ccs_y;
2480
2481 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002482 tile_width *= hsub;
2483 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002484
Ville Syrjälä303ba692017-08-24 22:10:49 +03002485 ccs_x = (x * hsub) % tile_width;
2486 ccs_y = (y * vsub) % tile_height;
2487 main_x = intel_fb->normal[0].x % tile_width;
2488 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002489
2490 /*
2491 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2492 * x/y offsets must match between CCS and the main surface.
2493 */
2494 if (main_x != ccs_x || main_y != ccs_y) {
2495 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2496 main_x, main_y,
2497 ccs_x, ccs_y,
2498 intel_fb->normal[0].x,
2499 intel_fb->normal[0].y,
2500 x, y);
2501 return -EINVAL;
2502 }
2503 }
2504
Ville Syrjälä6687c902015-09-15 13:16:41 +03002505 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002506 * The fence (if used) is aligned to the start of the object
2507 * so having the framebuffer wrap around across the edge of the
2508 * fenced region doesn't really work. We have no API to configure
2509 * the fence start offset within the object (nor could we probably
2510 * on gen2/3). So it's just easier if we just require that the
2511 * fb layout agrees with the fence layout. We already check that the
2512 * fb stride matches the fence stride elsewhere.
2513 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002514 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002515 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002516 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2517 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002518 return -EINVAL;
2519 }
2520
2521 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002522 * First pixel of the framebuffer from
2523 * the start of the normal gtt mapping.
2524 */
2525 intel_fb->normal[i].x = x;
2526 intel_fb->normal[i].y = y;
2527
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002528 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2529 fb->pitches[i],
2530 DRM_MODE_ROTATE_0,
2531 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002532 offset /= tile_size;
2533
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002534 if (!is_surface_linear(fb->modifier, i)) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002535 unsigned int tile_width, tile_height;
2536 unsigned int pitch_tiles;
2537 struct drm_rect r;
2538
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002539 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002540
2541 rot_info->plane[i].offset = offset;
2542 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2543 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2544 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2545
2546 intel_fb->rotated[i].pitch =
2547 rot_info->plane[i].height * tile_height;
2548
2549 /* how many tiles does this plane need */
2550 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2551 /*
2552 * If the plane isn't horizontally tile aligned,
2553 * we need one more tile.
2554 */
2555 if (x != 0)
2556 size++;
2557
2558 /* rotate the x/y offsets to match the GTT view */
2559 r.x1 = x;
2560 r.y1 = y;
2561 r.x2 = x + width;
2562 r.y2 = y + height;
2563 drm_rect_rotate(&r,
2564 rot_info->plane[i].width * tile_width,
2565 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002566 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002567 x = r.x1;
2568 y = r.y1;
2569
2570 /* rotate the tile dimensions to match the GTT view */
2571 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2572 swap(tile_width, tile_height);
2573
2574 /*
2575 * We only keep the x/y offsets, so push all of the
2576 * gtt offset into the x/y offsets.
2577 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002578 intel_adjust_tile_offset(&x, &y,
2579 tile_width, tile_height,
2580 tile_size, pitch_tiles,
2581 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002582
2583 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2584
2585 /*
2586 * First pixel of the framebuffer from
2587 * the start of the rotated gtt mapping.
2588 */
2589 intel_fb->rotated[i].x = x;
2590 intel_fb->rotated[i].y = y;
2591 } else {
2592 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2593 x * cpp, tile_size);
2594 }
2595
2596 /* how many tiles in total needed in the bo */
2597 max_size = max(max_size, offset + size);
2598 }
2599
Ville Syrjälä4e050472018-09-12 21:04:43 +03002600 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2601 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2602 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002603 return -EINVAL;
2604 }
2605
2606 return 0;
2607}
2608
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002609static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002610{
2611 switch (format) {
2612 case DISPPLANE_8BPP:
2613 return DRM_FORMAT_C8;
2614 case DISPPLANE_BGRX555:
2615 return DRM_FORMAT_XRGB1555;
2616 case DISPPLANE_BGRX565:
2617 return DRM_FORMAT_RGB565;
2618 default:
2619 case DISPPLANE_BGRX888:
2620 return DRM_FORMAT_XRGB8888;
2621 case DISPPLANE_RGBX888:
2622 return DRM_FORMAT_XBGR8888;
2623 case DISPPLANE_BGRX101010:
2624 return DRM_FORMAT_XRGB2101010;
2625 case DISPPLANE_RGBX101010:
2626 return DRM_FORMAT_XBGR2101010;
2627 }
2628}
2629
Mahesh Kumarddf34312018-04-09 09:11:03 +05302630int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002631{
2632 switch (format) {
2633 case PLANE_CTL_FORMAT_RGB_565:
2634 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302635 case PLANE_CTL_FORMAT_NV12:
2636 return DRM_FORMAT_NV12;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002637 default:
2638 case PLANE_CTL_FORMAT_XRGB_8888:
2639 if (rgb_order) {
2640 if (alpha)
2641 return DRM_FORMAT_ABGR8888;
2642 else
2643 return DRM_FORMAT_XBGR8888;
2644 } else {
2645 if (alpha)
2646 return DRM_FORMAT_ARGB8888;
2647 else
2648 return DRM_FORMAT_XRGB8888;
2649 }
2650 case PLANE_CTL_FORMAT_XRGB_2101010:
2651 if (rgb_order)
2652 return DRM_FORMAT_XBGR2101010;
2653 else
2654 return DRM_FORMAT_XRGB2101010;
2655 }
2656}
2657
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002658static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002659intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2660 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002661{
2662 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002663 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002664 struct drm_i915_gem_object *obj = NULL;
2665 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002666 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002667 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2668 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2669 PAGE_SIZE);
2670
2671 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002672
Chris Wilsonff2652e2014-03-10 08:07:02 +00002673 if (plane_config->size == 0)
2674 return false;
2675
Paulo Zanoni3badb492015-09-23 12:52:23 -03002676 /* If the FB is too big, just don't use it since fbdev is not very
2677 * important and we should probably use that space with FBC or other
2678 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002679 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002680 return false;
2681
Imre Deak914a4fd2018-10-16 19:00:11 +03002682 switch (fb->modifier) {
2683 case DRM_FORMAT_MOD_LINEAR:
2684 case I915_FORMAT_MOD_X_TILED:
2685 case I915_FORMAT_MOD_Y_TILED:
2686 break;
2687 default:
2688 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2689 fb->modifier);
2690 return false;
2691 }
2692
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002693 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002694 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002695 base_aligned,
2696 base_aligned,
2697 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002698 mutex_unlock(&dev->struct_mutex);
2699 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002700 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002701
Imre Deak914a4fd2018-10-16 19:00:11 +03002702 switch (plane_config->tiling) {
2703 case I915_TILING_NONE:
2704 break;
2705 case I915_TILING_X:
2706 case I915_TILING_Y:
2707 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2708 break;
2709 default:
2710 MISSING_CASE(plane_config->tiling);
2711 return false;
2712 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002713
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002714 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002715 mode_cmd.width = fb->width;
2716 mode_cmd.height = fb->height;
2717 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002718 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002719 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002720
Chris Wilson24dbf512017-02-15 10:59:18 +00002721 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002722 DRM_DEBUG_KMS("intel fb init failed\n");
2723 goto out_unref_obj;
2724 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002725
Jesse Barnes484b41d2014-03-07 08:57:55 -08002726
Daniel Vetterf6936e22015-03-26 12:17:05 +01002727 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002728 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002729
2730out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002731 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002732 return false;
2733}
2734
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002735static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002736intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2737 struct intel_plane_state *plane_state,
2738 bool visible)
2739{
2740 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2741
2742 plane_state->base.visible = visible;
2743
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002744 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002745 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002746 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002747 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002748}
2749
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002750static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2751{
2752 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2753 struct drm_plane *plane;
2754
2755 /*
2756 * Active_planes aliases if multiple "primary" or cursor planes
2757 * have been used on the same (or wrong) pipe. plane_mask uses
2758 * unique ids, hence we can use that to reconstruct active_planes.
2759 */
2760 crtc_state->active_planes = 0;
2761
2762 drm_for_each_plane_mask(plane, &dev_priv->drm,
2763 crtc_state->base.plane_mask)
2764 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2765}
2766
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002767static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2768 struct intel_plane *plane)
2769{
2770 struct intel_crtc_state *crtc_state =
2771 to_intel_crtc_state(crtc->base.state);
2772 struct intel_plane_state *plane_state =
2773 to_intel_plane_state(plane->base.state);
2774
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002775 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2776 plane->base.base.id, plane->base.name,
2777 crtc->base.base.id, crtc->base.name);
2778
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002779 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002780 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002781
2782 if (plane->id == PLANE_PRIMARY)
2783 intel_pre_disable_primary_noatomic(&crtc->base);
2784
2785 trace_intel_disable_plane(&plane->base, crtc);
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02002786 plane->disable_plane(plane, crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002787}
2788
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002789static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002790intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2791 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002792{
2793 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002794 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002795 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002796 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002797 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002798 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002799 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002800 struct intel_plane_state *intel_state =
2801 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002802 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002803
Damien Lespiau2d140302015-02-05 17:22:18 +00002804 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002805 return;
2806
Daniel Vetterf6936e22015-03-26 12:17:05 +01002807 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002808 fb = &plane_config->fb->base;
2809 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002810 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002811
Damien Lespiau2d140302015-02-05 17:22:18 +00002812 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002813
2814 /*
2815 * Failed to alloc the obj, check to see if we should share
2816 * an fb with another CRTC instead
2817 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002818 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002819 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002820
2821 if (c == &intel_crtc->base)
2822 continue;
2823
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002824 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002825 continue;
2826
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002827 state = to_intel_plane_state(c->primary->state);
2828 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002829 continue;
2830
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002831 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002832 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302833 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002834 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002835 }
2836 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002837
Matt Roper200757f2015-12-03 11:37:36 -08002838 /*
2839 * We've failed to reconstruct the BIOS FB. Current display state
2840 * indicates that the primary plane is visible, but has a NULL FB,
2841 * which will lead to problems later if we don't fix it up. The
2842 * simplest solution is to just disable the primary plane now and
2843 * pretend the BIOS never had it enabled.
2844 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002845 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002846
Daniel Vetter88595ac2015-03-26 12:42:24 +01002847 return;
2848
2849valid_fb:
Ville Syrjäläf43348a2018-11-20 15:54:50 +02002850 intel_state->base.rotation = plane_config->rotation;
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002851 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2852 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002853 intel_state->color_plane[0].stride =
2854 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2855
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002856 mutex_lock(&dev->struct_mutex);
2857 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002858 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002859 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002860 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002861 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002862 mutex_unlock(&dev->struct_mutex);
2863 if (IS_ERR(intel_state->vma)) {
2864 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2865 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2866
2867 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302868 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002869 return;
2870 }
2871
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002872 obj = intel_fb_obj(fb);
2873 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2874
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002875 plane_state->src_x = 0;
2876 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002877 plane_state->src_w = fb->width << 16;
2878 plane_state->src_h = fb->height << 16;
2879
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002880 plane_state->crtc_x = 0;
2881 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002882 plane_state->crtc_w = fb->width;
2883 plane_state->crtc_h = fb->height;
2884
Rob Clark1638d302016-11-05 11:08:08 -04002885 intel_state->base.src = drm_plane_state_src(plane_state);
2886 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002887
Chris Wilson3e510a82016-08-05 10:14:23 +01002888 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002889 dev_priv->preserve_bios_swizzle = true;
2890
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002891 plane_state->fb = fb;
2892 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002893
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002894 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2895 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002896}
2897
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002898static int skl_max_plane_width(const struct drm_framebuffer *fb,
2899 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002900 unsigned int rotation)
2901{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002902 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002903
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002904 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002905 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002906 case I915_FORMAT_MOD_X_TILED:
2907 switch (cpp) {
2908 case 8:
2909 return 4096;
2910 case 4:
2911 case 2:
2912 case 1:
2913 return 8192;
2914 default:
2915 MISSING_CASE(cpp);
2916 break;
2917 }
2918 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002919 case I915_FORMAT_MOD_Y_TILED_CCS:
2920 case I915_FORMAT_MOD_Yf_TILED_CCS:
2921 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002922 case I915_FORMAT_MOD_Y_TILED:
2923 case I915_FORMAT_MOD_Yf_TILED:
2924 switch (cpp) {
2925 case 8:
2926 return 2048;
2927 case 4:
2928 return 4096;
2929 case 2:
2930 case 1:
2931 return 8192;
2932 default:
2933 MISSING_CASE(cpp);
2934 break;
2935 }
2936 break;
2937 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002938 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002939 }
2940
2941 return 2048;
2942}
2943
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002944static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2945 int main_x, int main_y, u32 main_offset)
2946{
2947 const struct drm_framebuffer *fb = plane_state->base.fb;
2948 int hsub = fb->format->hsub;
2949 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002950 int aux_x = plane_state->color_plane[1].x;
2951 int aux_y = plane_state->color_plane[1].y;
2952 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002953 u32 alignment = intel_surf_alignment(fb, 1);
2954
2955 while (aux_offset >= main_offset && aux_y <= main_y) {
2956 int x, y;
2957
2958 if (aux_x == main_x && aux_y == main_y)
2959 break;
2960
2961 if (aux_offset == 0)
2962 break;
2963
2964 x = aux_x / hsub;
2965 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002966 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2967 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002968 aux_x = x * hsub + aux_x % hsub;
2969 aux_y = y * vsub + aux_y % vsub;
2970 }
2971
2972 if (aux_x != main_x || aux_y != main_y)
2973 return false;
2974
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002975 plane_state->color_plane[1].offset = aux_offset;
2976 plane_state->color_plane[1].x = aux_x;
2977 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002978
2979 return true;
2980}
2981
Ville Syrjälä73266592018-09-07 18:24:11 +03002982static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002983{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002984 const struct drm_framebuffer *fb = plane_state->base.fb;
2985 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02002986 int x = plane_state->base.src.x1 >> 16;
2987 int y = plane_state->base.src.y1 >> 16;
2988 int w = drm_rect_width(&plane_state->base.src) >> 16;
2989 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002990 int max_width = skl_max_plane_width(fb, 0, rotation);
2991 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002992 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002993
2994 if (w > max_width || h > max_height) {
2995 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2996 w, h, max_width, max_height);
2997 return -EINVAL;
2998 }
2999
3000 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003001 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003002 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003003
3004 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02003005 * AUX surface offset is specified as the distance from the
3006 * main surface offset, and it must be non-negative. Make
3007 * sure that is what we will get.
3008 */
3009 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003010 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3011 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02003012
3013 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003014 * When using an X-tiled surface, the plane blows up
3015 * if the x offset + width exceed the stride.
3016 *
3017 * TODO: linear and Y-tiled seem fine, Yf untested,
3018 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003019 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003020 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003021
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003022 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003023 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003024 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003025 return -EINVAL;
3026 }
3027
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003028 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3029 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003030 }
3031 }
3032
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003033 /*
3034 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3035 * they match with the main surface x/y offsets.
3036 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003037 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003038 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3039 if (offset == 0)
3040 break;
3041
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003042 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3043 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003044 }
3045
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003046 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003047 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3048 return -EINVAL;
3049 }
3050 }
3051
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003052 plane_state->color_plane[0].offset = offset;
3053 plane_state->color_plane[0].x = x;
3054 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003055
3056 return 0;
3057}
3058
Ville Syrjälä8d970652016-01-28 16:30:28 +02003059static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3060{
3061 const struct drm_framebuffer *fb = plane_state->base.fb;
3062 unsigned int rotation = plane_state->base.rotation;
3063 int max_width = skl_max_plane_width(fb, 1, rotation);
3064 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003065 int x = plane_state->base.src.x1 >> 17;
3066 int y = plane_state->base.src.y1 >> 17;
3067 int w = drm_rect_width(&plane_state->base.src) >> 17;
3068 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003069 u32 offset;
3070
3071 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003072 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003073
3074 /* FIXME not quite sure how/if these apply to the chroma plane */
3075 if (w > max_width || h > max_height) {
3076 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3077 w, h, max_width, max_height);
3078 return -EINVAL;
3079 }
3080
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003081 plane_state->color_plane[1].offset = offset;
3082 plane_state->color_plane[1].x = x;
3083 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003084
3085 return 0;
3086}
3087
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003088static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3089{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003090 const struct drm_framebuffer *fb = plane_state->base.fb;
3091 int src_x = plane_state->base.src.x1 >> 16;
3092 int src_y = plane_state->base.src.y1 >> 16;
3093 int hsub = fb->format->hsub;
3094 int vsub = fb->format->vsub;
3095 int x = src_x / hsub;
3096 int y = src_y / vsub;
3097 u32 offset;
3098
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003099 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003100 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003101
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003102 plane_state->color_plane[1].offset = offset;
3103 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3104 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003105
3106 return 0;
3107}
3108
Ville Syrjälä73266592018-09-07 18:24:11 +03003109int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003110{
3111 const struct drm_framebuffer *fb = plane_state->base.fb;
3112 unsigned int rotation = plane_state->base.rotation;
3113 int ret;
3114
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003115 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003116 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3117 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3118
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003119 ret = intel_plane_check_stride(plane_state);
3120 if (ret)
3121 return ret;
3122
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003123 if (!plane_state->base.visible)
3124 return 0;
3125
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003126 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003127 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003128 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003129 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003130 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003131
Ville Syrjälä8d970652016-01-28 16:30:28 +02003132 /*
3133 * Handle the AUX surface first since
3134 * the main surface setup depends on it.
3135 */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003136 if (fb->format->format == DRM_FORMAT_NV12) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003137 ret = skl_check_nv12_aux_surface(plane_state);
3138 if (ret)
3139 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003140 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003141 ret = skl_check_ccs_aux_surface(plane_state);
3142 if (ret)
3143 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003144 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003145 plane_state->color_plane[1].offset = ~0xfff;
3146 plane_state->color_plane[1].x = 0;
3147 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003148 }
3149
Ville Syrjälä73266592018-09-07 18:24:11 +03003150 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003151 if (ret)
3152 return ret;
3153
3154 return 0;
3155}
3156
Ville Syrjäläddd57132018-09-07 18:24:02 +03003157unsigned int
3158i9xx_plane_max_stride(struct intel_plane *plane,
3159 u32 pixel_format, u64 modifier,
3160 unsigned int rotation)
3161{
3162 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3163
3164 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3165 return 32*1024;
3166 } else if (INTEL_GEN(dev_priv) >= 4) {
3167 if (modifier == I915_FORMAT_MOD_X_TILED)
3168 return 16*1024;
3169 else
3170 return 32*1024;
3171 } else if (INTEL_GEN(dev_priv) >= 3) {
3172 if (modifier == I915_FORMAT_MOD_X_TILED)
3173 return 8*1024;
3174 else
3175 return 16*1024;
3176 } else {
3177 if (plane->i9xx_plane == PLANE_C)
3178 return 4*1024;
3179 else
3180 return 8*1024;
3181 }
3182}
3183
Ville Syrjälä7145f602017-03-23 21:27:07 +02003184static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3185 const struct intel_plane_state *plane_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003186{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003187 struct drm_i915_private *dev_priv =
3188 to_i915(plane_state->base.plane->dev);
3189 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3190 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02003191 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003192 u32 dspcntr;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003193
Ville Syrjälä7145f602017-03-23 21:27:07 +02003194 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003195
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003196 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3197 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjälä7145f602017-03-23 21:27:07 +02003198 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003199
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003200 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3201 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003202
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003203 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003204 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003205
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003206 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003207 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003208 dspcntr |= DISPPLANE_8BPP;
3209 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003210 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003211 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003212 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003213 case DRM_FORMAT_RGB565:
3214 dspcntr |= DISPPLANE_BGRX565;
3215 break;
3216 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003217 dspcntr |= DISPPLANE_BGRX888;
3218 break;
3219 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003220 dspcntr |= DISPPLANE_RGBX888;
3221 break;
3222 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003223 dspcntr |= DISPPLANE_BGRX101010;
3224 break;
3225 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003226 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003227 break;
3228 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003229 MISSING_CASE(fb->format->format);
3230 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003231 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003232
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003233 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003234 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003235 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003236
Robert Fossc2c446a2017-05-19 16:50:17 -04003237 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003238 dspcntr |= DISPPLANE_ROTATE_180;
3239
Robert Fossc2c446a2017-05-19 16:50:17 -04003240 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003241 dspcntr |= DISPPLANE_MIRROR;
3242
Ville Syrjälä7145f602017-03-23 21:27:07 +02003243 return dspcntr;
3244}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003245
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003246int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003247{
3248 struct drm_i915_private *dev_priv =
3249 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003250 const struct drm_framebuffer *fb = plane_state->base.fb;
3251 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003252 int src_x = plane_state->base.src.x1 >> 16;
3253 int src_y = plane_state->base.src.y1 >> 16;
3254 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003255 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003256
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003257 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003258 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3259
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003260 ret = intel_plane_check_stride(plane_state);
3261 if (ret)
3262 return ret;
3263
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003264 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003265
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003266 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003267 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3268 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003269 else
3270 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003271
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003272 /* HSW/BDW do this automagically in hardware */
3273 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003274 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3275 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3276
Robert Fossc2c446a2017-05-19 16:50:17 -04003277 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003278 src_x += src_w - 1;
3279 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003280 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003281 src_x += src_w - 1;
3282 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303283 }
3284
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003285 plane_state->color_plane[0].offset = offset;
3286 plane_state->color_plane[0].x = src_x;
3287 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003288
3289 return 0;
3290}
3291
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003292static int
3293i9xx_plane_check(struct intel_crtc_state *crtc_state,
3294 struct intel_plane_state *plane_state)
3295{
3296 int ret;
3297
Ville Syrjälä25721f82018-09-07 18:24:12 +03003298 ret = chv_plane_check_rotation(plane_state);
3299 if (ret)
3300 return ret;
3301
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003302 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3303 &crtc_state->base,
3304 DRM_PLANE_HELPER_NO_SCALING,
3305 DRM_PLANE_HELPER_NO_SCALING,
3306 false, true);
3307 if (ret)
3308 return ret;
3309
3310 if (!plane_state->base.visible)
3311 return 0;
3312
3313 ret = intel_plane_check_src_coordinates(plane_state);
3314 if (ret)
3315 return ret;
3316
3317 ret = i9xx_check_plane_surface(plane_state);
3318 if (ret)
3319 return ret;
3320
3321 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3322
3323 return 0;
3324}
3325
Ville Syrjäläed150302017-11-17 21:19:10 +02003326static void i9xx_update_plane(struct intel_plane *plane,
3327 const struct intel_crtc_state *crtc_state,
3328 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003329{
Ville Syrjäläed150302017-11-17 21:19:10 +02003330 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003331 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003332 u32 linear_offset;
Ville Syrjäläa0864d52017-03-23 21:27:09 +02003333 u32 dspcntr = plane_state->ctl;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003334 int x = plane_state->color_plane[0].x;
3335 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003336 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003337 u32 dspaddr_offset;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003338
Ville Syrjälä29490562016-01-20 18:02:50 +02003339 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003340
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003341 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003342 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003343 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003344 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003345
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003346 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3347
Ville Syrjälä83234d12018-11-14 23:07:17 +02003348 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3349
Ville Syrjälä78587de2017-03-09 17:44:32 +02003350 if (INTEL_GEN(dev_priv) < 4) {
3351 /* pipesrc and dspsize control the size that is scaled from,
3352 * which should always be the user's requested size.
3353 */
Ville Syrjälä83234d12018-11-14 23:07:17 +02003354 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003355 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003356 ((crtc_state->pipe_src_h - 1) << 16) |
3357 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003358 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003359 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003360 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003361 ((crtc_state->pipe_src_h - 1) << 16) |
3362 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003363 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003364 }
3365
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003366 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003367 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003368 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003369 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3370 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3371 }
3372
3373 /*
3374 * The control register self-arms if the plane was previously
3375 * disabled. Try to make the plane enable atomic by writing
3376 * the control register just before the surface register.
3377 */
3378 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3379 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläed150302017-11-17 21:19:10 +02003380 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003381 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003382 dspaddr_offset);
Ville Syrjälä83234d12018-11-14 23:07:17 +02003383 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003384 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003385 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003386 dspaddr_offset);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003387
3388 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003389}
3390
Ville Syrjäläed150302017-11-17 21:19:10 +02003391static void i9xx_disable_plane(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02003392 const struct intel_crtc_state *crtc_state)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003393{
Ville Syrjäläed150302017-11-17 21:19:10 +02003394 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3395 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003396 unsigned long irqflags;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003397
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003398 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3399
Ville Syrjäläed150302017-11-17 21:19:10 +02003400 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3401 if (INTEL_GEN(dev_priv) >= 4)
3402 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003403 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003404 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003405
3406 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003407}
3408
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003409static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3410 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003411{
Ville Syrjäläed150302017-11-17 21:19:10 +02003412 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003413 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003414 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003415 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003416 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003417
3418 /*
3419 * Not 100% correct for planes that can move between pipes,
3420 * but that's only the case for gen2-4 which don't have any
3421 * display power wells.
3422 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003423 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003424 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3425 return false;
3426
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003427 val = I915_READ(DSPCNTR(i9xx_plane));
3428
3429 ret = val & DISPLAY_PLANE_ENABLE;
3430
3431 if (INTEL_GEN(dev_priv) >= 5)
3432 *pipe = plane->pipe;
3433 else
3434 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3435 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003436
3437 intel_display_power_put(dev_priv, power_domain);
3438
3439 return ret;
3440}
3441
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003442static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003443intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003444{
Ben Widawsky2f075562017-03-24 14:29:48 -07003445 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003446 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003447 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003448 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003449}
3450
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003451static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3452{
3453 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003454 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003455
3456 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3457 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3458 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003459}
3460
Chandra Kondurua1b22782015-04-07 15:28:45 -07003461/*
3462 * This function detaches (aka. unbinds) unused scalers in hardware
3463 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003464static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003465{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003466 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3467 const struct intel_crtc_scaler_state *scaler_state =
3468 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003469 int i;
3470
Chandra Kondurua1b22782015-04-07 15:28:45 -07003471 /* loop through and disable scalers that aren't in use */
3472 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003473 if (!scaler_state->scalers[i].in_use)
3474 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003475 }
3476}
3477
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003478static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3479 int color_plane, unsigned int rotation)
3480{
3481 /*
3482 * The stride is either expressed as a multiple of 64 bytes chunks for
3483 * linear buffers or in number of tiles for tiled buffers.
3484 */
3485 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3486 return 64;
3487 else if (drm_rotation_90_or_270(rotation))
3488 return intel_tile_height(fb, color_plane);
3489 else
3490 return intel_tile_width_bytes(fb, color_plane);
3491}
3492
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003493u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003494 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003495{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003496 const struct drm_framebuffer *fb = plane_state->base.fb;
3497 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003498 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003499
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003500 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003501 return 0;
3502
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003503 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003504}
3505
Ville Syrjälä2e881262017-03-17 23:17:56 +02003506static u32 skl_plane_ctl_format(uint32_t pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003507{
Chandra Konduru6156a452015-04-27 13:48:39 -07003508 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003509 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003510 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003511 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003512 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003513 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003514 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003515 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003516 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003517 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003518 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003519 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003520 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003521 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003522 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003523 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003524 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003525 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003526 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003527 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003528 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003529 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003530 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303531 case DRM_FORMAT_NV12:
3532 return PLANE_CTL_FORMAT_NV12;
Chandra Konduru6156a452015-04-27 13:48:39 -07003533 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003534 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003535 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003536
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003537 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003538}
3539
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003540static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003541{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003542 if (!plane_state->base.fb->format->has_alpha)
3543 return PLANE_CTL_ALPHA_DISABLE;
3544
3545 switch (plane_state->base.pixel_blend_mode) {
3546 case DRM_MODE_BLEND_PIXEL_NONE:
3547 return PLANE_CTL_ALPHA_DISABLE;
3548 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003549 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003550 case DRM_MODE_BLEND_COVERAGE:
3551 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003552 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003553 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003554 return PLANE_CTL_ALPHA_DISABLE;
3555 }
3556}
3557
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003558static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003559{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003560 if (!plane_state->base.fb->format->has_alpha)
3561 return PLANE_COLOR_ALPHA_DISABLE;
3562
3563 switch (plane_state->base.pixel_blend_mode) {
3564 case DRM_MODE_BLEND_PIXEL_NONE:
3565 return PLANE_COLOR_ALPHA_DISABLE;
3566 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003567 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003568 case DRM_MODE_BLEND_COVERAGE:
3569 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003570 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003571 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003572 return PLANE_COLOR_ALPHA_DISABLE;
3573 }
3574}
3575
Ville Syrjälä2e881262017-03-17 23:17:56 +02003576static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003577{
Chandra Konduru6156a452015-04-27 13:48:39 -07003578 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003579 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003580 break;
3581 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003582 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003583 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003584 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003585 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003586 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003587 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003588 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003589 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003590 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003591 default:
3592 MISSING_CASE(fb_modifier);
3593 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003594
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003595 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003596}
3597
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003598static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003599{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003600 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003601 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003602 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303603 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003604 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303605 * while i915 HW rotation is clockwise, thats why this swapping.
3606 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003607 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303608 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003609 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003610 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003611 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303612 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003613 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003614 MISSING_CASE(rotate);
3615 }
3616
3617 return 0;
3618}
3619
3620static u32 cnl_plane_ctl_flip(unsigned int reflect)
3621{
3622 switch (reflect) {
3623 case 0:
3624 break;
3625 case DRM_MODE_REFLECT_X:
3626 return PLANE_CTL_FLIP_HORIZONTAL;
3627 case DRM_MODE_REFLECT_Y:
3628 default:
3629 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003630 }
3631
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003632 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003633}
3634
Ville Syrjälä2e881262017-03-17 23:17:56 +02003635u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3636 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003637{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003638 struct drm_i915_private *dev_priv =
3639 to_i915(plane_state->base.plane->dev);
3640 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003641 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003642 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003643 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003644
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003645 plane_ctl = PLANE_CTL_ENABLE;
3646
James Ausmus4036c782017-11-13 10:11:28 -08003647 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003648 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003649 plane_ctl |=
3650 PLANE_CTL_PIPE_GAMMA_ENABLE |
3651 PLANE_CTL_PIPE_CSC_ENABLE |
3652 PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003653
3654 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3655 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003656
3657 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3658 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003659 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003660
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003661 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003662 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003663 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3664
3665 if (INTEL_GEN(dev_priv) >= 10)
3666 plane_ctl |= cnl_plane_ctl_flip(rotation &
3667 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003668
Ville Syrjälä2e881262017-03-17 23:17:56 +02003669 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3670 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3671 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3672 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3673
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003674 return plane_ctl;
3675}
3676
James Ausmus4036c782017-11-13 10:11:28 -08003677u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3678 const struct intel_plane_state *plane_state)
3679{
James Ausmus077ef1f2018-03-28 14:57:56 -07003680 struct drm_i915_private *dev_priv =
3681 to_i915(plane_state->base.plane->dev);
James Ausmus4036c782017-11-13 10:11:28 -08003682 const struct drm_framebuffer *fb = plane_state->base.fb;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303683 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
James Ausmus4036c782017-11-13 10:11:28 -08003684 u32 plane_color_ctl = 0;
3685
James Ausmus077ef1f2018-03-28 14:57:56 -07003686 if (INTEL_GEN(dev_priv) < 11) {
3687 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3688 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3689 }
James Ausmus4036c782017-11-13 10:11:28 -08003690 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003691 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003692
Uma Shankarbfe60a02018-11-02 00:40:20 +05303693 if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003694 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3695 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3696 else
3697 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003698
3699 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3700 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303701 } else if (fb->format->is_yuv) {
3702 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003703 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003704
James Ausmus4036c782017-11-13 10:11:28 -08003705 return plane_color_ctl;
3706}
3707
Maarten Lankhorst73974892016-08-05 23:28:27 +03003708static int
3709__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003710 struct drm_atomic_state *state,
3711 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003712{
3713 struct drm_crtc_state *crtc_state;
3714 struct drm_crtc *crtc;
3715 int i, ret;
3716
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003717 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003718 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003719
3720 if (!state)
3721 return 0;
3722
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003723 /*
3724 * We've duplicated the state, pointers to the old state are invalid.
3725 *
3726 * Don't attempt to use the old state until we commit the duplicated state.
3727 */
3728 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003729 /*
3730 * Force recalculation even if we restore
3731 * current state. With fast modeset this may not result
3732 * in a modeset when the state is compatible.
3733 */
3734 crtc_state->mode_changed = true;
3735 }
3736
3737 /* ignore any reset values/BIOS leftovers in the WM registers */
Ville Syrjälä602ae832017-03-02 19:15:02 +02003738 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3739 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003740
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003741 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003742
3743 WARN_ON(ret == -EDEADLK);
3744 return ret;
3745}
3746
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003747static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3748{
Chris Wilson55277e12019-01-03 11:21:04 +00003749 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3750 intel_has_gpu_reset(dev_priv));
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003751}
3752
Chris Wilsonc0336662016-05-06 15:40:21 +01003753void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003754{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003755 struct drm_device *dev = &dev_priv->drm;
3756 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3757 struct drm_atomic_state *state;
3758 int ret;
3759
Daniel Vetterce87ea12017-07-19 14:54:55 +02003760 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003761 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003762 !gpu_reset_clobbers_display(dev_priv))
3763 return;
3764
Daniel Vetter9db529a2017-08-08 10:08:28 +02003765 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3766 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3767 wake_up_all(&dev_priv->gpu_error.wait_queue);
3768
3769 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3770 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3771 i915_gem_set_wedged(dev_priv);
3772 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003773
Maarten Lankhorst73974892016-08-05 23:28:27 +03003774 /*
3775 * Need mode_config.mutex so that we don't
3776 * trample ongoing ->detect() and whatnot.
3777 */
3778 mutex_lock(&dev->mode_config.mutex);
3779 drm_modeset_acquire_init(ctx, 0);
3780 while (1) {
3781 ret = drm_modeset_lock_all_ctx(dev, ctx);
3782 if (ret != -EDEADLK)
3783 break;
3784
3785 drm_modeset_backoff(ctx);
3786 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003787 /*
3788 * Disabling the crtcs gracefully seems nicer. Also the
3789 * g33 docs say we should at least disable all the planes.
3790 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003791 state = drm_atomic_helper_duplicate_state(dev, ctx);
3792 if (IS_ERR(state)) {
3793 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003794 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003795 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003796 }
3797
3798 ret = drm_atomic_helper_disable_all(dev, ctx);
3799 if (ret) {
3800 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003801 drm_atomic_state_put(state);
3802 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003803 }
3804
3805 dev_priv->modeset_restore_state = state;
3806 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003807}
3808
Chris Wilsonc0336662016-05-06 15:40:21 +01003809void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003810{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003811 struct drm_device *dev = &dev_priv->drm;
3812 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003813 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003814 int ret;
3815
Daniel Vetterce87ea12017-07-19 14:54:55 +02003816 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003817 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003818 return;
3819
Chris Wilson40da1d32018-04-05 13:37:14 +01003820 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003821 if (!state)
3822 goto unlock;
3823
Ville Syrjälä75147472014-11-24 18:28:11 +02003824 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003825 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003826 /* for testing only restore the display */
3827 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003828 if (ret)
3829 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003830 } else {
3831 /*
3832 * The display has been reset as well,
3833 * so need a full re-initialization.
3834 */
3835 intel_runtime_pm_disable_interrupts(dev_priv);
3836 intel_runtime_pm_enable_interrupts(dev_priv);
3837
Imre Deak51f59202016-09-14 13:04:13 +03003838 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003839 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003840 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003841
3842 spin_lock_irq(&dev_priv->irq_lock);
3843 if (dev_priv->display.hpd_irq_setup)
3844 dev_priv->display.hpd_irq_setup(dev_priv);
3845 spin_unlock_irq(&dev_priv->irq_lock);
3846
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003847 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003848 if (ret)
3849 DRM_ERROR("Restoring old state failed with %i\n", ret);
3850
3851 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003852 }
3853
Daniel Vetterce87ea12017-07-19 14:54:55 +02003854 drm_atomic_state_put(state);
3855unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003856 drm_modeset_drop_locks(ctx);
3857 drm_modeset_acquire_fini(ctx);
3858 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003859
3860 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003861}
3862
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003863static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3864 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003865{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003866 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003867 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003868
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003869 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003870 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003871
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003872 /*
3873 * Update pipe size and adjust fitter if needed: the reason for this is
3874 * that in compute_mode_changes we check the native mode (not the pfit
3875 * mode) to see if we can flip rather than do a full mode set. In the
3876 * fastboot case, we'll flip, but if we don't update the pipesrc and
3877 * pfit state, we'll end up with a big fb scanned out into the wrong
3878 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003879 */
3880
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003881 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003882 ((new_crtc_state->pipe_src_w - 1) << 16) |
3883 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003884
3885 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003886 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003887 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003888
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003889 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003890 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003891 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003892 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003893 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003894 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003895 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003896 }
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003897}
3898
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003899static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003900{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003901 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003902 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003903 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003904 i915_reg_t reg;
3905 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003906
3907 /* enable normal train */
3908 reg = FDI_TX_CTL(pipe);
3909 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003910 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07003911 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3912 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07003913 } else {
3914 temp &= ~FDI_LINK_TRAIN_NONE;
3915 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07003916 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003917 I915_WRITE(reg, temp);
3918
3919 reg = FDI_RX_CTL(pipe);
3920 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003921 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003922 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3923 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3924 } else {
3925 temp &= ~FDI_LINK_TRAIN_NONE;
3926 temp |= FDI_LINK_TRAIN_NONE;
3927 }
3928 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3929
3930 /* wait one idle pattern time */
3931 POSTING_READ(reg);
3932 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07003933
3934 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003935 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07003936 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3937 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003938}
3939
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003940/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003941static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3942 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003943{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003944 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003945 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003946 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003947 i915_reg_t reg;
3948 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003949
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03003950 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003951 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003952
Adam Jacksone1a44742010-06-25 15:32:14 -04003953 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3954 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01003955 reg = FDI_RX_IMR(pipe);
3956 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003957 temp &= ~FDI_RX_SYMBOL_LOCK;
3958 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01003959 I915_WRITE(reg, temp);
3960 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003961 udelay(150);
3962
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003963 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01003964 reg = FDI_TX_CTL(pipe);
3965 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02003966 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003967 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003968 temp &= ~FDI_LINK_TRAIN_NONE;
3969 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003970 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003971
Chris Wilson5eddb702010-09-11 13:48:45 +01003972 reg = FDI_RX_CTL(pipe);
3973 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003974 temp &= ~FDI_LINK_TRAIN_NONE;
3975 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003976 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3977
3978 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003979 udelay(150);
3980
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003981 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01003982 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3983 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3984 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003985
Chris Wilson5eddb702010-09-11 13:48:45 +01003986 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04003987 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003988 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003989 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3990
3991 if ((temp & FDI_RX_BIT_LOCK)) {
3992 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01003993 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003994 break;
3995 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003996 }
Adam Jacksone1a44742010-06-25 15:32:14 -04003997 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01003998 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003999
4000 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004001 reg = FDI_TX_CTL(pipe);
4002 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004003 temp &= ~FDI_LINK_TRAIN_NONE;
4004 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004005 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004006
Chris Wilson5eddb702010-09-11 13:48:45 +01004007 reg = FDI_RX_CTL(pipe);
4008 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004009 temp &= ~FDI_LINK_TRAIN_NONE;
4010 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004011 I915_WRITE(reg, temp);
4012
4013 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004014 udelay(150);
4015
Chris Wilson5eddb702010-09-11 13:48:45 +01004016 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004017 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004018 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004019 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4020
4021 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004022 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004023 DRM_DEBUG_KMS("FDI train 2 done.\n");
4024 break;
4025 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004026 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004027 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004028 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004029
4030 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004031
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004032}
4033
Akshay Joshi0206e352011-08-16 15:34:10 -04004034static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004035 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4036 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4037 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4038 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4039};
4040
4041/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004042static void gen6_fdi_link_train(struct intel_crtc *crtc,
4043 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004044{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004045 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004046 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004047 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004048 i915_reg_t reg;
4049 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004050
Adam Jacksone1a44742010-06-25 15:32:14 -04004051 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4052 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004053 reg = FDI_RX_IMR(pipe);
4054 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004055 temp &= ~FDI_RX_SYMBOL_LOCK;
4056 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004057 I915_WRITE(reg, temp);
4058
4059 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004060 udelay(150);
4061
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004062 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004063 reg = FDI_TX_CTL(pipe);
4064 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004065 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004066 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004067 temp &= ~FDI_LINK_TRAIN_NONE;
4068 temp |= FDI_LINK_TRAIN_PATTERN_1;
4069 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4070 /* SNB-B */
4071 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004072 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004073
Daniel Vetterd74cf322012-10-26 10:58:13 +02004074 I915_WRITE(FDI_RX_MISC(pipe),
4075 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4076
Chris Wilson5eddb702010-09-11 13:48:45 +01004077 reg = FDI_RX_CTL(pipe);
4078 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004079 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004080 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4081 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4082 } else {
4083 temp &= ~FDI_LINK_TRAIN_NONE;
4084 temp |= FDI_LINK_TRAIN_PATTERN_1;
4085 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004086 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4087
4088 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004089 udelay(150);
4090
Akshay Joshi0206e352011-08-16 15:34:10 -04004091 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004092 reg = FDI_TX_CTL(pipe);
4093 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004094 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4095 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004096 I915_WRITE(reg, temp);
4097
4098 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004099 udelay(500);
4100
Sean Paulfa37d392012-03-02 12:53:39 -05004101 for (retry = 0; retry < 5; retry++) {
4102 reg = FDI_RX_IIR(pipe);
4103 temp = I915_READ(reg);
4104 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4105 if (temp & FDI_RX_BIT_LOCK) {
4106 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4107 DRM_DEBUG_KMS("FDI train 1 done.\n");
4108 break;
4109 }
4110 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004111 }
Sean Paulfa37d392012-03-02 12:53:39 -05004112 if (retry < 5)
4113 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004114 }
4115 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004116 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004117
4118 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004119 reg = FDI_TX_CTL(pipe);
4120 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004121 temp &= ~FDI_LINK_TRAIN_NONE;
4122 temp |= FDI_LINK_TRAIN_PATTERN_2;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004123 if (IS_GEN(dev_priv, 6)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004124 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4125 /* SNB-B */
4126 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4127 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004128 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004129
Chris Wilson5eddb702010-09-11 13:48:45 +01004130 reg = FDI_RX_CTL(pipe);
4131 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004132 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004133 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4134 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4135 } else {
4136 temp &= ~FDI_LINK_TRAIN_NONE;
4137 temp |= FDI_LINK_TRAIN_PATTERN_2;
4138 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004139 I915_WRITE(reg, temp);
4140
4141 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004142 udelay(150);
4143
Akshay Joshi0206e352011-08-16 15:34:10 -04004144 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004145 reg = FDI_TX_CTL(pipe);
4146 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004147 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4148 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004149 I915_WRITE(reg, temp);
4150
4151 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004152 udelay(500);
4153
Sean Paulfa37d392012-03-02 12:53:39 -05004154 for (retry = 0; retry < 5; retry++) {
4155 reg = FDI_RX_IIR(pipe);
4156 temp = I915_READ(reg);
4157 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4158 if (temp & FDI_RX_SYMBOL_LOCK) {
4159 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4160 DRM_DEBUG_KMS("FDI train 2 done.\n");
4161 break;
4162 }
4163 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004164 }
Sean Paulfa37d392012-03-02 12:53:39 -05004165 if (retry < 5)
4166 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004167 }
4168 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004169 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004170
4171 DRM_DEBUG_KMS("FDI train done.\n");
4172}
4173
Jesse Barnes357555c2011-04-28 15:09:55 -07004174/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004175static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4176 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004177{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004178 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004179 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004180 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004181 i915_reg_t reg;
4182 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004183
4184 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4185 for train result */
4186 reg = FDI_RX_IMR(pipe);
4187 temp = I915_READ(reg);
4188 temp &= ~FDI_RX_SYMBOL_LOCK;
4189 temp &= ~FDI_RX_BIT_LOCK;
4190 I915_WRITE(reg, temp);
4191
4192 POSTING_READ(reg);
4193 udelay(150);
4194
Daniel Vetter01a415f2012-10-27 15:58:40 +02004195 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4196 I915_READ(FDI_RX_IIR(pipe)));
4197
Jesse Barnes139ccd32013-08-19 11:04:55 -07004198 /* Try each vswing and preemphasis setting twice before moving on */
4199 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4200 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004201 reg = FDI_TX_CTL(pipe);
4202 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004203 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4204 temp &= ~FDI_TX_ENABLE;
4205 I915_WRITE(reg, temp);
4206
4207 reg = FDI_RX_CTL(pipe);
4208 temp = I915_READ(reg);
4209 temp &= ~FDI_LINK_TRAIN_AUTO;
4210 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4211 temp &= ~FDI_RX_ENABLE;
4212 I915_WRITE(reg, temp);
4213
4214 /* enable CPU FDI TX and PCH FDI RX */
4215 reg = FDI_TX_CTL(pipe);
4216 temp = I915_READ(reg);
4217 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004218 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004219 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004220 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004221 temp |= snb_b_fdi_train_param[j/2];
4222 temp |= FDI_COMPOSITE_SYNC;
4223 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4224
4225 I915_WRITE(FDI_RX_MISC(pipe),
4226 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4227
4228 reg = FDI_RX_CTL(pipe);
4229 temp = I915_READ(reg);
4230 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4231 temp |= FDI_COMPOSITE_SYNC;
4232 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4233
4234 POSTING_READ(reg);
4235 udelay(1); /* should be 0.5us */
4236
4237 for (i = 0; i < 4; i++) {
4238 reg = FDI_RX_IIR(pipe);
4239 temp = I915_READ(reg);
4240 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4241
4242 if (temp & FDI_RX_BIT_LOCK ||
4243 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4244 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4245 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4246 i);
4247 break;
4248 }
4249 udelay(1); /* should be 0.5us */
4250 }
4251 if (i == 4) {
4252 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4253 continue;
4254 }
4255
4256 /* Train 2 */
4257 reg = FDI_TX_CTL(pipe);
4258 temp = I915_READ(reg);
4259 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4260 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4261 I915_WRITE(reg, temp);
4262
4263 reg = FDI_RX_CTL(pipe);
4264 temp = I915_READ(reg);
4265 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4266 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004267 I915_WRITE(reg, temp);
4268
4269 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004270 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004271
Jesse Barnes139ccd32013-08-19 11:04:55 -07004272 for (i = 0; i < 4; i++) {
4273 reg = FDI_RX_IIR(pipe);
4274 temp = I915_READ(reg);
4275 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004276
Jesse Barnes139ccd32013-08-19 11:04:55 -07004277 if (temp & FDI_RX_SYMBOL_LOCK ||
4278 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4279 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4280 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4281 i);
4282 goto train_done;
4283 }
4284 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004285 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004286 if (i == 4)
4287 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004288 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004289
Jesse Barnes139ccd32013-08-19 11:04:55 -07004290train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004291 DRM_DEBUG_KMS("FDI train done.\n");
4292}
4293
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004294static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004295{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004296 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4297 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004298 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004299 i915_reg_t reg;
4300 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004301
Jesse Barnes0e23b992010-09-10 11:10:00 -07004302 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004303 reg = FDI_RX_CTL(pipe);
4304 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004305 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004306 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004307 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004308 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4309
4310 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004311 udelay(200);
4312
4313 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004314 temp = I915_READ(reg);
4315 I915_WRITE(reg, temp | FDI_PCDCLK);
4316
4317 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004318 udelay(200);
4319
Paulo Zanoni20749732012-11-23 15:30:38 -02004320 /* Enable CPU FDI TX PLL, always on for Ironlake */
4321 reg = FDI_TX_CTL(pipe);
4322 temp = I915_READ(reg);
4323 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4324 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004325
Paulo Zanoni20749732012-11-23 15:30:38 -02004326 POSTING_READ(reg);
4327 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004328 }
4329}
4330
Daniel Vetter88cefb62012-08-12 19:27:14 +02004331static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4332{
4333 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004334 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004335 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004336 i915_reg_t reg;
4337 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004338
4339 /* Switch from PCDclk to Rawclk */
4340 reg = FDI_RX_CTL(pipe);
4341 temp = I915_READ(reg);
4342 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4343
4344 /* Disable CPU FDI TX PLL */
4345 reg = FDI_TX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4348
4349 POSTING_READ(reg);
4350 udelay(100);
4351
4352 reg = FDI_RX_CTL(pipe);
4353 temp = I915_READ(reg);
4354 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4355
4356 /* Wait for the clocks to turn off. */
4357 POSTING_READ(reg);
4358 udelay(100);
4359}
4360
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004361static void ironlake_fdi_disable(struct drm_crtc *crtc)
4362{
4363 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004364 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004365 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4366 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004367 i915_reg_t reg;
4368 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004369
4370 /* disable CPU FDI tx and PCH FDI rx */
4371 reg = FDI_TX_CTL(pipe);
4372 temp = I915_READ(reg);
4373 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4374 POSTING_READ(reg);
4375
4376 reg = FDI_RX_CTL(pipe);
4377 temp = I915_READ(reg);
4378 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004379 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004380 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4381
4382 POSTING_READ(reg);
4383 udelay(100);
4384
4385 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004386 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004387 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004388
4389 /* still set train pattern 1 */
4390 reg = FDI_TX_CTL(pipe);
4391 temp = I915_READ(reg);
4392 temp &= ~FDI_LINK_TRAIN_NONE;
4393 temp |= FDI_LINK_TRAIN_PATTERN_1;
4394 I915_WRITE(reg, temp);
4395
4396 reg = FDI_RX_CTL(pipe);
4397 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004398 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004399 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4400 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4401 } else {
4402 temp &= ~FDI_LINK_TRAIN_NONE;
4403 temp |= FDI_LINK_TRAIN_PATTERN_1;
4404 }
4405 /* BPC in FDI rx is consistent with that in PIPECONF */
4406 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004407 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004408 I915_WRITE(reg, temp);
4409
4410 POSTING_READ(reg);
4411 udelay(100);
4412}
4413
Chris Wilson49d73912016-11-29 09:50:08 +00004414bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004415{
Daniel Vetterfa058872017-07-20 19:57:52 +02004416 struct drm_crtc *crtc;
4417 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004418
Daniel Vetterfa058872017-07-20 19:57:52 +02004419 drm_for_each_crtc(crtc, &dev_priv->drm) {
4420 struct drm_crtc_commit *commit;
4421 spin_lock(&crtc->commit_lock);
4422 commit = list_first_entry_or_null(&crtc->commit_list,
4423 struct drm_crtc_commit, commit_entry);
4424 cleanup_done = commit ?
4425 try_wait_for_completion(&commit->cleanup_done) : true;
4426 spin_unlock(&crtc->commit_lock);
4427
4428 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004429 continue;
4430
Daniel Vetterfa058872017-07-20 19:57:52 +02004431 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004432
4433 return true;
4434 }
4435
4436 return false;
4437}
4438
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004439void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004440{
4441 u32 temp;
4442
4443 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4444
4445 mutex_lock(&dev_priv->sb_lock);
4446
4447 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4448 temp |= SBI_SSCCTL_DISABLE;
4449 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4450
4451 mutex_unlock(&dev_priv->sb_lock);
4452}
4453
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004454/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004455static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004456{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004457 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004459 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004460 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4461 u32 temp;
4462
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004463 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004464
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004465 /* The iCLK virtual clock root frequency is in MHz,
4466 * but the adjusted_mode->crtc_clock in in KHz. To get the
4467 * divisors, it is necessary to divide one by another, so we
4468 * convert the virtual clock precision to KHz here for higher
4469 * precision.
4470 */
4471 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004472 u32 iclk_virtual_root_freq = 172800 * 1000;
4473 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004474 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004475
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004476 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4477 clock << auxdiv);
4478 divsel = (desired_divisor / iclk_pi_range) - 2;
4479 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004480
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004481 /*
4482 * Near 20MHz is a corner case which is
4483 * out of range for the 7-bit divisor
4484 */
4485 if (divsel <= 0x7f)
4486 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004487 }
4488
4489 /* This should not happen with any sane values */
4490 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4491 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4492 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4493 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4494
4495 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
Ville Syrjälä12d7cee2013-09-04 18:25:19 +03004496 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004497 auxdiv,
4498 divsel,
4499 phasedir,
4500 phaseinc);
4501
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004502 mutex_lock(&dev_priv->sb_lock);
4503
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004504 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004505 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004506 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4507 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4508 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4509 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4510 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4511 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004512 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004513
4514 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004515 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004516 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4517 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004518 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004519
4520 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004521 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004522 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004523 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004524
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004525 mutex_unlock(&dev_priv->sb_lock);
4526
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004527 /* Wait for initialization time */
4528 udelay(24);
4529
4530 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4531}
4532
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004533int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4534{
4535 u32 divsel, phaseinc, auxdiv;
4536 u32 iclk_virtual_root_freq = 172800 * 1000;
4537 u32 iclk_pi_range = 64;
4538 u32 desired_divisor;
4539 u32 temp;
4540
4541 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4542 return 0;
4543
4544 mutex_lock(&dev_priv->sb_lock);
4545
4546 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4547 if (temp & SBI_SSCCTL_DISABLE) {
4548 mutex_unlock(&dev_priv->sb_lock);
4549 return 0;
4550 }
4551
4552 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4553 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4554 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4555 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4556 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4557
4558 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4559 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4560 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4561
4562 mutex_unlock(&dev_priv->sb_lock);
4563
4564 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4565
4566 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4567 desired_divisor << auxdiv);
4568}
4569
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004570static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004571 enum pipe pch_transcoder)
4572{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004573 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4575 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004576
4577 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4578 I915_READ(HTOTAL(cpu_transcoder)));
4579 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4580 I915_READ(HBLANK(cpu_transcoder)));
4581 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4582 I915_READ(HSYNC(cpu_transcoder)));
4583
4584 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4585 I915_READ(VTOTAL(cpu_transcoder)));
4586 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4587 I915_READ(VBLANK(cpu_transcoder)));
4588 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4589 I915_READ(VSYNC(cpu_transcoder)));
4590 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4591 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4592}
4593
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004594static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004595{
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004596 uint32_t temp;
4597
4598 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004599 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004600 return;
4601
4602 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4603 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4604
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004605 temp &= ~FDI_BC_BIFURCATION_SELECT;
4606 if (enable)
4607 temp |= FDI_BC_BIFURCATION_SELECT;
4608
4609 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004610 I915_WRITE(SOUTH_CHICKEN1, temp);
4611 POSTING_READ(SOUTH_CHICKEN1);
4612}
4613
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004614static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004615{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004616 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4617 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004618
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004619 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004620 case PIPE_A:
4621 break;
4622 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004623 if (crtc_state->fdi_lanes > 2)
4624 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004625 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004626 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004627
4628 break;
4629 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004630 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004631
4632 break;
4633 default:
4634 BUG();
4635 }
4636}
4637
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004638/*
4639 * Finds the encoder associated with the given CRTC. This can only be
4640 * used when we know that the CRTC isn't feeding multiple encoders!
4641 */
4642static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004643intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4644 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004645{
4646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004647 const struct drm_connector_state *connector_state;
4648 const struct drm_connector *connector;
4649 struct intel_encoder *encoder = NULL;
4650 int num_encoders = 0;
4651 int i;
4652
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004653 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004654 if (connector_state->crtc != &crtc->base)
4655 continue;
4656
4657 encoder = to_intel_encoder(connector_state->best_encoder);
4658 num_encoders++;
4659 }
4660
4661 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4662 num_encoders, pipe_name(crtc->pipe));
4663
4664 return encoder;
4665}
4666
Jesse Barnesf67a5592011-01-05 10:31:48 -08004667/*
4668 * Enable PCH resources required for PCH ports:
4669 * - PCH PLLs
4670 * - FDI training & RX/TX
4671 * - update transcoder timings
4672 * - DP transcoding bits
4673 * - transcoder
4674 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004675static void ironlake_pch_enable(const struct intel_atomic_state *state,
4676 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004677{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004678 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004679 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004680 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004681 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004682 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004683
Daniel Vetterab9412b2013-05-03 11:49:46 +02004684 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004685
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004686 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004687 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004688
Daniel Vettercd986ab2012-10-26 10:58:12 +02004689 /* Write the TU size bits before fdi link training, so that error
4690 * detection works. */
4691 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4692 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4693
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004694 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004695 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004696
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004697 /* We need to program the right clock selection before writing the pixel
4698 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004699 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004700 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004701
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004702 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004703 temp |= TRANS_DPLL_ENABLE(pipe);
4704 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004705 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004706 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004707 temp |= sel;
4708 else
4709 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004710 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004711 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004712
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004713 /* XXX: pch pll's can be enabled any time before we enable the PCH
4714 * transcoder, and we actually should do this to not upset any PCH
4715 * transcoder that already use the clock when we share it.
4716 *
4717 * Note that enable_shared_dpll tries to do the right thing, but
4718 * get_shared_dpll unconditionally resets the pll - we need that to have
4719 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004720 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004721
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004722 /* set transcoder timing, panel must allow it */
4723 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004724 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004725
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004726 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004727
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004728 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004729 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004730 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004731 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004732 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004733 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004734 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004735 enum port port;
4736
Chris Wilson5eddb702010-09-11 13:48:45 +01004737 temp = I915_READ(reg);
4738 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004739 TRANS_DP_SYNC_MASK |
4740 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004741 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004742 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004743
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004744 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004745 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004746 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004747 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004748
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004749 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004750 WARN_ON(port < PORT_B || port > PORT_D);
4751 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004752
Chris Wilson5eddb702010-09-11 13:48:45 +01004753 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004754 }
4755
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004756 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004757}
4758
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004759static void lpt_pch_enable(const struct intel_atomic_state *state,
4760 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004761{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004764 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004765
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004766 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004767
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004768 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004769
Paulo Zanoni0540e482012-10-31 18:12:40 -02004770 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004771 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004772
Paulo Zanoni937bb612012-10-31 18:12:47 -02004773 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004774}
4775
Daniel Vettera1520312013-05-03 11:49:50 +02004776static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004777{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004778 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004779 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004780 u32 temp;
4781
4782 temp = I915_READ(dslreg);
4783 udelay(500);
4784 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004785 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004786 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004787 }
4788}
4789
Ville Syrjälä0a599522018-05-21 21:56:13 +03004790/*
4791 * The hardware phase 0.0 refers to the center of the pixel.
4792 * We want to start from the top/left edge which is phase
4793 * -0.5. That matches how the hardware calculates the scaling
4794 * factors (from top-left of the first pixel to bottom-right
4795 * of the last pixel, as opposed to the pixel centers).
4796 *
4797 * For 4:2:0 subsampled chroma planes we obviously have to
4798 * adjust that so that the chroma sample position lands in
4799 * the right spot.
4800 *
4801 * Note that for packed YCbCr 4:2:2 formats there is no way to
4802 * control chroma siting. The hardware simply replicates the
4803 * chroma samples for both of the luma samples, and thus we don't
4804 * actually get the expected MPEG2 chroma siting convention :(
4805 * The same behaviour is observed on pre-SKL platforms as well.
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004806 *
4807 * Theory behind the formula (note that we ignore sub-pixel
4808 * source coordinates):
4809 * s = source sample position
4810 * d = destination sample position
4811 *
4812 * Downscaling 4:1:
4813 * -0.5
4814 * | 0.0
4815 * | | 1.5 (initial phase)
4816 * | | |
4817 * v v v
4818 * | s | s | s | s |
4819 * | d |
4820 *
4821 * Upscaling 1:4:
4822 * -0.5
4823 * | -0.375 (initial phase)
4824 * | | 0.0
4825 * | | |
4826 * v v v
4827 * | s |
4828 * | d | d | d | d |
Ville Syrjälä0a599522018-05-21 21:56:13 +03004829 */
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004830u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
Ville Syrjälä0a599522018-05-21 21:56:13 +03004831{
4832 int phase = -0x8000;
4833 u16 trip = 0;
4834
4835 if (chroma_cosited)
4836 phase += (sub - 1) * 0x8000 / sub;
4837
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004838 phase += scale / (2 * sub);
4839
4840 /*
4841 * Hardware initial phase limited to [-0.5:1.5].
4842 * Since the max hardware scale factor is 3.0, we
4843 * should never actually excdeed 1.0 here.
4844 */
4845 WARN_ON(phase < -0x8000 || phase > 0x18000);
4846
Ville Syrjälä0a599522018-05-21 21:56:13 +03004847 if (phase < 0)
4848 phase = 0x10000 + phase;
4849 else
4850 trip = PS_PHASE_TRIP;
4851
4852 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4853}
4854
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004855static int
4856skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004857 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304858 int src_w, int src_h, int dst_w, int dst_h,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004859 const struct drm_format_info *format, bool need_scaler)
Chandra Kondurua1b22782015-04-07 15:28:45 -07004860{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004861 struct intel_crtc_scaler_state *scaler_state =
4862 &crtc_state->scaler_state;
4863 struct intel_crtc *intel_crtc =
4864 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304865 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4866 const struct drm_display_mode *adjusted_mode =
4867 &crtc_state->base.adjusted_mode;
Chandra Konduru6156a452015-04-27 13:48:39 -07004868
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004869 /*
4870 * Src coordinates are already rotated by 270 degrees for
4871 * the 90/270 degree plane rotation cases (to match the
4872 * GTT mapping), hence no need to account for rotation here.
4873 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004874 if (src_w != dst_w || src_h != dst_h)
4875 need_scaler = true;
Shashank Sharmae5c05932017-07-21 20:55:05 +05304876
Chandra Kondurua1b22782015-04-07 15:28:45 -07004877 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304878 * Scaling/fitting not supported in IF-ID mode in GEN9+
4879 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4880 * Once NV12 is enabled, handle it here while allocating scaler
4881 * for NV12.
4882 */
4883 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004884 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304885 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4886 return -EINVAL;
4887 }
4888
4889 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07004890 * if plane is being disabled or scaler is no more required or force detach
4891 * - free scaler binded to this plane/crtc
4892 * - in order to do this, update crtc->scaler_usage
4893 *
4894 * Here scaler state in crtc_state is set free so that
4895 * scaler can be assigned to other user. Actual register
4896 * update to free the scaler is done in plane/panel-fit programming.
4897 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4898 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004899 if (force_detach || !need_scaler) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07004900 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004901 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004902 scaler_state->scalers[*scaler_id].in_use = 0;
4903
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004904 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4905 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4906 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07004907 scaler_state->scaler_users);
4908 *scaler_id = -1;
4909 }
4910 return 0;
4911 }
4912
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004913 if (format && format->format == DRM_FORMAT_NV12 &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05304914 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Chandra Konduru77224cd2018-04-09 09:11:13 +05304915 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4916 return -EINVAL;
4917 }
4918
Chandra Kondurua1b22782015-04-07 15:28:45 -07004919 /* range checks */
4920 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07004921 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004922 (IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07004923 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4924 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004925 (!IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07004926 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4927 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004928 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07004929 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004930 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004931 return -EINVAL;
4932 }
4933
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004934 /* mark this plane as a scaler user in crtc_state */
4935 scaler_state->scaler_users |= (1 << scaler_user);
4936 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4937 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4938 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4939 scaler_state->scaler_users);
4940
4941 return 0;
4942}
4943
4944/**
4945 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4946 *
4947 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004948 *
4949 * Return
4950 * 0 - scaler_usage updated successfully
4951 * error - requested scaling cannot be supported or other error condition
4952 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004953int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004954{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03004955 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004956 bool need_scaler = false;
4957
4958 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
4959 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004960
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004961 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304962 &state->scaler_state.scaler_id,
4963 state->pipe_src_w, state->pipe_src_h,
4964 adjusted_mode->crtc_hdisplay,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004965 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004966}
4967
4968/**
4969 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00004970 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004971 * @plane_state: atomic plane state to update
4972 *
4973 * Return
4974 * 0 - scaler_usage updated successfully
4975 * error - requested scaling cannot be supported or other error condition
4976 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004977static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4978 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004979{
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004980 struct intel_plane *intel_plane =
4981 to_intel_plane(plane_state->base.plane);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004982 struct drm_framebuffer *fb = plane_state->base.fb;
4983 int ret;
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004984 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004985 bool need_scaler = false;
4986
4987 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
4988 if (!icl_is_hdr_plane(intel_plane) &&
4989 fb && fb->format->format == DRM_FORMAT_NV12)
4990 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004991
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004992 ret = skl_update_scaler(crtc_state, force_detach,
4993 drm_plane_index(&intel_plane->base),
4994 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004995 drm_rect_width(&plane_state->base.src) >> 16,
4996 drm_rect_height(&plane_state->base.src) >> 16,
4997 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05304998 drm_rect_height(&plane_state->base.dst),
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004999 fb ? fb->format : NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005000
5001 if (ret || plane_state->scaler_id < 0)
5002 return ret;
5003
Chandra Kondurua1b22782015-04-07 15:28:45 -07005004 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02005005 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005006 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5007 intel_plane->base.base.id,
5008 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005009 return -EINVAL;
5010 }
5011
5012 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005013 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005014 case DRM_FORMAT_RGB565:
5015 case DRM_FORMAT_XBGR8888:
5016 case DRM_FORMAT_XRGB8888:
5017 case DRM_FORMAT_ABGR8888:
5018 case DRM_FORMAT_ARGB8888:
5019 case DRM_FORMAT_XRGB2101010:
5020 case DRM_FORMAT_XBGR2101010:
5021 case DRM_FORMAT_YUYV:
5022 case DRM_FORMAT_YVYU:
5023 case DRM_FORMAT_UYVY:
5024 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05305025 case DRM_FORMAT_NV12:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005026 break;
5027 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005028 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5029 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005030 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005031 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005032 }
5033
Chandra Kondurua1b22782015-04-07 15:28:45 -07005034 return 0;
5035}
5036
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005037static void skylake_scaler_disable(struct intel_crtc *crtc)
5038{
5039 int i;
5040
5041 for (i = 0; i < crtc->num_scalers; i++)
5042 skl_detach_scaler(crtc, i);
5043}
5044
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005045static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005046{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005047 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5048 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5049 enum pipe pipe = crtc->pipe;
5050 const struct intel_crtc_scaler_state *scaler_state =
5051 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005052
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005053 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005054 u16 uv_rgb_hphase, uv_rgb_vphase;
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005055 int pfit_w, pfit_h, hscale, vscale;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005056 int id;
5057
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005058 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005059 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005060
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005061 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5062 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5063
5064 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5065 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5066
5067 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5068 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005069
Chandra Kondurua1b22782015-04-07 15:28:45 -07005070 id = scaler_state->scaler_id;
5071 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5072 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005073 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5074 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5075 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5076 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005077 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5078 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005079 }
5080}
5081
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005082static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005083{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005084 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5085 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005086 int pipe = crtc->pipe;
5087
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005088 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005089 /* Force use of hard-coded filter coefficients
5090 * as some pre-programmed values are broken,
5091 * e.g. x201.
5092 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005093 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005094 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5095 PF_PIPE_SEL_IVB(pipe));
5096 else
5097 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005098 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5099 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005100 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005101}
5102
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005103void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005104{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005105 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005106 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005107 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005108
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005109 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005110 return;
5111
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005112 /*
5113 * We can only enable IPS after we enable a plane and wait for a vblank
5114 * This function is called from post_plane_update, which is run after
5115 * a vblank wait.
5116 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005117 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005118
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005119 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005120 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005121 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5122 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005123 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005124 /* Quoting Art Runyan: "its not safe to expect any particular
5125 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005126 * mailbox." Moreover, the mailbox may return a bogus state,
5127 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005128 */
5129 } else {
5130 I915_WRITE(IPS_CTL, IPS_ENABLE);
5131 /* The bit only becomes 1 in the next vblank, so this wait here
5132 * is essentially intel_wait_for_vblank. If we don't have this
5133 * and don't wait for vblanks until the end of crtc_enable, then
5134 * the HW state readout code will complain that the expected
5135 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005136 if (intel_wait_for_register(dev_priv,
5137 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5138 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005139 DRM_ERROR("Timed out waiting for IPS enable\n");
5140 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005141}
5142
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005143void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005144{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005145 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005146 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005147 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005148
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005149 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005150 return;
5151
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005152 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005153 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005154 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005155 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005156 /*
5157 * Wait for PCODE to finish disabling IPS. The BSpec specified
5158 * 42ms timeout value leads to occasional timeouts so use 100ms
5159 * instead.
5160 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005161 if (intel_wait_for_register(dev_priv,
5162 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005163 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005164 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005165 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005166 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005167 POSTING_READ(IPS_CTL);
5168 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005169
5170 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005171 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005172}
5173
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005174static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005175{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005176 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005177 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005178
5179 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005180 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005181 mutex_unlock(&dev->struct_mutex);
5182 }
5183
5184 /* Let userspace switch the overlay on again. In most cases userspace
5185 * has to recompute where to put it anyway.
5186 */
5187}
5188
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005189/**
5190 * intel_post_enable_primary - Perform operations after enabling primary plane
5191 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005192 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005193 *
5194 * Performs potentially sleeping operations that must be done after the primary
5195 * plane is enabled, such as updating FBC and IPS. Note that this may be
5196 * called due to an explicit primary plane update, or due to an implicit
5197 * re-enable that is caused when a sprite plane is updated to no longer
5198 * completely hide the primary plane.
5199 */
5200static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005201intel_post_enable_primary(struct drm_crtc *crtc,
5202 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005203{
5204 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005205 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005206 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5207 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005208
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005209 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005210 * Gen2 reports pipe underruns whenever all planes are disabled.
5211 * So don't enable underrun reporting before at least some planes
5212 * are enabled.
5213 * FIXME: Need to fix the logic to work when we turn off all planes
5214 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005215 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005216 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005217 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5218
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005219 /* Underruns don't always raise interrupts, so check manually. */
5220 intel_check_cpu_fifo_underruns(dev_priv);
5221 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005222}
5223
Ville Syrjälä2622a082016-03-09 19:07:26 +02005224/* FIXME get rid of this and use pre_plane_update */
5225static void
5226intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5227{
5228 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005229 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005230 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5231 int pipe = intel_crtc->pipe;
5232
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005233 /*
5234 * Gen2 reports pipe underruns whenever all planes are disabled.
5235 * So disable underrun reporting before all the planes get disabled.
5236 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005237 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005238 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5239
5240 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005241
5242 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005243 * Vblank time updates from the shadow to live plane control register
5244 * are blocked if the memory self-refresh mode is active at that
5245 * moment. So to make sure the plane gets truly disabled, disable
5246 * first the self-refresh mode. The self-refresh enable bit in turn
5247 * will be checked/applied by the HW only at the next frame start
5248 * event which is after the vblank start event, so we need to have a
5249 * wait-for-vblank between disabling the plane and the pipe.
5250 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005251 if (HAS_GMCH_DISPLAY(dev_priv) &&
5252 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005253 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005254}
5255
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005256static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5257 const struct intel_crtc_state *new_crtc_state)
5258{
5259 if (!old_crtc_state->ips_enabled)
5260 return false;
5261
5262 if (needs_modeset(&new_crtc_state->base))
5263 return true;
5264
5265 return !new_crtc_state->ips_enabled;
5266}
5267
5268static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5269 const struct intel_crtc_state *new_crtc_state)
5270{
5271 if (!new_crtc_state->ips_enabled)
5272 return false;
5273
5274 if (needs_modeset(&new_crtc_state->base))
5275 return true;
5276
5277 /*
5278 * We can't read out IPS on broadwell, assume the worst and
5279 * forcibly enable IPS on the first fastset.
5280 */
5281 if (new_crtc_state->update_pipe &&
5282 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5283 return true;
5284
5285 return !old_crtc_state->ips_enabled;
5286}
5287
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305288static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5289 const struct intel_crtc_state *crtc_state)
5290{
5291 if (!crtc_state->nv12_planes)
5292 return false;
5293
Rodrigo Vivi1347d3c2018-10-31 09:28:45 -07005294 /* WA Display #0827: Gen9:all */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005295 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305296 return true;
5297
5298 return false;
5299}
5300
Daniel Vetter5a21b662016-05-24 17:13:53 +02005301static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5302{
5303 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305304 struct drm_device *dev = crtc->base.dev;
5305 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005306 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5307 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005308 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5309 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005310 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005311 struct drm_plane_state *old_primary_state =
5312 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005313
Chris Wilson5748b6a2016-08-04 16:32:38 +01005314 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005315
Daniel Vetter5a21b662016-05-24 17:13:53 +02005316 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005317 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005318
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005319 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5320 hsw_enable_ips(pipe_config);
5321
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005322 if (old_primary_state) {
5323 struct drm_plane_state *new_primary_state =
5324 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005325
5326 intel_fbc_post_update(crtc);
5327
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005328 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005329 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005330 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005331 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005332 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305333
5334 /* Display WA 827 */
5335 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305336 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305337 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305338 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005339}
5340
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005341static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5342 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005343{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005344 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005345 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005346 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005347 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5348 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005349 struct drm_plane_state *old_primary_state =
5350 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005351 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005352 struct intel_atomic_state *old_intel_state =
5353 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005354
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005355 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5356 hsw_disable_ips(old_crtc_state);
5357
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005358 if (old_primary_state) {
5359 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005360 intel_atomic_get_new_plane_state(old_intel_state,
5361 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005362
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005363 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005364 /*
5365 * Gen2 reports pipe underruns whenever all planes are disabled.
5366 * So disable underrun reporting before all the planes get disabled.
5367 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005368 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005369 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005370 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005371 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005372
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305373 /* Display WA 827 */
5374 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305375 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305376 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305377 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305378
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005379 /*
5380 * Vblank time updates from the shadow to live plane control register
5381 * are blocked if the memory self-refresh mode is active at that
5382 * moment. So to make sure the plane gets truly disabled, disable
5383 * first the self-refresh mode. The self-refresh enable bit in turn
5384 * will be checked/applied by the HW only at the next frame start
5385 * event which is after the vblank start event, so we need to have a
5386 * wait-for-vblank between disabling the plane and the pipe.
5387 */
5388 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5389 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5390 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005391
Matt Ropered4a6a72016-02-23 17:20:13 -08005392 /*
5393 * IVB workaround: must disable low power watermarks for at least
5394 * one frame before enabling scaling. LP watermarks can be re-enabled
5395 * when scaling is disabled.
5396 *
5397 * WaCxSRDisabledForSpriteScaling:ivb
5398 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005399 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5400 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005401 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005402
5403 /*
5404 * If we're doing a modeset, we're done. No need to do any pre-vblank
5405 * watermark programming here.
5406 */
5407 if (needs_modeset(&pipe_config->base))
5408 return;
5409
5410 /*
5411 * For platforms that support atomic watermarks, program the
5412 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5413 * will be the intermediate values that are safe for both pre- and
5414 * post- vblank; when vblank happens, the 'active' values will be set
5415 * to the final 'target' values and we'll do this again to get the
5416 * optimal watermarks. For gen9+ platforms, the values we program here
5417 * will be the final target values which will get automatically latched
5418 * at vblank time; no further programming will be necessary.
5419 *
5420 * If a platform hasn't been transitioned to atomic watermarks yet,
5421 * we'll continue to update watermarks the old way, if flags tell
5422 * us to.
5423 */
5424 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005425 dev_priv->display.initial_watermarks(old_intel_state,
5426 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005427 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005428 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005429}
5430
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005431static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5432 struct intel_crtc *crtc)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005433{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5435 const struct intel_crtc_state *new_crtc_state =
5436 intel_atomic_get_new_crtc_state(state, crtc);
5437 unsigned int update_mask = new_crtc_state->update_planes;
5438 const struct intel_plane_state *old_plane_state;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005439 struct intel_plane *plane;
5440 unsigned fb_bits = 0;
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005441 int i;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005442
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005443 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005444
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005445 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5446 if (crtc->pipe != plane->pipe ||
5447 !(update_mask & BIT(plane->id)))
5448 continue;
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005449
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005450 plane->disable_plane(plane, new_crtc_state);
5451
5452 if (old_plane_state->base.visible)
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005453 fb_bits |= plane->frontbuffer_bit;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005454 }
5455
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005456 intel_frontbuffer_flip(dev_priv, fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005457}
5458
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005459static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005460 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005461 struct drm_atomic_state *old_state)
5462{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005463 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005464 struct drm_connector *conn;
5465 int i;
5466
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005467 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005468 struct intel_encoder *encoder =
5469 to_intel_encoder(conn_state->best_encoder);
5470
5471 if (conn_state->crtc != crtc)
5472 continue;
5473
5474 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005475 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005476 }
5477}
5478
5479static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005480 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005481 struct drm_atomic_state *old_state)
5482{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005483 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005484 struct drm_connector *conn;
5485 int i;
5486
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005487 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005488 struct intel_encoder *encoder =
5489 to_intel_encoder(conn_state->best_encoder);
5490
5491 if (conn_state->crtc != crtc)
5492 continue;
5493
5494 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005495 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005496 }
5497}
5498
5499static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005500 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005501 struct drm_atomic_state *old_state)
5502{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005503 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005504 struct drm_connector *conn;
5505 int i;
5506
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005507 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005508 struct intel_encoder *encoder =
5509 to_intel_encoder(conn_state->best_encoder);
5510
5511 if (conn_state->crtc != crtc)
5512 continue;
5513
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005514 if (encoder->enable)
5515 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005516 intel_opregion_notify_encoder(encoder, true);
5517 }
5518}
5519
5520static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005521 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005522 struct drm_atomic_state *old_state)
5523{
5524 struct drm_connector_state *old_conn_state;
5525 struct drm_connector *conn;
5526 int i;
5527
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005528 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005529 struct intel_encoder *encoder =
5530 to_intel_encoder(old_conn_state->best_encoder);
5531
5532 if (old_conn_state->crtc != crtc)
5533 continue;
5534
5535 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005536 if (encoder->disable)
5537 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005538 }
5539}
5540
5541static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005542 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005543 struct drm_atomic_state *old_state)
5544{
5545 struct drm_connector_state *old_conn_state;
5546 struct drm_connector *conn;
5547 int i;
5548
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005549 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005550 struct intel_encoder *encoder =
5551 to_intel_encoder(old_conn_state->best_encoder);
5552
5553 if (old_conn_state->crtc != crtc)
5554 continue;
5555
5556 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005557 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005558 }
5559}
5560
5561static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005562 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005563 struct drm_atomic_state *old_state)
5564{
5565 struct drm_connector_state *old_conn_state;
5566 struct drm_connector *conn;
5567 int i;
5568
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005569 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005570 struct intel_encoder *encoder =
5571 to_intel_encoder(old_conn_state->best_encoder);
5572
5573 if (old_conn_state->crtc != crtc)
5574 continue;
5575
5576 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005577 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005578 }
5579}
5580
Hans de Goede608ed4a2018-12-20 14:21:18 +01005581static void intel_encoders_update_pipe(struct drm_crtc *crtc,
5582 struct intel_crtc_state *crtc_state,
5583 struct drm_atomic_state *old_state)
5584{
5585 struct drm_connector_state *conn_state;
5586 struct drm_connector *conn;
5587 int i;
5588
5589 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5590 struct intel_encoder *encoder =
5591 to_intel_encoder(conn_state->best_encoder);
5592
5593 if (conn_state->crtc != crtc)
5594 continue;
5595
5596 if (encoder->update_pipe)
5597 encoder->update_pipe(encoder, crtc_state, conn_state);
5598 }
5599}
5600
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005601static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5602 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005603{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005604 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005605 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005606 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005607 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5608 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005609 struct intel_atomic_state *old_intel_state =
5610 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005611
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005612 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005613 return;
5614
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005615 /*
5616 * Sometimes spurious CPU pipe underruns happen during FDI
5617 * training, at least with VGA+HDMI cloning. Suppress them.
5618 *
5619 * On ILK we get an occasional spurious CPU pipe underruns
5620 * between eDP port A enable and vdd enable. Also PCH port
5621 * enable seems to result in the occasional CPU pipe underrun.
5622 *
5623 * Spurious PCH underruns also occur during PCH enabling.
5624 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005625 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5626 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005627
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005628 if (pipe_config->has_pch_encoder)
5629 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005630
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005631 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005632 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005633
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005634 intel_set_pipe_timings(pipe_config);
5635 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005636
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005637 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005638 intel_cpu_transcoder_set_m_n(pipe_config,
5639 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005640 }
5641
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005642 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005643
Jesse Barnesf67a5592011-01-05 10:31:48 -08005644 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005645
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005646 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005647
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005648 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005649 /* Note: FDI PLL enabling _must_ be done before we enable the
5650 * cpu pipes, hence this is separate from all the other fdi/pch
5651 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005652 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005653 } else {
5654 assert_fdi_tx_disabled(dev_priv, pipe);
5655 assert_fdi_rx_disabled(dev_priv, pipe);
5656 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005657
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005658 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005659
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005660 /*
5661 * On ILK+ LUT must be loaded before the pipe is running but with
5662 * clocks enabled
5663 */
Matt Roper302da0c2018-12-10 13:54:15 -08005664 intel_color_load_luts(pipe_config);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005665
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005666 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005667 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005668 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005669
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005670 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005671 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005672
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005673 assert_vblank_disabled(crtc);
5674 drm_crtc_vblank_on(crtc);
5675
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005676 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005677
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005678 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005679 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005680
Ville Syrjäläea80a662018-05-24 22:04:05 +03005681 /*
5682 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5683 * And a second vblank wait is needed at least on ILK with
5684 * some interlaced HDMI modes. Let's do the double wait always
5685 * in case there are more corner cases we don't know about.
5686 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005687 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005688 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005689 intel_wait_for_vblank(dev_priv, pipe);
5690 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005691 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005692 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005693}
5694
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005695/* IPS only exists on ULT machines and is tied to pipe A. */
5696static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5697{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005698 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005699}
5700
Imre Deaked69cd42017-10-02 10:55:57 +03005701static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5702 enum pipe pipe, bool apply)
5703{
5704 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5705 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5706
5707 if (apply)
5708 val |= mask;
5709 else
5710 val &= ~mask;
5711
5712 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5713}
5714
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005715static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5716{
5717 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5718 enum pipe pipe = crtc->pipe;
5719 uint32_t val;
5720
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005721 val = MBUS_DBOX_A_CREDIT(2);
5722 val |= MBUS_DBOX_BW_CREDIT(1);
5723 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005724
5725 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5726}
5727
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005728static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5729 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005730{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005731 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005732 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005733 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005734 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005735 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005736 struct intel_atomic_state *old_intel_state =
5737 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005738 bool psl_clkgate_wa;
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305739 u32 pipe_chicken;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005740
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005741 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005742 return;
5743
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005744 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005745
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005746 if (pipe_config->shared_dpll)
5747 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005748
Paulo Zanonic8af5272018-05-02 14:58:51 -07005749 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5750
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005751 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005752 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005753
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005754 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005755 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005756
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005757 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005758
Jani Nikula4d1de972016-03-18 17:05:42 +02005759 if (cpu_transcoder != TRANSCODER_EDP &&
5760 !transcoder_is_dsi(cpu_transcoder)) {
5761 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005762 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005763 }
5764
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005765 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005766 intel_cpu_transcoder_set_m_n(pipe_config,
5767 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005768 }
5769
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005770 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005771 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005772
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005773 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005774
Matt Roper302da0c2018-12-10 13:54:15 -08005775 intel_color_set_csc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005776
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005777 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005778
Imre Deaked69cd42017-10-02 10:55:57 +03005779 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5780 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005781 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005782 if (psl_clkgate_wa)
5783 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5784
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005785 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005786 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005787 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005788 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005789
5790 /*
5791 * On ILK+ LUT must be loaded before the pipe is running but with
5792 * clocks enabled
5793 */
Matt Roper302da0c2018-12-10 13:54:15 -08005794 intel_color_load_luts(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005795
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305796 /*
5797 * Display WA #1153: enable hardware to bypass the alpha math
5798 * and rounding for per-pixel values 00 and 0xff
5799 */
5800 if (INTEL_GEN(dev_priv) >= 11) {
5801 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5802 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5803 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5804 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5805 }
5806
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005807 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005808 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005809 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005810
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005811 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02005812 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005813
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005814 if (INTEL_GEN(dev_priv) >= 11)
5815 icl_pipe_mbus_enable(intel_crtc);
5816
Jani Nikula4d1de972016-03-18 17:05:42 +02005817 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005818 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005819 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005820
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005821 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005822 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005823
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005824 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005825 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10005826
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005827 assert_vblank_disabled(crtc);
5828 drm_crtc_vblank_on(crtc);
5829
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005830 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005831
Imre Deaked69cd42017-10-02 10:55:57 +03005832 if (psl_clkgate_wa) {
5833 intel_wait_for_vblank(dev_priv, pipe);
5834 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5835 }
5836
Paulo Zanonie4916942013-09-20 16:21:19 -03005837 /* If we change the relative order between pipe/planes enabling, we need
5838 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005839 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01005840 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005841 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5842 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005843 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005844}
5845
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005846static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005847{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005848 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5849 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5850 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005851
5852 /* To avoid upsetting the power well on haswell only disable the pfit if
5853 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005854 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005855 I915_WRITE(PF_CTL(pipe), 0);
5856 I915_WRITE(PF_WIN_POS(pipe), 0);
5857 I915_WRITE(PF_WIN_SZ(pipe), 0);
5858 }
5859}
5860
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005861static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5862 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07005863{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005864 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005865 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005866 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005867 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5868 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005869
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005870 /*
5871 * Sometimes spurious CPU pipe underruns happen when the
5872 * pipe is already disabled, but FDI RX/TX is still enabled.
5873 * Happens at least with VGA+HDMI cloning. Suppress them.
5874 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005875 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5876 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005877
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005878 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02005879
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005880 drm_crtc_vblank_off(crtc);
5881 assert_vblank_disabled(crtc);
5882
Ville Syrjälä4972f702017-11-29 17:37:32 +02005883 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005884
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005885 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005886
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005887 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03005888 ironlake_fdi_disable(crtc);
5889
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005890 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005891
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005892 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02005893 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005894
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005895 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005896 i915_reg_t reg;
5897 u32 temp;
5898
Daniel Vetterd925c592013-06-05 13:34:04 +02005899 /* disable TRANS_DP_CTL */
5900 reg = TRANS_DP_CTL(pipe);
5901 temp = I915_READ(reg);
5902 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5903 TRANS_DP_PORT_SEL_MASK);
5904 temp |= TRANS_DP_PORT_SEL_NONE;
5905 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005906
Daniel Vetterd925c592013-06-05 13:34:04 +02005907 /* disable DPLL_SEL */
5908 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02005909 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02005910 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08005911 }
Daniel Vetterd925c592013-06-05 13:34:04 +02005912
Daniel Vetterd925c592013-06-05 13:34:04 +02005913 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005914 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005915
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005916 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005917 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005918}
5919
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005920static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5921 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005922{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005923 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005924 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005925 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03005926 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005927
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005928 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005929
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005930 drm_crtc_vblank_off(crtc);
5931 assert_vblank_disabled(crtc);
5932
Jani Nikula4d1de972016-03-18 17:05:42 +02005933 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005934 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005935 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005936
Imre Deak24a28172018-06-13 20:07:06 +03005937 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5938 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03005939
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005940 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07005941 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005942
Manasi Navarea6006222018-11-28 12:26:23 -08005943 intel_dsc_disable(old_crtc_state);
5944
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005945 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005946 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005947 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005948 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005949
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005950 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07005951
Imre Deakbdaa29b2018-11-01 16:04:24 +02005952 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005953}
5954
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005955static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005956{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005957 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5958 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005959
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005960 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005961 return;
5962
Daniel Vetterc0b03412013-05-28 12:05:54 +02005963 /*
5964 * The panel fitter should only be adjusted whilst the pipe is disabled,
5965 * according to register description and PRM.
5966 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07005967 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5968 assert_pipe_disabled(dev_priv, crtc->pipe);
5969
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005970 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5971 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02005972
5973 /* Border color in case we don't scale up to the full screen. Black by
5974 * default, change to something else for debugging. */
5975 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005976}
5977
Mahesh Kumar176597a2018-10-04 14:20:43 +05305978bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
5979{
5980 if (port == PORT_NONE)
5981 return false;
5982
5983 if (IS_ICELAKE(dev_priv))
5984 return port <= PORT_B;
5985
5986 return false;
5987}
5988
Paulo Zanoniac213c12018-05-21 17:25:37 -07005989bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5990{
5991 if (IS_ICELAKE(dev_priv))
5992 return port >= PORT_C && port <= PORT_F;
5993
5994 return false;
5995}
5996
5997enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5998{
5999 if (!intel_port_is_tc(dev_priv, port))
6000 return PORT_TC_NONE;
6001
6002 return port - PORT_C;
6003}
6004
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006005enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10006006{
6007 switch (port) {
6008 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006009 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006010 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006011 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006012 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006013 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006014 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006015 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08006016 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006017 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08006018 case PORT_F:
6019 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006020 default:
Imre Deakb9fec162015-11-18 15:57:25 +02006021 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10006022 return POWER_DOMAIN_PORT_OTHER;
6023 }
6024}
6025
Imre Deak337837a2018-11-01 16:04:23 +02006026enum intel_display_power_domain
6027intel_aux_power_domain(struct intel_digital_port *dig_port)
6028{
6029 switch (dig_port->aux_ch) {
6030 case AUX_CH_A:
6031 return POWER_DOMAIN_AUX_A;
6032 case AUX_CH_B:
6033 return POWER_DOMAIN_AUX_B;
6034 case AUX_CH_C:
6035 return POWER_DOMAIN_AUX_C;
6036 case AUX_CH_D:
6037 return POWER_DOMAIN_AUX_D;
6038 case AUX_CH_E:
6039 return POWER_DOMAIN_AUX_E;
6040 case AUX_CH_F:
6041 return POWER_DOMAIN_AUX_F;
6042 default:
6043 MISSING_CASE(dig_port->aux_ch);
6044 return POWER_DOMAIN_AUX_A;
6045 }
6046}
6047
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006048static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6049 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02006050{
6051 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006052 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006053 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02006054 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6055 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006056 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006057 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02006058
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006059 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006060 return 0;
6061
Imre Deak17bd6e62018-01-09 14:20:40 +02006062 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6063 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006064 if (crtc_state->pch_pfit.enabled ||
6065 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006066 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02006067
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006068 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6069 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6070
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006071 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006072 }
Imre Deak319be8a2014-03-04 19:22:57 +02006073
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006074 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02006075 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006076
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006077 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006078 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006079
Imre Deak77d22dc2014-03-05 16:20:52 +02006080 return mask;
6081}
6082
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006083static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006084modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6085 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006086{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006087 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006088 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6089 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006090 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006091
6092 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006093 intel_crtc->enabled_power_domains = new_domains =
6094 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006095
Daniel Vetter5a21b662016-05-24 17:13:53 +02006096 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006097
6098 for_each_power_domain(domain, domains)
6099 intel_display_power_get(dev_priv, domain);
6100
Daniel Vetter5a21b662016-05-24 17:13:53 +02006101 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006102}
6103
6104static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006105 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006106{
6107 enum intel_display_power_domain domain;
6108
6109 for_each_power_domain(domain, domains)
6110 intel_display_power_put(dev_priv, domain);
6111}
6112
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006113static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6114 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006115{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006116 struct intel_atomic_state *old_intel_state =
6117 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006118 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006119 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006120 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006121 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006122 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006123
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006124 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006125 return;
6126
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006127 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006128 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006129
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006130 intel_set_pipe_timings(pipe_config);
6131 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006132
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006133 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006134 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6135 I915_WRITE(CHV_CANVAS(pipe), 0);
6136 }
6137
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006138 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006139
Matt Roper302da0c2018-12-10 13:54:15 -08006140 intel_color_set_csc(pipe_config);
P Raviraj Sitaramc59d2da2018-09-10 19:57:14 +05306141
Jesse Barnes89b667f2013-04-18 14:51:36 -07006142 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006143
Daniel Vettera72e4c92014-09-30 10:56:47 +02006144 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006145
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006146 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006147
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006148 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006149 chv_prepare_pll(intel_crtc, pipe_config);
6150 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006151 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006152 vlv_prepare_pll(intel_crtc, pipe_config);
6153 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006154 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006155
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006156 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006157
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006158 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006159
Matt Roper302da0c2018-12-10 13:54:15 -08006160 intel_color_load_luts(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006161
Ville Syrjäläff32c542017-03-02 19:14:57 +02006162 dev_priv->display.initial_watermarks(old_intel_state,
6163 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006164 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006165
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006166 assert_vblank_disabled(crtc);
6167 drm_crtc_vblank_on(crtc);
6168
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006169 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006170}
6171
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006172static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006173{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006174 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6175 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006176
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006177 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6178 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006179}
6180
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006181static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6182 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006183{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006184 struct intel_atomic_state *old_intel_state =
6185 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006186 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006187 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006188 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006189 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006190 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006191
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006192 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006193 return;
6194
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006195 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006196
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006197 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006198 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006199
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006200 intel_set_pipe_timings(pipe_config);
6201 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006202
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006203 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006204
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006205 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006206
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006207 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006208 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006209
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006210 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006211
Ville Syrjälä939994d2017-09-13 17:08:56 +03006212 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006213
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006214 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006215
Matt Roper302da0c2018-12-10 13:54:15 -08006216 intel_color_load_luts(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006217
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006218 if (dev_priv->display.initial_watermarks != NULL)
6219 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006220 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006221 else
6222 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006223 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006224
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006225 assert_vblank_disabled(crtc);
6226 drm_crtc_vblank_on(crtc);
6227
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006228 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006229}
6230
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006231static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006232{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006233 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6234 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006235
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006236 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006237 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006238
6239 assert_pipe_disabled(dev_priv, crtc->pipe);
6240
Chris Wilson43031782018-09-13 14:16:26 +01006241 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6242 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006243 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006244}
6245
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006246static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6247 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006248{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006249 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006250 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006251 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006252 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6253 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006254
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006255 /*
6256 * On gen2 planes are double buffered but the pipe isn't, so we must
6257 * wait for planes to fully turn off before disabling the pipe.
6258 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006259 if (IS_GEN(dev_priv, 2))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006260 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006261
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006262 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006263
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006264 drm_crtc_vblank_off(crtc);
6265 assert_vblank_disabled(crtc);
6266
Ville Syrjälä4972f702017-11-29 17:37:32 +02006267 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006268
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006269 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006270
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006271 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006272
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006273 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006274 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006275 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006276 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006277 vlv_disable_pll(dev_priv, pipe);
6278 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006279 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006280 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006281
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006282 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006283
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006284 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006285 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006286
6287 if (!dev_priv->display.initial_watermarks)
6288 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006289
6290 /* clock the pipe down to 640x480@60 to potentially save power */
6291 if (IS_I830(dev_priv))
6292 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006293}
6294
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006295static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6296 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006297{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006298 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006299 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006300 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006301 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006302 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006303 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006304 struct drm_atomic_state *state;
6305 struct intel_crtc_state *crtc_state;
6306 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006307
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006308 if (!intel_crtc->active)
6309 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006310
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006311 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6312 const struct intel_plane_state *plane_state =
6313 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006314
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006315 if (plane_state->base.visible)
6316 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006317 }
6318
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006319 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006320 if (!state) {
6321 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6322 crtc->base.id, crtc->name);
6323 return;
6324 }
6325
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006326 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006327
6328 /* Everything's already locked, -EDEADLK can't happen. */
6329 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6330 ret = drm_atomic_add_affected_connectors(state, crtc);
6331
6332 WARN_ON(IS_ERR(crtc_state) || ret);
6333
6334 dev_priv->display.crtc_disable(crtc_state, state);
6335
Chris Wilson08536952016-10-14 13:18:18 +01006336 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006337
Ville Syrjälä78108b72016-05-27 20:59:19 +03006338 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6339 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006340
6341 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6342 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006343 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006344 crtc->enabled = false;
6345 crtc->state->connector_mask = 0;
6346 crtc->state->encoder_mask = 0;
6347
6348 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6349 encoder->base.crtc = NULL;
6350
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006351 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006352 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006353 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006354
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006355 domains = intel_crtc->enabled_power_domains;
6356 for_each_power_domain(domain, domains)
6357 intel_display_power_put(dev_priv, domain);
6358 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006359
6360 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006361 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006362 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006363}
6364
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006365/*
6366 * turn all crtc's off, but do not adjust state
6367 * This has to be paired with a call to intel_modeset_setup_hw_state.
6368 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006369int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006370{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006371 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006372 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006373 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006374
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006375 state = drm_atomic_helper_suspend(dev);
6376 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006377 if (ret)
6378 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006379 else
6380 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006381 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006382}
6383
Chris Wilsonea5b2132010-08-04 13:50:23 +01006384void intel_encoder_destroy(struct drm_encoder *encoder)
6385{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006386 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006387
Chris Wilsonea5b2132010-08-04 13:50:23 +01006388 drm_encoder_cleanup(encoder);
6389 kfree(intel_encoder);
6390}
6391
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006392/* Cross check the actual hw state with our own modeset state tracking (and it's
6393 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006394static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6395 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006396{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006397 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006398
6399 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6400 connector->base.base.id,
6401 connector->base.name);
6402
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006403 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006404 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006405
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006406 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006407 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006408
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006409 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006410 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006411
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006412 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006413 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006414
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006415 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006416 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006417
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006418 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006419 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006420
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006421 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006422 "attached encoder crtc differs from connector crtc\n");
6423 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006424 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006425 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006426 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006427 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006428 }
6429}
6430
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006431static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006432{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006433 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6434 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006435
6436 return 0;
6437}
6438
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006439static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006440 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006441{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006442 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006443 struct drm_atomic_state *state = pipe_config->base.state;
6444 struct intel_crtc *other_crtc;
6445 struct intel_crtc_state *other_crtc_state;
6446
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006447 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6448 pipe_name(pipe), pipe_config->fdi_lanes);
6449 if (pipe_config->fdi_lanes > 4) {
6450 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6451 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006452 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006453 }
6454
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006455 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006456 if (pipe_config->fdi_lanes > 2) {
6457 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6458 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006459 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006460 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006461 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006462 }
6463 }
6464
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006465 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006466 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006467
6468 /* Ivybridge 3 pipe is really complicated */
6469 switch (pipe) {
6470 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006471 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006472 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006473 if (pipe_config->fdi_lanes <= 2)
6474 return 0;
6475
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006476 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006477 other_crtc_state =
6478 intel_atomic_get_crtc_state(state, other_crtc);
6479 if (IS_ERR(other_crtc_state))
6480 return PTR_ERR(other_crtc_state);
6481
6482 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006483 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6484 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006485 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006486 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006487 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006488 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006489 if (pipe_config->fdi_lanes > 2) {
6490 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6491 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006492 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006493 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006494
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006495 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006496 other_crtc_state =
6497 intel_atomic_get_crtc_state(state, other_crtc);
6498 if (IS_ERR(other_crtc_state))
6499 return PTR_ERR(other_crtc_state);
6500
6501 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006502 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006503 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006504 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006505 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006506 default:
6507 BUG();
6508 }
6509}
6510
Daniel Vettere29c22c2013-02-21 00:00:16 +01006511#define RETRY 1
6512static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006513 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006514{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006515 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006516 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006517 int lane, link_bw, fdi_dotclock, ret;
6518 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006519
Daniel Vettere29c22c2013-02-21 00:00:16 +01006520retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006521 /* FDI is a binary signal running at ~2.7GHz, encoding
6522 * each output octet as 10 bits. The actual frequency
6523 * is stored as a divider into a 100MHz clock, and the
6524 * mode pixel clock is stored in units of 1KHz.
6525 * Hence the bw of each lane in terms of the mode signal
6526 * is:
6527 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006528 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006529
Damien Lespiau241bfc32013-09-25 16:45:37 +01006530 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006531
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006532 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006533 pipe_config->pipe_bpp);
6534
6535 pipe_config->fdi_lanes = lane;
6536
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006537 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006538 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006539
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006540 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +02006541 if (ret == -EDEADLK)
6542 return ret;
6543
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006544 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006545 pipe_config->pipe_bpp -= 2*3;
6546 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6547 pipe_config->pipe_bpp);
6548 needs_recompute = true;
6549 pipe_config->bw_constrained = true;
6550
6551 goto retry;
6552 }
6553
6554 if (needs_recompute)
6555 return RETRY;
6556
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006557 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006558}
6559
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006560bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006561{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006562 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6563 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6564
6565 /* IPS only exists on ULT machines and is tied to pipe A. */
6566 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006567 return false;
6568
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006569 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006570 return false;
6571
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006572 if (crtc_state->pipe_bpp > 24)
6573 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006574
6575 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006576 * We compare against max which means we must take
6577 * the increased cdclk requirement into account when
6578 * calculating the new cdclk.
6579 *
6580 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006581 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006582 if (IS_BROADWELL(dev_priv) &&
6583 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6584 return false;
6585
6586 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006587}
6588
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006589static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006590{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006591 struct drm_i915_private *dev_priv =
6592 to_i915(crtc_state->base.crtc->dev);
6593 struct intel_atomic_state *intel_state =
6594 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006595
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006596 if (!hsw_crtc_state_ips_capable(crtc_state))
6597 return false;
6598
6599 if (crtc_state->ips_force_disable)
6600 return false;
6601
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006602 /* IPS should be fine as long as at least one plane is enabled. */
6603 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006604 return false;
6605
6606 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6607 if (IS_BROADWELL(dev_priv) &&
6608 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6609 return false;
6610
6611 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006612}
6613
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006614static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6615{
6616 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6617
6618 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006619 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006620 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6621}
6622
Ville Syrjäläceb99322017-01-20 20:22:05 +02006623static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6624{
6625 uint32_t pixel_rate;
6626
6627 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6628
6629 /*
6630 * We only use IF-ID interlacing. If we ever use
6631 * PF-ID we'll need to adjust the pixel_rate here.
6632 */
6633
6634 if (pipe_config->pch_pfit.enabled) {
6635 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6636 uint32_t pfit_size = pipe_config->pch_pfit.size;
6637
6638 pipe_w = pipe_config->pipe_src_w;
6639 pipe_h = pipe_config->pipe_src_h;
6640
6641 pfit_w = (pfit_size >> 16) & 0xFFFF;
6642 pfit_h = pfit_size & 0xFFFF;
6643 if (pipe_w < pfit_w)
6644 pipe_w = pfit_w;
6645 if (pipe_h < pfit_h)
6646 pipe_h = pfit_h;
6647
6648 if (WARN_ON(!pfit_w || !pfit_h))
6649 return pixel_rate;
6650
6651 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6652 pfit_w * pfit_h);
6653 }
6654
6655 return pixel_rate;
6656}
6657
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006658static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6659{
6660 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6661
6662 if (HAS_GMCH_DISPLAY(dev_priv))
6663 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6664 crtc_state->pixel_rate =
6665 crtc_state->base.adjusted_mode.crtc_clock;
6666 else
6667 crtc_state->pixel_rate =
6668 ilk_pipe_pixel_rate(crtc_state);
6669}
6670
Daniel Vettera43f6e02013-06-07 23:10:32 +02006671static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006672 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006673{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006674 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006675 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006676 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006677 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006678
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006679 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006680 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006681
6682 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006683 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006684 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006685 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006686 if (intel_crtc_supports_double_wide(crtc) &&
6687 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006688 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006689 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006690 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006691 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006692
Ville Syrjäläf3261152016-05-24 21:34:18 +03006693 if (adjusted_mode->crtc_clock > clock_limit) {
6694 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6695 adjusted_mode->crtc_clock, clock_limit,
6696 yesno(pipe_config->double_wide));
6697 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006698 }
Chris Wilson89749352010-09-12 18:25:19 +01006699
Shashank Sharma8c79f842018-10-12 11:53:09 +05306700 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6701 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6702 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306703 /*
6704 * There is only one pipe CSC unit per pipe, and we need that
6705 * for output conversion from RGB->YCBCR. So if CTM is already
6706 * applied we can't support YCBCR420 output.
6707 */
6708 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6709 return -EINVAL;
6710 }
6711
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006712 /*
6713 * Pipe horizontal size must be even in:
6714 * - DVO ganged mode
6715 * - LVDS dual channel mode
6716 * - Double wide pipe
6717 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006718 if (pipe_config->pipe_src_w & 1) {
6719 if (pipe_config->double_wide) {
6720 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6721 return -EINVAL;
6722 }
6723
6724 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6725 intel_is_dual_link_lvds(dev)) {
6726 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6727 return -EINVAL;
6728 }
6729 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006730
Damien Lespiau8693a822013-05-03 18:48:11 +01006731 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6732 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006733 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006734 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006735 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006736 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006737
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006738 intel_crtc_compute_pixel_rate(pipe_config);
6739
Daniel Vetter877d48d2013-04-19 11:24:43 +02006740 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006741 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006742
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006743 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006744}
6745
Zhenyu Wang2c072452009-06-05 15:38:42 +08006746static void
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006747intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006748{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006749 while (*num > DATA_LINK_M_N_MASK ||
6750 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006751 *num >>= 1;
6752 *den >>= 1;
6753 }
6754}
6755
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006756static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006757 uint32_t *ret_m, uint32_t *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006758 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006759{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006760 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006761 * Several DP dongles in particular seem to be fussy about
6762 * too large link M/N values. Give N value as 0x8000 that
6763 * should be acceptable by specific devices. 0x8000 is the
6764 * specified fixed N value for asynchronous clock mode,
6765 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006766 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006767 if (constant_n)
6768 *ret_n = 0x8000;
6769 else
6770 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006771
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006772 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6773 intel_reduce_m_n_ratio(ret_m, ret_n);
6774}
6775
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006776void
Manasi Navarea4a15772018-11-28 13:36:21 -08006777intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006778 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006779 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006780 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006781{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006782 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006783
6784 compute_m_n(bits_per_pixel * pixel_clock,
6785 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006786 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006787 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006788
6789 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006790 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006791 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006792}
6793
Chris Wilsona7615032011-01-12 17:04:08 +00006794static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6795{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006796 if (i915_modparams.panel_use_ssc >= 0)
6797 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006798 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006799 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006800}
6801
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006802static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006803{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006804 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006805}
Daniel Vetterf47709a2013-03-28 10:42:02 +01006806
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006807static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6808{
6809 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006810}
6811
Daniel Vetterf47709a2013-03-28 10:42:02 +01006812static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006813 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03006814 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08006815{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006817 u32 fp, fp2 = 0;
6818
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006819 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006820 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006821 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006822 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006823 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006824 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006825 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006826 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006827 }
6828
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006829 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006830
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03006831 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07006832 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006833 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006834 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006835 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006836 }
6837}
6838
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006839static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6840 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006841{
6842 u32 reg_val;
6843
6844 /*
6845 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6846 * and set it to a reasonable value instead.
6847 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006848 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006849 reg_val &= 0xffffff00;
6850 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006851 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006852
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006853 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03006854 reg_val &= 0x00ffffff;
6855 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006856 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006857
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006858 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006859 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006860 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006861
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006862 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006863 reg_val &= 0x00ffffff;
6864 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006865 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006866}
6867
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006868static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6869 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02006870{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006871 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6872 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6873 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02006874
Daniel Vettere3b95f12013-05-03 11:49:49 +02006875 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6876 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6877 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6878 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006879}
6880
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006881static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6882 enum transcoder transcoder)
6883{
6884 if (IS_HASWELL(dev_priv))
6885 return transcoder == TRANSCODER_EDP;
6886
6887 /*
6888 * Strictly speaking some registers are available before
6889 * gen7, but we only support DRRS on gen7+
6890 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006891 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006892}
6893
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006894static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6895 const struct intel_link_m_n *m_n,
6896 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02006897{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006898 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006899 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006900 enum pipe pipe = crtc->pipe;
6901 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02006902
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006903 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02006904 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6905 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6906 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6907 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006908 /*
6909 * M2_N2 registers are set only if DRRS is supported
6910 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07006911 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006912 if (m2_n2 && crtc_state->has_drrs &&
6913 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07006914 I915_WRITE(PIPE_DATA_M2(transcoder),
6915 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6916 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6917 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6918 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6919 }
Daniel Vetterb5518422013-05-03 11:49:48 +02006920 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02006921 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6922 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6923 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6924 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006925 }
6926}
6927
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006928void intel_dp_set_m_n(const struct intel_crtc_state *crtc_state, enum link_m_n_set m_n)
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006929{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006930 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306931
6932 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006933 dp_m_n = &crtc_state->dp_m_n;
6934 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306935 } else if (m_n == M2_N2) {
6936
6937 /*
6938 * M2_N2 registers are not supported. Hence m2_n2 divider value
6939 * needs to be programmed into M1_N1.
6940 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006941 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306942 } else {
6943 DRM_ERROR("Unsupported divider value\n");
6944 return;
6945 }
6946
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006947 if (crtc_state->has_pch_encoder)
6948 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006949 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006950 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006951}
6952
Daniel Vetter251ac862015-06-18 10:30:24 +02006953static void vlv_compute_dpll(struct intel_crtc *crtc,
6954 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006955{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006956 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006957 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006958 if (crtc->pipe != PIPE_A)
6959 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006960
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006961 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006962 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006963 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6964 DPLL_EXT_BUFFER_ENABLE_VLV;
6965
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006966 pipe_config->dpll_hw_state.dpll_md =
6967 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6968}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006969
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006970static void chv_compute_dpll(struct intel_crtc *crtc,
6971 struct intel_crtc_state *pipe_config)
6972{
6973 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006974 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006975 if (crtc->pipe != PIPE_A)
6976 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6977
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006978 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006979 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006980 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6981
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006982 pipe_config->dpll_hw_state.dpll_md =
6983 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006984}
6985
Ville Syrjäläd288f652014-10-28 13:20:22 +02006986static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006987 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006988{
Daniel Vetterf47709a2013-03-28 10:42:02 +01006989 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006990 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006991 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006992 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006993 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006994 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006995
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006996 /* Enable Refclk */
6997 I915_WRITE(DPLL(pipe),
6998 pipe_config->dpll_hw_state.dpll &
6999 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7000
7001 /* No need to actually set up the DPLL with DSI */
7002 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7003 return;
7004
Ville Syrjäläa5805162015-05-26 20:42:30 +03007005 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01007006
Ville Syrjäläd288f652014-10-28 13:20:22 +02007007 bestn = pipe_config->dpll.n;
7008 bestm1 = pipe_config->dpll.m1;
7009 bestm2 = pipe_config->dpll.m2;
7010 bestp1 = pipe_config->dpll.p1;
7011 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007012
Jesse Barnes89b667f2013-04-18 14:51:36 -07007013 /* See eDP HDMI DPIO driver vbios notes doc */
7014
7015 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007016 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08007017 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007018
7019 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007020 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007021
7022 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007023 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007024 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007025 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007026
7027 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007028 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007029
7030 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007031 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7032 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7033 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007034 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07007035
7036 /*
7037 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7038 * but we don't support that).
7039 * Note: don't use the DAC post divider as it seems unstable.
7040 */
7041 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007042 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007043
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007044 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007045 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007046
Jesse Barnes89b667f2013-04-18 14:51:36 -07007047 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02007048 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007049 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7050 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007051 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03007052 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007053 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007054 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007055 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007056
Ville Syrjälä37a56502016-06-22 21:57:04 +03007057 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07007058 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007059 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007060 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007061 0x0df40000);
7062 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007063 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007064 0x0df70000);
7065 } else { /* HDMI or VGA */
7066 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007067 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007068 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007069 0x0df70000);
7070 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007071 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007072 0x0df40000);
7073 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007074
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007075 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007076 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007077 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07007078 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007079 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007080
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007081 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03007082 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007083}
7084
Ville Syrjäläd288f652014-10-28 13:20:22 +02007085static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007086 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03007087{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007088 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007089 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007090 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007091 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307092 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007093 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307094 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307095 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007096
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007097 /* Enable Refclk and SSC */
7098 I915_WRITE(DPLL(pipe),
7099 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7100
7101 /* No need to actually set up the DPLL with DSI */
7102 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7103 return;
7104
Ville Syrjäläd288f652014-10-28 13:20:22 +02007105 bestn = pipe_config->dpll.n;
7106 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7107 bestm1 = pipe_config->dpll.m1;
7108 bestm2 = pipe_config->dpll.m2 >> 22;
7109 bestp1 = pipe_config->dpll.p1;
7110 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307111 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307112 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307113 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007114
Ville Syrjäläa5805162015-05-26 20:42:30 +03007115 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007116
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007117 /* p1 and p2 divider */
7118 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7119 5 << DPIO_CHV_S1_DIV_SHIFT |
7120 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7121 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7122 1 << DPIO_CHV_K_DIV_SHIFT);
7123
7124 /* Feedback post-divider - m2 */
7125 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7126
7127 /* Feedback refclk divider - n and m1 */
7128 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7129 DPIO_CHV_M1_DIV_BY_2 |
7130 1 << DPIO_CHV_N_DIV_SHIFT);
7131
7132 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007133 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007134
7135 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307136 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7137 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7138 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7139 if (bestm2_frac)
7140 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7141 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007142
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307143 /* Program digital lock detect threshold */
7144 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7145 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7146 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7147 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7148 if (!bestm2_frac)
7149 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7150 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7151
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007152 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307153 if (vco == 5400000) {
7154 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7155 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7156 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7157 tribuf_calcntr = 0x9;
7158 } else if (vco <= 6200000) {
7159 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7160 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7161 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7162 tribuf_calcntr = 0x9;
7163 } else if (vco <= 6480000) {
7164 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7165 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7166 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7167 tribuf_calcntr = 0x8;
7168 } else {
7169 /* Not supported. Apply the same limits as in the max case */
7170 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7171 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7172 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7173 tribuf_calcntr = 0;
7174 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007175 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7176
Ville Syrjälä968040b2015-03-11 22:52:08 +02007177 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307178 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7179 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7180 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7181
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007182 /* AFC Recal */
7183 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7184 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7185 DPIO_AFC_RECAL);
7186
Ville Syrjäläa5805162015-05-26 20:42:30 +03007187 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007188}
7189
Ville Syrjäläd288f652014-10-28 13:20:22 +02007190/**
7191 * vlv_force_pll_on - forcibly enable just the PLL
7192 * @dev_priv: i915 private structure
7193 * @pipe: pipe PLL to enable
7194 * @dpll: PLL configuration
7195 *
7196 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7197 * in cases where we need the PLL enabled even when @pipe is not going to
7198 * be enabled.
7199 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007200int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007201 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007202{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007203 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007204 struct intel_crtc_state *pipe_config;
7205
7206 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7207 if (!pipe_config)
7208 return -ENOMEM;
7209
7210 pipe_config->base.crtc = &crtc->base;
7211 pipe_config->pixel_multiplier = 1;
7212 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007213
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007214 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007215 chv_compute_dpll(crtc, pipe_config);
7216 chv_prepare_pll(crtc, pipe_config);
7217 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007218 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007219 vlv_compute_dpll(crtc, pipe_config);
7220 vlv_prepare_pll(crtc, pipe_config);
7221 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007222 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007223
7224 kfree(pipe_config);
7225
7226 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007227}
7228
7229/**
7230 * vlv_force_pll_off - forcibly disable just the PLL
7231 * @dev_priv: i915 private structure
7232 * @pipe: pipe PLL to disable
7233 *
7234 * Disable the PLL for @pipe. To be used in cases where we need
7235 * the PLL enabled even when @pipe is not going to be enabled.
7236 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007237void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007238{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007239 if (IS_CHERRYVIEW(dev_priv))
7240 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007241 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007242 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007243}
7244
Daniel Vetter251ac862015-06-18 10:30:24 +02007245static void i9xx_compute_dpll(struct intel_crtc *crtc,
7246 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007247 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007248{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007249 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007250 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007251 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007252
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007253 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307254
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007255 dpll = DPLL_VGA_MODE_DIS;
7256
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007257 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007258 dpll |= DPLLB_MODE_LVDS;
7259 else
7260 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007261
Jani Nikula73f67aa2016-12-07 22:48:09 +02007262 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7263 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007264 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007265 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007266 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007267
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007268 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7269 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007270 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007271
Ville Syrjälä37a56502016-06-22 21:57:04 +03007272 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007273 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007274
7275 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007276 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007277 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7278 else {
7279 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007280 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007281 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7282 }
7283 switch (clock->p2) {
7284 case 5:
7285 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7286 break;
7287 case 7:
7288 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7289 break;
7290 case 10:
7291 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7292 break;
7293 case 14:
7294 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7295 break;
7296 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007297 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007298 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7299
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007300 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007301 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007302 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007303 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007304 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7305 else
7306 dpll |= PLL_REF_INPUT_DREFCLK;
7307
7308 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007309 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007310
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007311 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007312 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007313 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007314 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007315 }
7316}
7317
Daniel Vetter251ac862015-06-18 10:30:24 +02007318static void i8xx_compute_dpll(struct intel_crtc *crtc,
7319 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007320 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007321{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007322 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007323 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007324 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007325 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007326
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007327 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307328
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007329 dpll = DPLL_VGA_MODE_DIS;
7330
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007331 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007332 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7333 } else {
7334 if (clock->p1 == 2)
7335 dpll |= PLL_P1_DIVIDE_BY_TWO;
7336 else
7337 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7338 if (clock->p2 == 4)
7339 dpll |= PLL_P2_DIVIDE_BY_4;
7340 }
7341
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007342 if (!IS_I830(dev_priv) &&
7343 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007344 dpll |= DPLL_DVO_2X_MODE;
7345
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007346 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007347 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007348 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7349 else
7350 dpll |= PLL_REF_INPUT_DREFCLK;
7351
7352 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007353 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007354}
7355
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007356static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007357{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007358 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7360 enum pipe pipe = crtc->pipe;
7361 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7362 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007363 uint32_t crtc_vtotal, crtc_vblank_end;
7364 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007365
7366 /* We need to be careful not to changed the adjusted mode, for otherwise
7367 * the hw state checker will get angry at the mismatch. */
7368 crtc_vtotal = adjusted_mode->crtc_vtotal;
7369 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007370
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007371 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007372 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007373 crtc_vtotal -= 1;
7374 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007375
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007376 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007377 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7378 else
7379 vsyncshift = adjusted_mode->crtc_hsync_start -
7380 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007381 if (vsyncshift < 0)
7382 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007383 }
7384
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007385 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007386 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007387
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007388 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007389 (adjusted_mode->crtc_hdisplay - 1) |
7390 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007391 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007392 (adjusted_mode->crtc_hblank_start - 1) |
7393 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007394 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007395 (adjusted_mode->crtc_hsync_start - 1) |
7396 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7397
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007398 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007399 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007400 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007401 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007402 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007403 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007404 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007405 (adjusted_mode->crtc_vsync_start - 1) |
7406 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7407
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007408 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7409 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7410 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7411 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007412 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007413 (pipe == PIPE_B || pipe == PIPE_C))
7414 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7415
Jani Nikulabc58be62016-03-18 17:05:39 +02007416}
7417
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007418static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007419{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007420 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7421 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7422 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007423
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007424 /* pipesrc controls the size that is scaled from, which should
7425 * always be the user's requested size.
7426 */
7427 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007428 ((crtc_state->pipe_src_w - 1) << 16) |
7429 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007430}
7431
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007432static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007433 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007434{
7435 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007436 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007437 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7438 uint32_t tmp;
7439
7440 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007441 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7442 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007443 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007444 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7445 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007446 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007447 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7448 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007449
7450 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007451 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7452 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007453 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007454 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7455 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007456 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007457 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7458 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007459
7460 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007461 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7462 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7463 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007464 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007465}
7466
7467static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7468 struct intel_crtc_state *pipe_config)
7469{
7470 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007471 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007472 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007473
7474 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007475 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7476 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7477
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007478 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7479 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007480}
7481
Daniel Vetterf6a83282014-02-11 15:28:57 -08007482void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007483 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007484{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007485 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7486 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7487 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7488 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007489
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007490 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7491 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7492 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7493 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007494
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007495 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007496 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007497
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007498 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007499
7500 mode->hsync = drm_mode_hsync(mode);
7501 mode->vrefresh = drm_mode_vrefresh(mode);
7502 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007503}
7504
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007505static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007506{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007507 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7508 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter84b046f2013-02-19 18:48:54 +01007509 uint32_t pipeconf;
7510
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007511 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007512
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007513 /* we keep both pipes enabled on 830 */
7514 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007515 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007516
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007517 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007518 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007519
Daniel Vetterff9ce462013-04-24 14:57:17 +02007520 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007521 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7522 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007523 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007524 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007525 pipeconf |= PIPECONF_DITHER_EN |
7526 PIPECONF_DITHER_TYPE_SP;
7527
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007528 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007529 case 18:
7530 pipeconf |= PIPECONF_6BPC;
7531 break;
7532 case 24:
7533 pipeconf |= PIPECONF_8BPC;
7534 break;
7535 case 30:
7536 pipeconf |= PIPECONF_10BPC;
7537 break;
7538 default:
7539 /* Case prevented by intel_choose_pipe_bpp_dither. */
7540 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007541 }
7542 }
7543
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007544 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007545 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007546 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007547 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7548 else
7549 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7550 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007551 pipeconf |= PIPECONF_PROGRESSIVE;
7552
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007553 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007554 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007555 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007556
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007557 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7558 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007559}
7560
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007561static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7562 struct intel_crtc_state *crtc_state)
7563{
7564 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007565 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007566 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007567 int refclk = 48000;
7568
7569 memset(&crtc_state->dpll_hw_state, 0,
7570 sizeof(crtc_state->dpll_hw_state));
7571
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007572 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007573 if (intel_panel_use_ssc(dev_priv)) {
7574 refclk = dev_priv->vbt.lvds_ssc_freq;
7575 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7576 }
7577
7578 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007579 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007580 limit = &intel_limits_i8xx_dvo;
7581 } else {
7582 limit = &intel_limits_i8xx_dac;
7583 }
7584
7585 if (!crtc_state->clock_set &&
7586 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7587 refclk, NULL, &crtc_state->dpll)) {
7588 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7589 return -EINVAL;
7590 }
7591
7592 i8xx_compute_dpll(crtc, crtc_state, NULL);
7593
7594 return 0;
7595}
7596
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007597static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7598 struct intel_crtc_state *crtc_state)
7599{
7600 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007601 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007602 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007603 int refclk = 96000;
7604
7605 memset(&crtc_state->dpll_hw_state, 0,
7606 sizeof(crtc_state->dpll_hw_state));
7607
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007608 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007609 if (intel_panel_use_ssc(dev_priv)) {
7610 refclk = dev_priv->vbt.lvds_ssc_freq;
7611 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7612 }
7613
7614 if (intel_is_dual_link_lvds(dev))
7615 limit = &intel_limits_g4x_dual_channel_lvds;
7616 else
7617 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007618 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7619 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007620 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007621 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007622 limit = &intel_limits_g4x_sdvo;
7623 } else {
7624 /* The option is for other outputs */
7625 limit = &intel_limits_i9xx_sdvo;
7626 }
7627
7628 if (!crtc_state->clock_set &&
7629 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7630 refclk, NULL, &crtc_state->dpll)) {
7631 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7632 return -EINVAL;
7633 }
7634
7635 i9xx_compute_dpll(crtc, crtc_state, NULL);
7636
7637 return 0;
7638}
7639
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007640static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7641 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007642{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007643 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007644 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007645 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007646 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007647
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007648 memset(&crtc_state->dpll_hw_state, 0,
7649 sizeof(crtc_state->dpll_hw_state));
7650
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007651 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007652 if (intel_panel_use_ssc(dev_priv)) {
7653 refclk = dev_priv->vbt.lvds_ssc_freq;
7654 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7655 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007656
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007657 limit = &intel_limits_pineview_lvds;
7658 } else {
7659 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007660 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007661
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007662 if (!crtc_state->clock_set &&
7663 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7664 refclk, NULL, &crtc_state->dpll)) {
7665 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7666 return -EINVAL;
7667 }
7668
7669 i9xx_compute_dpll(crtc, crtc_state, NULL);
7670
7671 return 0;
7672}
7673
7674static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7675 struct intel_crtc_state *crtc_state)
7676{
7677 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007678 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007679 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007680 int refclk = 96000;
7681
7682 memset(&crtc_state->dpll_hw_state, 0,
7683 sizeof(crtc_state->dpll_hw_state));
7684
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007685 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007686 if (intel_panel_use_ssc(dev_priv)) {
7687 refclk = dev_priv->vbt.lvds_ssc_freq;
7688 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007689 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007690
7691 limit = &intel_limits_i9xx_lvds;
7692 } else {
7693 limit = &intel_limits_i9xx_sdvo;
7694 }
7695
7696 if (!crtc_state->clock_set &&
7697 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7698 refclk, NULL, &crtc_state->dpll)) {
7699 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7700 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007701 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007702
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007703 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007704
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007705 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007706}
7707
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007708static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7709 struct intel_crtc_state *crtc_state)
7710{
7711 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007712 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007713
7714 memset(&crtc_state->dpll_hw_state, 0,
7715 sizeof(crtc_state->dpll_hw_state));
7716
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007717 if (!crtc_state->clock_set &&
7718 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7719 refclk, NULL, &crtc_state->dpll)) {
7720 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7721 return -EINVAL;
7722 }
7723
7724 chv_compute_dpll(crtc, crtc_state);
7725
7726 return 0;
7727}
7728
7729static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7730 struct intel_crtc_state *crtc_state)
7731{
7732 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007733 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007734
7735 memset(&crtc_state->dpll_hw_state, 0,
7736 sizeof(crtc_state->dpll_hw_state));
7737
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007738 if (!crtc_state->clock_set &&
7739 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7740 refclk, NULL, &crtc_state->dpll)) {
7741 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7742 return -EINVAL;
7743 }
7744
7745 vlv_compute_dpll(crtc, crtc_state);
7746
7747 return 0;
7748}
7749
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007750static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007751 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007752{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007753 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007754 uint32_t tmp;
7755
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007756 if (INTEL_GEN(dev_priv) <= 3 &&
7757 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007758 return;
7759
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007760 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007761 if (!(tmp & PFIT_ENABLE))
7762 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007763
Daniel Vetter06922822013-07-11 13:35:40 +02007764 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007765 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007766 if (crtc->pipe != PIPE_B)
7767 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007768 } else {
7769 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7770 return;
7771 }
7772
Daniel Vetter06922822013-07-11 13:35:40 +02007773 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007774 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007775}
7776
Jesse Barnesacbec812013-09-20 11:29:32 -07007777static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007778 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007779{
7780 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007781 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007782 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007783 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007784 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007785 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007786
Ville Syrjäläb5219732016-03-15 16:40:01 +02007787 /* In case of DSI, DPLL will not be used */
7788 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307789 return;
7790
Ville Syrjäläa5805162015-05-26 20:42:30 +03007791 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007792 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007793 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007794
7795 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7796 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7797 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7798 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7799 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7800
Imre Deakdccbea32015-06-22 23:35:51 +03007801 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007802}
7803
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007804static void
7805i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7806 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007807{
7808 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007809 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007810 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7811 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007812 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007813 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007814 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00007815 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007816 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00007817 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007818
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007819 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00007820 return;
7821
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007822 WARN_ON(pipe != crtc->pipe);
7823
Damien Lespiaud9806c92015-01-21 14:07:19 +00007824 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00007825 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007826 DRM_DEBUG_KMS("failed to alloc fb\n");
7827 return;
7828 }
7829
Damien Lespiau1b842c82015-01-21 13:50:54 +00007830 fb = &intel_fb->base;
7831
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02007832 fb->dev = dev;
7833
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02007834 val = I915_READ(DSPCNTR(i9xx_plane));
7835
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007836 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00007837 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007838 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02007839 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00007840 }
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007841
7842 if (val & DISPPLANE_ROTATE_180)
7843 plane_config->rotation = DRM_MODE_ROTATE_180;
Daniel Vetter18c52472015-02-10 17:16:09 +00007844 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007845
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007846 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
7847 val & DISPPLANE_MIRROR)
7848 plane_config->rotation |= DRM_MODE_REFLECT_X;
7849
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007850 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00007851 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02007852 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007853
Ville Syrjälä81894b22017-11-17 21:19:13 +02007854 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7855 offset = I915_READ(DSPOFFSET(i9xx_plane));
7856 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7857 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007858 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007859 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007860 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007861 offset = I915_READ(DSPLINOFF(i9xx_plane));
7862 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007863 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007864 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007865 }
7866 plane_config->base = base;
7867
7868 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007869 fb->width = ((val >> 16) & 0xfff) + 1;
7870 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007871
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007872 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007873 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007874
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02007875 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007876
Daniel Vetterf37b5c22015-02-10 23:12:27 +01007877 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007878
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007879 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7880 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02007881 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00007882 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007883
Damien Lespiau2d140302015-02-05 17:22:18 +00007884 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007885}
7886
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007887static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007888 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007889{
7890 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007891 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007892 int pipe = pipe_config->cpu_transcoder;
7893 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007894 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007895 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007896 int refclk = 100000;
7897
Ville Syrjäläb5219732016-03-15 16:40:01 +02007898 /* In case of DSI, DPLL will not be used */
7899 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7900 return;
7901
Ville Syrjäläa5805162015-05-26 20:42:30 +03007902 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007903 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7904 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7905 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7906 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03007907 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007908 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007909
7910 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007911 clock.m2 = (pll_dw0 & 0xff) << 22;
7912 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7913 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007914 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7915 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7916 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7917
Imre Deakdccbea32015-06-22 23:35:51 +03007918 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007919}
7920
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307921static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
7922 struct intel_crtc_state *pipe_config)
7923{
7924 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7925 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
7926
Shashank Sharma668b6c12018-10-12 11:53:14 +05307927 pipe_config->lspcon_downsampling = false;
7928
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307929 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
7930 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
7931
7932 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7933 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
7934 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
7935
7936 if (ycbcr420_enabled) {
7937 /* We support 4:2:0 in full blend mode only */
7938 if (!blend)
7939 output = INTEL_OUTPUT_FORMAT_INVALID;
7940 else if (!(IS_GEMINILAKE(dev_priv) ||
7941 INTEL_GEN(dev_priv) >= 10))
7942 output = INTEL_OUTPUT_FORMAT_INVALID;
7943 else
7944 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307945 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05307946 /*
7947 * Currently there is no interface defined to
7948 * check user preference between RGB/YCBCR444
7949 * or YCBCR420. So the only possible case for
7950 * YCBCR444 usage is driving YCBCR420 output
7951 * with LSPCON, when pipe is configured for
7952 * YCBCR444 output and LSPCON takes care of
7953 * downsampling it.
7954 */
7955 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307956 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307957 }
7958 }
7959 }
7960
7961 pipe_config->output_format = output;
7962}
7963
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007964static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007965 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007966{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007967 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02007968 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007969 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02007970 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007971
Imre Deak17290502016-02-12 18:55:11 +02007972 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7973 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02007974 return false;
7975
Shashank Sharmad9facae2018-10-12 11:53:07 +05307976 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02007977 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02007978 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02007979
Imre Deak17290502016-02-12 18:55:11 +02007980 ret = false;
7981
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007982 tmp = I915_READ(PIPECONF(crtc->pipe));
7983 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02007984 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007985
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007986 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7987 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03007988 switch (tmp & PIPECONF_BPC_MASK) {
7989 case PIPECONF_6BPC:
7990 pipe_config->pipe_bpp = 18;
7991 break;
7992 case PIPECONF_8BPC:
7993 pipe_config->pipe_bpp = 24;
7994 break;
7995 case PIPECONF_10BPC:
7996 pipe_config->pipe_bpp = 30;
7997 break;
7998 default:
7999 break;
8000 }
8001 }
8002
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008003 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08008004 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02008005 pipe_config->limited_color_range = true;
8006
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008007 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03008008 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8009
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008010 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02008011 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008012
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008013 i9xx_get_pfit_config(crtc, pipe_config);
8014
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008015 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02008016 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008017 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02008018 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8019 else
8020 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02008021 pipe_config->pixel_multiplier =
8022 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8023 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008024 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008025 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02008026 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02008027 tmp = I915_READ(DPLL(crtc->pipe));
8028 pipe_config->pixel_multiplier =
8029 ((tmp & SDVO_MULTIPLIER_MASK)
8030 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8031 } else {
8032 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8033 * port and will be fixed up in the encoder->get_config
8034 * function. */
8035 pipe_config->pixel_multiplier = 1;
8036 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008037 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008038 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008039 /*
8040 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8041 * on 830. Filter it out here so that we don't
8042 * report errors due to that.
8043 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008044 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008045 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8046
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008047 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8048 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03008049 } else {
8050 /* Mask out read-only status bits. */
8051 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8052 DPLL_PORTC_READY_MASK |
8053 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008054 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02008055
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008056 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008057 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01008058 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07008059 vlv_crtc_clock_get(crtc, pipe_config);
8060 else
8061 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03008062
Ville Syrjälä0f646142015-08-26 19:39:18 +03008063 /*
8064 * Normally the dotclock is filled in by the encoder .get_config()
8065 * but in case the pipe is enabled w/o any ports we need a sane
8066 * default.
8067 */
8068 pipe_config->base.adjusted_mode.crtc_clock =
8069 pipe_config->port_clock / pipe_config->pixel_multiplier;
8070
Imre Deak17290502016-02-12 18:55:11 +02008071 ret = true;
8072
8073out:
8074 intel_display_power_put(dev_priv, power_domain);
8075
8076 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008077}
8078
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008079static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07008080{
Jesse Barnes13d83a62011-08-03 12:59:20 -07008081 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04008082 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008083 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008084 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008085 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008086 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07008087 bool has_ck505 = false;
8088 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04008089 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008090
8091 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008092 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07008093 switch (encoder->type) {
8094 case INTEL_OUTPUT_LVDS:
8095 has_panel = true;
8096 has_lvds = true;
8097 break;
8098 case INTEL_OUTPUT_EDP:
8099 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02008100 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07008101 has_cpu_edp = true;
8102 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008103 default:
8104 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008105 }
8106 }
8107
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008108 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008109 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008110 can_ssc = has_ck505;
8111 } else {
8112 has_ck505 = false;
8113 can_ssc = true;
8114 }
8115
Lyude1c1a24d2016-06-14 11:04:09 -04008116 /* Check if any DPLLs are using the SSC source */
8117 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8118 u32 temp = I915_READ(PCH_DPLL(i));
8119
8120 if (!(temp & DPLL_VCO_ENABLE))
8121 continue;
8122
8123 if ((temp & PLL_REF_INPUT_MASK) ==
8124 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8125 using_ssc_source = true;
8126 break;
8127 }
8128 }
8129
8130 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8131 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008132
8133 /* Ironlake: try to setup display ref clock before DPLL
8134 * enabling. This is only under driver's control after
8135 * PCH B stepping, previous chipset stepping should be
8136 * ignoring this setting.
8137 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008138 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008139
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008140 /* As we must carefully and slowly disable/enable each source in turn,
8141 * compute the final state we want first and check if we need to
8142 * make any changes at all.
8143 */
8144 final = val;
8145 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008146 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008147 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008148 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008149 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8150
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008151 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008152 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008153 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008154
Keith Packard199e5d72011-09-22 12:01:57 -07008155 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008156 final |= DREF_SSC_SOURCE_ENABLE;
8157
8158 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8159 final |= DREF_SSC1_ENABLE;
8160
8161 if (has_cpu_edp) {
8162 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8163 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8164 else
8165 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8166 } else
8167 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008168 } else if (using_ssc_source) {
8169 final |= DREF_SSC_SOURCE_ENABLE;
8170 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008171 }
8172
8173 if (final == val)
8174 return;
8175
8176 /* Always enable nonspread source */
8177 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8178
8179 if (has_ck505)
8180 val |= DREF_NONSPREAD_CK505_ENABLE;
8181 else
8182 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8183
8184 if (has_panel) {
8185 val &= ~DREF_SSC_SOURCE_MASK;
8186 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008187
Keith Packard199e5d72011-09-22 12:01:57 -07008188 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008189 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008190 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008191 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008192 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008193 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008194
8195 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008196 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008197 POSTING_READ(PCH_DREF_CONTROL);
8198 udelay(200);
8199
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008200 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008201
8202 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008203 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008204 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008205 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008206 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008207 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008208 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008209 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008210 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008211
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008212 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008213 POSTING_READ(PCH_DREF_CONTROL);
8214 udelay(200);
8215 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008216 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008217
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008218 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008219
8220 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008221 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008222
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008223 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008224 POSTING_READ(PCH_DREF_CONTROL);
8225 udelay(200);
8226
Lyude1c1a24d2016-06-14 11:04:09 -04008227 if (!using_ssc_source) {
8228 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008229
Lyude1c1a24d2016-06-14 11:04:09 -04008230 /* Turn off the SSC source */
8231 val &= ~DREF_SSC_SOURCE_MASK;
8232 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008233
Lyude1c1a24d2016-06-14 11:04:09 -04008234 /* Turn off SSC1 */
8235 val &= ~DREF_SSC1_ENABLE;
8236
8237 I915_WRITE(PCH_DREF_CONTROL, val);
8238 POSTING_READ(PCH_DREF_CONTROL);
8239 udelay(200);
8240 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008241 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008242
8243 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008244}
8245
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008246static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008247{
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008248 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008249
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008250 tmp = I915_READ(SOUTH_CHICKEN2);
8251 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8252 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008253
Imre Deakcf3598c2016-06-28 13:37:31 +03008254 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8255 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008256 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008257
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008258 tmp = I915_READ(SOUTH_CHICKEN2);
8259 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8260 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008261
Imre Deakcf3598c2016-06-28 13:37:31 +03008262 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8263 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008264 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008265}
8266
8267/* WaMPhyProgramming:hsw */
8268static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8269{
8270 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008271
8272 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8273 tmp &= ~(0xFF << 24);
8274 tmp |= (0x12 << 24);
8275 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8276
Paulo Zanonidde86e22012-12-01 12:04:25 -02008277 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8278 tmp |= (1 << 11);
8279 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8280
8281 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8282 tmp |= (1 << 11);
8283 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8284
Paulo Zanonidde86e22012-12-01 12:04:25 -02008285 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8286 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8287 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8288
8289 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8290 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8291 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8292
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008293 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8294 tmp &= ~(7 << 13);
8295 tmp |= (5 << 13);
8296 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008297
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008298 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8299 tmp &= ~(7 << 13);
8300 tmp |= (5 << 13);
8301 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008302
8303 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8304 tmp &= ~0xFF;
8305 tmp |= 0x1C;
8306 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8307
8308 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8309 tmp &= ~0xFF;
8310 tmp |= 0x1C;
8311 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8312
8313 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8314 tmp &= ~(0xFF << 16);
8315 tmp |= (0x1C << 16);
8316 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8317
8318 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8319 tmp &= ~(0xFF << 16);
8320 tmp |= (0x1C << 16);
8321 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8322
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008323 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8324 tmp |= (1 << 27);
8325 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008326
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008327 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8328 tmp |= (1 << 27);
8329 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008330
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008331 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8332 tmp &= ~(0xF << 28);
8333 tmp |= (4 << 28);
8334 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008335
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008336 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8337 tmp &= ~(0xF << 28);
8338 tmp |= (4 << 28);
8339 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008340}
8341
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008342/* Implements 3 different sequences from BSpec chapter "Display iCLK
8343 * Programming" based on the parameters passed:
8344 * - Sequence to enable CLKOUT_DP
8345 * - Sequence to enable CLKOUT_DP without spread
8346 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8347 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008348static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8349 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008350{
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008351 uint32_t reg, tmp;
8352
8353 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8354 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008355 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8356 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008357 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008358
Ville Syrjäläa5805162015-05-26 20:42:30 +03008359 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008360
8361 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8362 tmp &= ~SBI_SSCCTL_DISABLE;
8363 tmp |= SBI_SSCCTL_PATHALT;
8364 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8365
8366 udelay(24);
8367
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008368 if (with_spread) {
8369 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8370 tmp &= ~SBI_SSCCTL_PATHALT;
8371 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008372
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008373 if (with_fdi) {
8374 lpt_reset_fdi_mphy(dev_priv);
8375 lpt_program_fdi_mphy(dev_priv);
8376 }
8377 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008378
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008379 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008380 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8381 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8382 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008383
Ville Syrjäläa5805162015-05-26 20:42:30 +03008384 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008385}
8386
Paulo Zanoni47701c32013-07-23 11:19:25 -03008387/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008388static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008389{
Paulo Zanoni47701c32013-07-23 11:19:25 -03008390 uint32_t reg, tmp;
8391
Ville Syrjäläa5805162015-05-26 20:42:30 +03008392 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008393
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008394 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008395 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8396 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8397 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8398
8399 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8400 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8401 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8402 tmp |= SBI_SSCCTL_PATHALT;
8403 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8404 udelay(32);
8405 }
8406 tmp |= SBI_SSCCTL_DISABLE;
8407 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8408 }
8409
Ville Syrjäläa5805162015-05-26 20:42:30 +03008410 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008411}
8412
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008413#define BEND_IDX(steps) ((50 + (steps)) / 5)
8414
8415static const uint16_t sscdivintphase[] = {
8416 [BEND_IDX( 50)] = 0x3B23,
8417 [BEND_IDX( 45)] = 0x3B23,
8418 [BEND_IDX( 40)] = 0x3C23,
8419 [BEND_IDX( 35)] = 0x3C23,
8420 [BEND_IDX( 30)] = 0x3D23,
8421 [BEND_IDX( 25)] = 0x3D23,
8422 [BEND_IDX( 20)] = 0x3E23,
8423 [BEND_IDX( 15)] = 0x3E23,
8424 [BEND_IDX( 10)] = 0x3F23,
8425 [BEND_IDX( 5)] = 0x3F23,
8426 [BEND_IDX( 0)] = 0x0025,
8427 [BEND_IDX( -5)] = 0x0025,
8428 [BEND_IDX(-10)] = 0x0125,
8429 [BEND_IDX(-15)] = 0x0125,
8430 [BEND_IDX(-20)] = 0x0225,
8431 [BEND_IDX(-25)] = 0x0225,
8432 [BEND_IDX(-30)] = 0x0325,
8433 [BEND_IDX(-35)] = 0x0325,
8434 [BEND_IDX(-40)] = 0x0425,
8435 [BEND_IDX(-45)] = 0x0425,
8436 [BEND_IDX(-50)] = 0x0525,
8437};
8438
8439/*
8440 * Bend CLKOUT_DP
8441 * steps -50 to 50 inclusive, in steps of 5
8442 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8443 * change in clock period = -(steps / 10) * 5.787 ps
8444 */
8445static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8446{
8447 uint32_t tmp;
8448 int idx = BEND_IDX(steps);
8449
8450 if (WARN_ON(steps % 5 != 0))
8451 return;
8452
8453 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8454 return;
8455
8456 mutex_lock(&dev_priv->sb_lock);
8457
8458 if (steps % 10 != 0)
8459 tmp = 0xAAAAAAAB;
8460 else
8461 tmp = 0x00000000;
8462 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8463
8464 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8465 tmp &= 0xffff0000;
8466 tmp |= sscdivintphase[idx];
8467 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8468
8469 mutex_unlock(&dev_priv->sb_lock);
8470}
8471
8472#undef BEND_IDX
8473
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008474static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008475{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008476 struct intel_encoder *encoder;
8477 bool has_vga = false;
8478
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008479 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008480 switch (encoder->type) {
8481 case INTEL_OUTPUT_ANALOG:
8482 has_vga = true;
8483 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008484 default:
8485 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008486 }
8487 }
8488
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008489 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008490 lpt_bend_clkout_dp(dev_priv, 0);
8491 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008492 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008493 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008494 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008495}
8496
Paulo Zanonidde86e22012-12-01 12:04:25 -02008497/*
8498 * Initialize reference clocks when the driver loads
8499 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008500void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008501{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008502 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008503 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008504 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008505 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008506}
8507
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008508static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008509{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008510 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8511 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8512 enum pipe pipe = crtc->pipe;
Paulo Zanonic8203562012-09-12 10:06:29 -03008513 uint32_t val;
8514
Daniel Vetter78114072013-06-13 00:54:57 +02008515 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008516
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008517 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008518 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008519 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008520 break;
8521 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008522 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008523 break;
8524 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008525 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008526 break;
8527 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008528 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008529 break;
8530 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008531 /* Case prevented by intel_choose_pipe_bpp_dither. */
8532 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008533 }
8534
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008535 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008536 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8537
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008538 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008539 val |= PIPECONF_INTERLACED_ILK;
8540 else
8541 val |= PIPECONF_PROGRESSIVE;
8542
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008543 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008544 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008545
Paulo Zanonic8203562012-09-12 10:06:29 -03008546 I915_WRITE(PIPECONF(pipe), val);
8547 POSTING_READ(PIPECONF(pipe));
8548}
8549
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008550static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008551{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008552 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8553 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8554 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008555 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008556
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008557 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008558 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8559
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008560 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008561 val |= PIPECONF_INTERLACED_ILK;
8562 else
8563 val |= PIPECONF_PROGRESSIVE;
8564
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008565 I915_WRITE(PIPECONF(cpu_transcoder), val);
8566 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008567}
8568
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008569static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008570{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008571 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8572 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008573
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008574 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008575 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008576
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008577 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008578 case 18:
8579 val |= PIPEMISC_DITHER_6_BPC;
8580 break;
8581 case 24:
8582 val |= PIPEMISC_DITHER_8_BPC;
8583 break;
8584 case 30:
8585 val |= PIPEMISC_DITHER_10_BPC;
8586 break;
8587 case 36:
8588 val |= PIPEMISC_DITHER_12_BPC;
8589 break;
8590 default:
8591 /* Case prevented by pipe_config_set_bpp. */
8592 BUG();
8593 }
8594
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008595 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008596 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8597
Shashank Sharma8c79f842018-10-12 11:53:09 +05308598 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8599 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308600 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308601
8602 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308603 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308604 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308605
Jani Nikula391bf042016-03-18 17:05:40 +02008606 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008607 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008608}
8609
Paulo Zanonid4b19312012-11-29 11:29:32 -02008610int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8611{
8612 /*
8613 * Account for spread spectrum to avoid
8614 * oversubscribing the link. Max center spread
8615 * is 2.5%; use 5% for safety's sake.
8616 */
8617 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008618 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008619}
8620
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008621static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008622{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008623 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008624}
8625
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008626static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8627 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008628 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008629{
8630 struct drm_crtc *crtc = &intel_crtc->base;
8631 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008632 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008633 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008634 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008635
Chris Wilsonc1858122010-12-03 21:35:48 +00008636 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008637 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008638 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008639 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008640 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008641 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008642 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008643 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008644 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008645
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008646 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008647
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008648 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8649 fp |= FP_CB_TUNE;
8650
8651 if (reduced_clock) {
8652 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8653
8654 if (reduced_clock->m < factor * reduced_clock->n)
8655 fp2 |= FP_CB_TUNE;
8656 } else {
8657 fp2 = fp;
8658 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008659
Chris Wilson5eddb702010-09-11 13:48:45 +01008660 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008661
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008662 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008663 dpll |= DPLLB_MODE_LVDS;
8664 else
8665 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008666
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008667 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008668 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008669
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008670 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8671 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008672 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008673
Ville Syrjälä37a56502016-06-22 21:57:04 +03008674 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008675 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008676
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008677 /*
8678 * The high speed IO clock is only really required for
8679 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8680 * possible to share the DPLL between CRT and HDMI. Enabling
8681 * the clock needlessly does no real harm, except use up a
8682 * bit of power potentially.
8683 *
8684 * We'll limit this to IVB with 3 pipes, since it has only two
8685 * DPLLs and so DPLL sharing is the only way to get three pipes
8686 * driving PCH ports at the same time. On SNB we could do this,
8687 * and potentially avoid enabling the second DPLL, but it's not
8688 * clear if it''s a win or loss power wise. No point in doing
8689 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8690 */
8691 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8692 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8693 dpll |= DPLL_SDVO_HIGH_SPEED;
8694
Eric Anholta07d6782011-03-30 13:01:08 -07008695 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008696 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008697 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008698 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008699
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008700 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008701 case 5:
8702 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8703 break;
8704 case 7:
8705 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8706 break;
8707 case 10:
8708 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8709 break;
8710 case 14:
8711 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8712 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008713 }
8714
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008715 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8716 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008717 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008718 else
8719 dpll |= PLL_REF_INPUT_DREFCLK;
8720
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008721 dpll |= DPLL_VCO_ENABLE;
8722
8723 crtc_state->dpll_hw_state.dpll = dpll;
8724 crtc_state->dpll_hw_state.fp0 = fp;
8725 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008726}
8727
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008728static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8729 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008730{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008731 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008732 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008733 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008734 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008735
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008736 memset(&crtc_state->dpll_hw_state, 0,
8737 sizeof(crtc_state->dpll_hw_state));
8738
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008739 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8740 if (!crtc_state->has_pch_encoder)
8741 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008742
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008743 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008744 if (intel_panel_use_ssc(dev_priv)) {
8745 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8746 dev_priv->vbt.lvds_ssc_freq);
8747 refclk = dev_priv->vbt.lvds_ssc_freq;
8748 }
8749
8750 if (intel_is_dual_link_lvds(dev)) {
8751 if (refclk == 100000)
8752 limit = &intel_limits_ironlake_dual_lvds_100m;
8753 else
8754 limit = &intel_limits_ironlake_dual_lvds;
8755 } else {
8756 if (refclk == 100000)
8757 limit = &intel_limits_ironlake_single_lvds_100m;
8758 else
8759 limit = &intel_limits_ironlake_single_lvds;
8760 }
8761 } else {
8762 limit = &intel_limits_ironlake_dac;
8763 }
8764
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008765 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008766 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8767 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008768 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8769 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008770 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008771
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008772 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008773
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008774 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008775 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8776 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008777 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008778 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008779
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008780 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008781}
8782
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008783static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8784 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008785{
8786 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008787 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008788 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008789
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008790 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8791 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8792 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8793 & ~TU_SIZE_MASK;
8794 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8795 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8796 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8797}
8798
8799static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8800 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008801 struct intel_link_m_n *m_n,
8802 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008803{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008804 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008805 enum pipe pipe = crtc->pipe;
8806
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008807 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008808 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8809 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8810 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8811 & ~TU_SIZE_MASK;
8812 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8813 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8814 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02008815
8816 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008817 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8818 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8819 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8820 & ~TU_SIZE_MASK;
8821 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8822 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8823 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8824 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008825 } else {
8826 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8827 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8828 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8829 & ~TU_SIZE_MASK;
8830 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8831 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8832 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8833 }
8834}
8835
8836void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008837 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008838{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02008839 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008840 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8841 else
8842 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008843 &pipe_config->dp_m_n,
8844 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008845}
8846
Daniel Vetter72419202013-04-04 13:28:53 +02008847static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008848 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02008849{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008850 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008851 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02008852}
8853
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008854static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008855 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008856{
8857 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008858 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07008859 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8860 uint32_t ps_ctrl = 0;
8861 int id = -1;
8862 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008863
Chandra Kondurua1b22782015-04-07 15:28:45 -07008864 /* find scaler attached to this pipe */
8865 for (i = 0; i < crtc->num_scalers; i++) {
8866 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8867 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8868 id = i;
8869 pipe_config->pch_pfit.enabled = true;
8870 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8871 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8872 break;
8873 }
8874 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008875
Chandra Kondurua1b22782015-04-07 15:28:45 -07008876 scaler_state->scaler_id = id;
8877 if (id >= 0) {
8878 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8879 } else {
8880 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008881 }
8882}
8883
Damien Lespiau5724dbd2015-01-20 12:51:52 +00008884static void
8885skylake_get_initial_plane_config(struct intel_crtc *crtc,
8886 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008887{
8888 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008889 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008890 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8891 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008892 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08008893 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008894 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00008895 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008896 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00008897 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008898
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008899 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02008900 return;
8901
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008902 WARN_ON(pipe != crtc->pipe);
8903
Damien Lespiaud9806c92015-01-21 14:07:19 +00008904 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00008905 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008906 DRM_DEBUG_KMS("failed to alloc fb\n");
8907 return;
8908 }
8909
Damien Lespiau1b842c82015-01-21 13:50:54 +00008910 fb = &intel_fb->base;
8911
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02008912 fb->dev = dev;
8913
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008914 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00008915
James Ausmusb5972772018-01-30 11:49:16 -02008916 if (INTEL_GEN(dev_priv) >= 11)
8917 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8918 else
8919 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08008920
8921 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008922 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08008923 alpha &= PLANE_COLOR_ALPHA_MASK;
8924 } else {
8925 alpha = val & PLANE_CTL_ALPHA_MASK;
8926 }
8927
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008928 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08008929 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02008930 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008931
Damien Lespiau40f46282015-02-27 11:15:21 +00008932 tiling = val & PLANE_CTL_TILED_MASK;
8933 switch (tiling) {
8934 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07008935 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00008936 break;
8937 case PLANE_CTL_TILED_X:
8938 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02008939 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008940 break;
8941 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03008942 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008943 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008944 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8945 else
8946 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008947 break;
8948 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008949 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008950 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8951 else
8952 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008953 break;
8954 default:
8955 MISSING_CASE(tiling);
8956 goto error;
8957 }
8958
Ville Syrjäläf43348a2018-11-20 15:54:50 +02008959 /*
8960 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
8961 * while i915 HW rotation is clockwise, thats why this swapping.
8962 */
8963 switch (val & PLANE_CTL_ROTATE_MASK) {
8964 case PLANE_CTL_ROTATE_0:
8965 plane_config->rotation = DRM_MODE_ROTATE_0;
8966 break;
8967 case PLANE_CTL_ROTATE_90:
8968 plane_config->rotation = DRM_MODE_ROTATE_270;
8969 break;
8970 case PLANE_CTL_ROTATE_180:
8971 plane_config->rotation = DRM_MODE_ROTATE_180;
8972 break;
8973 case PLANE_CTL_ROTATE_270:
8974 plane_config->rotation = DRM_MODE_ROTATE_90;
8975 break;
8976 }
8977
8978 if (INTEL_GEN(dev_priv) >= 10 &&
8979 val & PLANE_CTL_FLIP_HORIZONTAL)
8980 plane_config->rotation |= DRM_MODE_REFLECT_X;
8981
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008982 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008983 plane_config->base = base;
8984
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008985 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008986
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008987 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008988 fb->height = ((val >> 16) & 0xfff) + 1;
8989 fb->width = ((val >> 0) & 0x1fff) + 1;
8990
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008991 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03008992 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008993 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8994
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008995 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008996
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008997 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008998
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008999 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9000 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02009001 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009002 plane_config->size);
9003
Damien Lespiau2d140302015-02-05 17:22:18 +00009004 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009005 return;
9006
9007error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01009008 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009009}
9010
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009011static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009012 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009013{
9014 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009015 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009016 uint32_t tmp;
9017
9018 tmp = I915_READ(PF_CTL(crtc->pipe));
9019
9020 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01009021 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009022 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9023 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009024
9025 /* We currently do not free assignements of panel fitters on
9026 * ivb/hsw (since we don't use the higher upscaling modes which
9027 * differentiates them) so just WARN about this case for now. */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08009028 if (IS_GEN(dev_priv, 7)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009029 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9030 PF_PIPE_SEL_IVB(crtc->pipe));
9031 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009032 }
Jesse Barnes79e53942008-11-07 14:24:08 -08009033}
9034
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009035static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009036 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009037{
9038 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009039 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02009040 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009041 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02009042 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009043
Imre Deak17290502016-02-12 18:55:11 +02009044 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9045 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni930e8c92014-07-04 13:38:34 -03009046 return false;
9047
Shashank Sharmad9facae2018-10-12 11:53:07 +05309048 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02009049 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009050 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02009051
Imre Deak17290502016-02-12 18:55:11 +02009052 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009053 tmp = I915_READ(PIPECONF(crtc->pipe));
9054 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02009055 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009056
Ville Syrjälä42571ae2013-09-06 23:29:00 +03009057 switch (tmp & PIPECONF_BPC_MASK) {
9058 case PIPECONF_6BPC:
9059 pipe_config->pipe_bpp = 18;
9060 break;
9061 case PIPECONF_8BPC:
9062 pipe_config->pipe_bpp = 24;
9063 break;
9064 case PIPECONF_10BPC:
9065 pipe_config->pipe_bpp = 30;
9066 break;
9067 case PIPECONF_12BPC:
9068 pipe_config->pipe_bpp = 36;
9069 break;
9070 default:
9071 break;
9072 }
9073
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02009074 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9075 pipe_config->limited_color_range = true;
9076
Daniel Vetterab9412b2013-05-03 11:49:46 +02009077 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02009078 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009079 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009080
Daniel Vetter88adfff2013-03-28 10:42:01 +01009081 pipe_config->has_pch_encoder = true;
9082
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009083 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9084 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9085 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02009086
9087 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009088
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03009089 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03009090 /*
9091 * The pipe->pch transcoder and pch transcoder->pll
9092 * mapping is fixed.
9093 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009094 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009095 } else {
9096 tmp = I915_READ(PCH_DPLL_SEL);
9097 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009098 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009099 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009100 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009101 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02009102
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009103 pipe_config->shared_dpll =
9104 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9105 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009106
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009107 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9108 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02009109
9110 tmp = pipe_config->dpll_hw_state.dpll;
9111 pipe_config->pixel_multiplier =
9112 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9113 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03009114
9115 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009116 } else {
9117 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009118 }
9119
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009120 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02009121 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009122
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009123 ironlake_get_pfit_config(crtc, pipe_config);
9124
Imre Deak17290502016-02-12 18:55:11 +02009125 ret = true;
9126
9127out:
9128 intel_display_power_put(dev_priv, power_domain);
9129
9130 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009131}
9132
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009133static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9134{
Chris Wilson91c8a322016-07-05 10:40:23 +01009135 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009136 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009137
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009138 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009139 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009140 pipe_name(crtc->pipe));
9141
Imre Deak75e39682018-08-06 12:58:39 +03009142 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009143 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009144 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009145 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9146 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009147 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009148 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009149 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009150 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009151 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009152 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009153 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009154 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009155 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009156 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009157 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009158
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009159 /*
9160 * In theory we can still leave IRQs enabled, as long as only the HPD
9161 * interrupts remain enabled. We used to check for that, but since it's
9162 * gen-specific and since we only disable LCPLL after we fully disable
9163 * the interrupts, the check below should be enough.
9164 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009165 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009166}
9167
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009168static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9169{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009170 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009171 return I915_READ(D_COMP_HSW);
9172 else
9173 return I915_READ(D_COMP_BDW);
9174}
9175
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009176static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9177{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009178 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009179 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009180 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9181 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009182 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009183 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009184 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009185 I915_WRITE(D_COMP_BDW, val);
9186 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009187 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009188}
9189
9190/*
9191 * This function implements pieces of two sequences from BSpec:
9192 * - Sequence for display software to disable LCPLL
9193 * - Sequence for display software to allow package C8+
9194 * The steps implemented here are just the steps that actually touch the LCPLL
9195 * register. Callers should take care of disabling all the display engine
9196 * functions, doing the mode unset, fixing interrupts, etc.
9197 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009198static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9199 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009200{
9201 uint32_t val;
9202
9203 assert_can_disable_lcpll(dev_priv);
9204
9205 val = I915_READ(LCPLL_CTL);
9206
9207 if (switch_to_fclk) {
9208 val |= LCPLL_CD_SOURCE_FCLK;
9209 I915_WRITE(LCPLL_CTL, val);
9210
Imre Deakf53dd632016-06-28 13:37:32 +03009211 if (wait_for_us(I915_READ(LCPLL_CTL) &
9212 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009213 DRM_ERROR("Switching to FCLK failed\n");
9214
9215 val = I915_READ(LCPLL_CTL);
9216 }
9217
9218 val |= LCPLL_PLL_DISABLE;
9219 I915_WRITE(LCPLL_CTL, val);
9220 POSTING_READ(LCPLL_CTL);
9221
Chris Wilson24d84412016-06-30 15:33:07 +01009222 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009223 DRM_ERROR("LCPLL still locked\n");
9224
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009225 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009226 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009227 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009228 ndelay(100);
9229
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009230 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9231 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009232 DRM_ERROR("D_COMP RCOMP still in progress\n");
9233
9234 if (allow_power_down) {
9235 val = I915_READ(LCPLL_CTL);
9236 val |= LCPLL_POWER_DOWN_ALLOW;
9237 I915_WRITE(LCPLL_CTL, val);
9238 POSTING_READ(LCPLL_CTL);
9239 }
9240}
9241
9242/*
9243 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9244 * source.
9245 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009246static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009247{
9248 uint32_t val;
9249
9250 val = I915_READ(LCPLL_CTL);
9251
9252 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9253 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9254 return;
9255
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009256 /*
9257 * Make sure we're not on PC8 state before disabling PC8, otherwise
9258 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009259 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009260 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009261
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009262 if (val & LCPLL_POWER_DOWN_ALLOW) {
9263 val &= ~LCPLL_POWER_DOWN_ALLOW;
9264 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009265 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009266 }
9267
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009268 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009269 val |= D_COMP_COMP_FORCE;
9270 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009271 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009272
9273 val = I915_READ(LCPLL_CTL);
9274 val &= ~LCPLL_PLL_DISABLE;
9275 I915_WRITE(LCPLL_CTL, val);
9276
Chris Wilson93220c02016-06-30 15:33:08 +01009277 if (intel_wait_for_register(dev_priv,
9278 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9279 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009280 DRM_ERROR("LCPLL not locked yet\n");
9281
9282 if (val & LCPLL_CD_SOURCE_FCLK) {
9283 val = I915_READ(LCPLL_CTL);
9284 val &= ~LCPLL_CD_SOURCE_FCLK;
9285 I915_WRITE(LCPLL_CTL, val);
9286
Imre Deakf53dd632016-06-28 13:37:32 +03009287 if (wait_for_us((I915_READ(LCPLL_CTL) &
9288 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009289 DRM_ERROR("Switching back to LCPLL failed\n");
9290 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009291
Mika Kuoppala59bad942015-01-16 11:34:40 +02009292 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009293
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009294 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009295 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009296}
9297
Paulo Zanoni765dab672014-03-07 20:08:18 -03009298/*
9299 * Package states C8 and deeper are really deep PC states that can only be
9300 * reached when all the devices on the system allow it, so even if the graphics
9301 * device allows PC8+, it doesn't mean the system will actually get to these
9302 * states. Our driver only allows PC8+ when going into runtime PM.
9303 *
9304 * The requirements for PC8+ are that all the outputs are disabled, the power
9305 * well is disabled and most interrupts are disabled, and these are also
9306 * requirements for runtime PM. When these conditions are met, we manually do
9307 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9308 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9309 * hang the machine.
9310 *
9311 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9312 * the state of some registers, so when we come back from PC8+ we need to
9313 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9314 * need to take care of the registers kept by RC6. Notice that this happens even
9315 * if we don't put the device in PCI D3 state (which is what currently happens
9316 * because of the runtime PM support).
9317 *
9318 * For more, read "Display Sequences for Package C8" on the hardware
9319 * documentation.
9320 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009321void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009322{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009323 uint32_t val;
9324
Paulo Zanonic67a4702013-08-19 13:18:09 -03009325 DRM_DEBUG_KMS("Enabling package C8+\n");
9326
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009327 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009328 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9329 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9330 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9331 }
9332
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009333 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009334 hsw_disable_lcpll(dev_priv, true, true);
9335}
9336
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009337void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009338{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009339 uint32_t val;
9340
Paulo Zanonic67a4702013-08-19 13:18:09 -03009341 DRM_DEBUG_KMS("Disabling package C8+\n");
9342
9343 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009344 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009345
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009346 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009347 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9348 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9349 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9350 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009351}
9352
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009353static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9354 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009355{
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009356 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009357 struct intel_atomic_state *state =
9358 to_intel_atomic_state(crtc_state->base.state);
9359
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009360 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9361 IS_ICELAKE(dev_priv)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009362 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009363 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009364
9365 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009366 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9367 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009368 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009369 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009370 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009371
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009372 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009373}
9374
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009375static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9376 enum port port,
9377 struct intel_crtc_state *pipe_config)
9378{
9379 enum intel_dpll_id id;
9380 u32 temp;
9381
9382 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009383 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009384
9385 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9386 return;
9387
9388 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9389}
9390
Paulo Zanoni970888e2018-05-21 17:25:44 -07009391static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9392 enum port port,
9393 struct intel_crtc_state *pipe_config)
9394{
9395 enum intel_dpll_id id;
9396 u32 temp;
9397
9398 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309399 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009400 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9401 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9402 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9403
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309404 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009405 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309406 } else if (intel_port_is_tc(dev_priv, port)) {
Vandita Kulkarnicb6caf72018-10-03 12:51:58 +05309407 id = icl_port_to_mg_pll_id(port);
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309408 } else {
9409 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009410 return;
9411 }
9412
9413 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9414}
9415
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309416static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9417 enum port port,
9418 struct intel_crtc_state *pipe_config)
9419{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009420 enum intel_dpll_id id;
9421
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309422 switch (port) {
9423 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009424 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309425 break;
9426 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009427 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309428 break;
9429 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009430 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309431 break;
9432 default:
9433 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009434 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309435 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009436
9437 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309438}
9439
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009440static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9441 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009442 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009443{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009444 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009445 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009446
9447 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009448 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009449
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009450 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009451 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009452
9453 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009454}
9455
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009456static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9457 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009458 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009459{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009460 enum intel_dpll_id id;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009461 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009462
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009463 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009464 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009465 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009466 break;
9467 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009468 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009469 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009470 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009471 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009472 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009473 case PORT_CLK_SEL_LCPLL_810:
9474 id = DPLL_ID_LCPLL_810;
9475 break;
9476 case PORT_CLK_SEL_LCPLL_1350:
9477 id = DPLL_ID_LCPLL_1350;
9478 break;
9479 case PORT_CLK_SEL_LCPLL_2700:
9480 id = DPLL_ID_LCPLL_2700;
9481 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009482 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009483 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009484 /* fall through */
9485 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009486 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009487 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009488
9489 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009490}
9491
Jani Nikulacf304292016-03-18 17:05:41 +02009492static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9493 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009494 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009495{
9496 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009497 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009498 enum intel_display_power_domain power_domain;
Jani Nikula07169312018-12-04 12:19:26 +02009499 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9500 unsigned long enabled_panel_transcoders = 0;
9501 enum transcoder panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009502 u32 tmp;
Jani Nikula07169312018-12-04 12:19:26 +02009503
9504 if (IS_ICELAKE(dev_priv))
9505 panel_transcoder_mask |=
9506 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
Jani Nikulacf304292016-03-18 17:05:41 +02009507
Imre Deakd9a7bc62016-05-12 16:18:50 +03009508 /*
9509 * The pipe->transcoder mapping is fixed with the exception of the eDP
Jani Nikula07169312018-12-04 12:19:26 +02009510 * and DSI transcoders handled below.
Imre Deakd9a7bc62016-05-12 16:18:50 +03009511 */
Jani Nikulacf304292016-03-18 17:05:41 +02009512 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9513
9514 /*
9515 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9516 * consistency and less surprising code; it's in always on power).
9517 */
Jani Nikula07169312018-12-04 12:19:26 +02009518 for_each_set_bit(panel_transcoder, &panel_transcoder_mask, 32) {
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009519 enum pipe trans_pipe;
Jani Nikula07169312018-12-04 12:19:26 +02009520
9521 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9522 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9523 continue;
9524
9525 /*
9526 * Log all enabled ones, only use the first one.
9527 *
9528 * FIXME: This won't work for two separate DSI displays.
9529 */
9530 enabled_panel_transcoders |= BIT(panel_transcoder);
9531 if (enabled_panel_transcoders != BIT(panel_transcoder))
9532 continue;
9533
Jani Nikulacf304292016-03-18 17:05:41 +02009534 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9535 default:
Jani Nikula07169312018-12-04 12:19:26 +02009536 WARN(1, "unknown pipe linked to transcoder %s\n",
9537 transcoder_name(panel_transcoder));
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009538 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009539 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9540 case TRANS_DDI_EDP_INPUT_A_ON:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009541 trans_pipe = PIPE_A;
Jani Nikulacf304292016-03-18 17:05:41 +02009542 break;
9543 case TRANS_DDI_EDP_INPUT_B_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009544 trans_pipe = PIPE_B;
Jani Nikulacf304292016-03-18 17:05:41 +02009545 break;
9546 case TRANS_DDI_EDP_INPUT_C_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009547 trans_pipe = PIPE_C;
Jani Nikulacf304292016-03-18 17:05:41 +02009548 break;
9549 }
9550
Jani Nikula07169312018-12-04 12:19:26 +02009551 if (trans_pipe == crtc->pipe)
9552 pipe_config->cpu_transcoder = panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009553 }
9554
Jani Nikula07169312018-12-04 12:19:26 +02009555 /*
9556 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9557 */
9558 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9559 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9560
Jani Nikulacf304292016-03-18 17:05:41 +02009561 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9562 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9563 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009564 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009565
9566 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9567
9568 return tmp & PIPECONF_ENABLE;
9569}
9570
Jani Nikula4d1de972016-03-18 17:05:42 +02009571static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9572 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009573 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009574{
9575 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009576 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009577 enum intel_display_power_domain power_domain;
9578 enum port port;
9579 enum transcoder cpu_transcoder;
9580 u32 tmp;
9581
Jani Nikula4d1de972016-03-18 17:05:42 +02009582 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9583 if (port == PORT_A)
9584 cpu_transcoder = TRANSCODER_DSI_A;
9585 else
9586 cpu_transcoder = TRANSCODER_DSI_C;
9587
9588 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9589 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9590 continue;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009591 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009592
Imre Deakdb18b6a2016-03-24 12:41:40 +02009593 /*
9594 * The PLL needs to be enabled with a valid divider
9595 * configuration, otherwise accessing DSI registers will hang
9596 * the machine. See BSpec North Display Engine
9597 * registers/MIPI[BXT]. We can break out here early, since we
9598 * need the same DSI PLL to be enabled for both DSI ports.
9599 */
Jani Nikulae5186342018-07-05 16:25:08 +03009600 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009601 break;
9602
Jani Nikula4d1de972016-03-18 17:05:42 +02009603 /* XXX: this works for video mode only */
9604 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9605 if (!(tmp & DPI_ENABLE))
9606 continue;
9607
9608 tmp = I915_READ(MIPI_CTRL(port));
9609 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9610 continue;
9611
9612 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009613 break;
9614 }
9615
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009616 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009617}
9618
Daniel Vetter26804af2014-06-25 22:01:55 +03009619static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009620 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009621{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009623 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009624 enum port port;
9625 uint32_t tmp;
9626
9627 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9628
9629 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9630
Paulo Zanoni970888e2018-05-21 17:25:44 -07009631 if (IS_ICELAKE(dev_priv))
9632 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9633 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009634 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9635 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009636 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009637 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309638 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009639 else
9640 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009641
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009642 pll = pipe_config->shared_dpll;
9643 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009644 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9645 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009646 }
9647
Daniel Vetter26804af2014-06-25 22:01:55 +03009648 /*
9649 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9650 * DDI E. So just check whether this pipe is wired to DDI E and whether
9651 * the PCH transcoder is on.
9652 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009653 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009654 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009655 pipe_config->has_pch_encoder = true;
9656
9657 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9658 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9659 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9660
9661 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9662 }
9663}
9664
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009665static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009666 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009667{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009668 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009669 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009670 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009671 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009672
Imre Deake79dfb52017-07-20 01:50:57 +03009673 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009674
Imre Deak17290502016-02-12 18:55:11 +02009675 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9676 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009677 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009678 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009679
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009680 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009681
Jani Nikulacf304292016-03-18 17:05:41 +02009682 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009683
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009684 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009685 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9686 WARN_ON(active);
9687 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009688 }
9689
Jani Nikulacf304292016-03-18 17:05:41 +02009690 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009691 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009692
Madhav Chauhan2eae5d62018-11-29 16:12:28 +02009693 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9694 IS_ICELAKE(dev_priv)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009695 haswell_get_ddi_port_state(crtc, pipe_config);
9696 intel_get_pipe_timings(crtc, pipe_config);
9697 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009698
Jani Nikulabc58be62016-03-18 17:05:39 +02009699 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309700 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009701
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009702 pipe_config->gamma_mode =
9703 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9704
Imre Deak17290502016-02-12 18:55:11 +02009705 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9706 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009707 power_domain_mask |= BIT_ULL(power_domain);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009708 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009709 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009710 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009711 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009712 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009713
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009714 if (hsw_crtc_supports_ips(crtc)) {
9715 if (IS_HASWELL(dev_priv))
9716 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9717 else {
9718 /*
9719 * We cannot readout IPS state on broadwell, set to
9720 * true so we can set it to a defined state on first
9721 * commit.
9722 */
9723 pipe_config->ips_enabled = true;
9724 }
9725 }
9726
Jani Nikula4d1de972016-03-18 17:05:42 +02009727 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9728 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009729 pipe_config->pixel_multiplier =
9730 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9731 } else {
9732 pipe_config->pixel_multiplier = 1;
9733 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009734
Imre Deak17290502016-02-12 18:55:11 +02009735out:
9736 for_each_power_domain(power_domain, power_domain_mask)
9737 intel_display_power_put(dev_priv, power_domain);
9738
Jani Nikulacf304292016-03-18 17:05:41 +02009739 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009740}
9741
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009742static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009743{
9744 struct drm_i915_private *dev_priv =
9745 to_i915(plane_state->base.plane->dev);
9746 const struct drm_framebuffer *fb = plane_state->base.fb;
9747 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9748 u32 base;
9749
José Roberto de Souzad53db442018-11-30 15:20:48 -08009750 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009751 base = obj->phys_handle->busaddr;
9752 else
9753 base = intel_plane_ggtt_offset(plane_state);
9754
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009755 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009756
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009757 /* ILK+ do this automagically */
9758 if (HAS_GMCH_DISPLAY(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009759 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009760 base += (plane_state->base.crtc_h *
9761 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9762
9763 return base;
9764}
9765
Ville Syrjäläed270222017-03-27 21:55:36 +03009766static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9767{
9768 int x = plane_state->base.crtc_x;
9769 int y = plane_state->base.crtc_y;
9770 u32 pos = 0;
9771
9772 if (x < 0) {
9773 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9774 x = -x;
9775 }
9776 pos |= x << CURSOR_X_SHIFT;
9777
9778 if (y < 0) {
9779 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9780 y = -y;
9781 }
9782 pos |= y << CURSOR_Y_SHIFT;
9783
9784 return pos;
9785}
9786
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009787static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9788{
9789 const struct drm_mode_config *config =
9790 &plane_state->base.plane->dev->mode_config;
9791 int width = plane_state->base.crtc_w;
9792 int height = plane_state->base.crtc_h;
9793
9794 return width > 0 && width <= config->cursor_width &&
9795 height > 0 && height <= config->cursor_height;
9796}
9797
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009798static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009799{
9800 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009801 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009802 int src_x, src_y;
9803 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009804 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009805
9806 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9807 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9808
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009809 ret = intel_plane_check_stride(plane_state);
9810 if (ret)
9811 return ret;
9812
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009813 src_x = plane_state->base.src_x >> 16;
9814 src_y = plane_state->base.src_y >> 16;
9815
9816 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9817 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9818 plane_state, 0);
9819
9820 if (src_x != 0 || src_y != 0) {
9821 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9822 return -EINVAL;
9823 }
9824
9825 plane_state->color_plane[0].offset = offset;
9826
9827 return 0;
9828}
9829
9830static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9831 struct intel_plane_state *plane_state)
9832{
9833 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009834 int ret;
9835
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009836 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9837 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9838 return -EINVAL;
9839 }
9840
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009841 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9842 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009843 DRM_PLANE_HELPER_NO_SCALING,
9844 DRM_PLANE_HELPER_NO_SCALING,
9845 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009846 if (ret)
9847 return ret;
9848
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009849 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009850 return 0;
9851
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009852 ret = intel_plane_check_src_coordinates(plane_state);
9853 if (ret)
9854 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009855
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009856 ret = intel_cursor_check_surface(plane_state);
9857 if (ret)
9858 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009859
Ville Syrjälä659056f2017-03-27 21:55:39 +03009860 return 0;
9861}
9862
Ville Syrjäläddd57132018-09-07 18:24:02 +03009863static unsigned int
9864i845_cursor_max_stride(struct intel_plane *plane,
9865 u32 pixel_format, u64 modifier,
9866 unsigned int rotation)
9867{
9868 return 2048;
9869}
9870
Ville Syrjälä292889e2017-03-17 23:18:01 +02009871static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9872 const struct intel_plane_state *plane_state)
9873{
Ville Syrjälä292889e2017-03-17 23:18:01 +02009874 return CURSOR_ENABLE |
9875 CURSOR_GAMMA_ENABLE |
9876 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009877 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009878}
9879
Ville Syrjälä659056f2017-03-27 21:55:39 +03009880static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9881{
Ville Syrjälä659056f2017-03-27 21:55:39 +03009882 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009883
9884 /*
9885 * 845g/865g are only limited by the width of their cursors,
9886 * the height is arbitrary up to the precision of the register.
9887 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009888 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009889}
9890
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009891static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009892 struct intel_plane_state *plane_state)
9893{
9894 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009895 int ret;
9896
9897 ret = intel_check_cursor(crtc_state, plane_state);
9898 if (ret)
9899 return ret;
9900
9901 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009902 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009903 return 0;
9904
9905 /* Check for which cursor types we support */
9906 if (!i845_cursor_size_ok(plane_state)) {
9907 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9908 plane_state->base.crtc_w,
9909 plane_state->base.crtc_h);
9910 return -EINVAL;
9911 }
9912
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009913 WARN_ON(plane_state->base.visible &&
9914 plane_state->color_plane[0].stride != fb->pitches[0]);
9915
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009916 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +01009917 case 256:
9918 case 512:
9919 case 1024:
9920 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +03009921 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009922 default:
9923 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9924 fb->pitches[0]);
9925 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +01009926 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009927
Ville Syrjälä659056f2017-03-27 21:55:39 +03009928 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9929
9930 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009931}
9932
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009933static void i845_update_cursor(struct intel_plane *plane,
9934 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +01009935 const struct intel_plane_state *plane_state)
9936{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009937 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009938 u32 cntl = 0, base = 0, pos = 0, size = 0;
9939 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +01009940
Ville Syrjälä936e71e2016-07-26 19:06:59 +03009941 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009942 unsigned int width = plane_state->base.crtc_w;
9943 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009944
Ville Syrjäläa0864d52017-03-23 21:27:09 +02009945 cntl = plane_state->ctl;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009946 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009947
9948 base = intel_cursor_base(plane_state);
9949 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +03009950 }
Chris Wilson560b85b2010-08-07 11:01:38 +01009951
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009952 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9953
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009954 /* On these chipsets we can only modify the base/size/stride
9955 * whilst the cursor is disabled.
9956 */
9957 if (plane->cursor.base != base ||
9958 plane->cursor.size != size ||
9959 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009960 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009961 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009962 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009963 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009964 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +03009965
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009966 plane->cursor.base = base;
9967 plane->cursor.size = size;
9968 plane->cursor.cntl = cntl;
9969 } else {
9970 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +03009971 }
9972
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009973 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9974}
9975
9976static void i845_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02009977 const struct intel_crtc_state *crtc_state)
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009978{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02009979 i845_update_cursor(plane, crtc_state, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +01009980}
9981
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009982static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9983 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009984{
9985 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9986 enum intel_display_power_domain power_domain;
9987 bool ret;
9988
9989 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9990 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9991 return false;
9992
9993 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9994
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009995 *pipe = PIPE_A;
9996
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009997 intel_display_power_put(dev_priv, power_domain);
9998
9999 return ret;
10000}
10001
Ville Syrjäläddd57132018-09-07 18:24:02 +030010002static unsigned int
10003i9xx_cursor_max_stride(struct intel_plane *plane,
10004 u32 pixel_format, u64 modifier,
10005 unsigned int rotation)
10006{
10007 return plane->base.dev->mode_config.cursor_width * 4;
10008}
10009
Ville Syrjälä292889e2017-03-17 23:18:01 +020010010static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10011 const struct intel_plane_state *plane_state)
10012{
10013 struct drm_i915_private *dev_priv =
10014 to_i915(plane_state->base.plane->dev);
10015 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
José Roberto de Souzac894d632018-05-18 13:15:47 -070010016 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010017
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010018 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjäläe876b782018-01-30 22:38:05 +020010019 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10020
José Roberto de Souzac894d632018-05-18 13:15:47 -070010021 if (INTEL_GEN(dev_priv) <= 10) {
10022 cntl |= MCURSOR_GAMMA_ENABLE;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010023
José Roberto de Souzac894d632018-05-18 13:15:47 -070010024 if (HAS_DDI(dev_priv))
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010025 cntl |= MCURSOR_PIPE_CSC_ENABLE;
José Roberto de Souzac894d632018-05-18 13:15:47 -070010026 }
Ville Syrjälä292889e2017-03-17 23:18:01 +020010027
Ville Syrjälä32ea06b2018-01-30 22:38:01 +020010028 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10029 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
Ville Syrjälä292889e2017-03-17 23:18:01 +020010030
10031 switch (plane_state->base.crtc_w) {
10032 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010033 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010034 break;
10035 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010036 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010037 break;
10038 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010039 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010040 break;
10041 default:
10042 MISSING_CASE(plane_state->base.crtc_w);
10043 return 0;
10044 }
10045
Robert Fossc2c446a2017-05-19 16:50:17 -040010046 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010047 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010048
10049 return cntl;
10050}
10051
Ville Syrjälä659056f2017-03-27 21:55:39 +030010052static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +010010053{
Ville Syrjälä024faac2017-03-27 21:55:42 +030010054 struct drm_i915_private *dev_priv =
10055 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010056 int width = plane_state->base.crtc_w;
10057 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +010010058
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010059 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +030010060 return false;
10061
Ville Syrjälä024faac2017-03-27 21:55:42 +030010062 /* Cursor width is limited to a few power-of-two sizes */
10063 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +030010064 case 256:
10065 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +030010066 case 64:
10067 break;
10068 default:
10069 return false;
10070 }
10071
Ville Syrjälädc41c152014-08-13 11:57:05 +030010072 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +030010073 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10074 * height from 8 lines up to the cursor width, when the
10075 * cursor is not rotated. Everything else requires square
10076 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +030010077 */
Ville Syrjälä024faac2017-03-27 21:55:42 +030010078 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +100010079 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010080 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010081 return false;
10082 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010083 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010084 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010085 }
10086
10087 return true;
10088}
10089
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010090static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010091 struct intel_plane_state *plane_state)
10092{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010093 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010094 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10095 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010096 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010097 int ret;
10098
10099 ret = intel_check_cursor(crtc_state, plane_state);
10100 if (ret)
10101 return ret;
10102
10103 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010104 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010105 return 0;
10106
10107 /* Check for which cursor types we support */
10108 if (!i9xx_cursor_size_ok(plane_state)) {
10109 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10110 plane_state->base.crtc_w,
10111 plane_state->base.crtc_h);
10112 return -EINVAL;
10113 }
10114
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010115 WARN_ON(plane_state->base.visible &&
10116 plane_state->color_plane[0].stride != fb->pitches[0]);
10117
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010118 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10119 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10120 fb->pitches[0], plane_state->base.crtc_w);
10121 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010122 }
10123
10124 /*
10125 * There's something wrong with the cursor on CHV pipe C.
10126 * If it straddles the left edge of the screen then
10127 * moving it away from the edge or disabling it often
10128 * results in a pipe underrun, and often that can lead to
10129 * dead pipe (constant underrun reported, and it scans
10130 * out just a solid color). To recover from that, the
10131 * display power well must be turned off and on again.
10132 * Refuse the put the cursor into that compromised position.
10133 */
10134 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10135 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10136 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10137 return -EINVAL;
10138 }
10139
10140 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10141
10142 return 0;
10143}
10144
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010145static void i9xx_update_cursor(struct intel_plane *plane,
10146 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010147 const struct intel_plane_state *plane_state)
10148{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010149 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10150 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +030010151 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010152 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010153
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010154 if (plane_state && plane_state->base.visible) {
Ville Syrjäläa0864d52017-03-23 21:27:09 +020010155 cntl = plane_state->ctl;
Chris Wilson4b0e3332014-05-30 16:35:26 +030010156
Ville Syrjälä024faac2017-03-27 21:55:42 +030010157 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10158 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10159
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010160 base = intel_cursor_base(plane_state);
10161 pos = intel_cursor_position(plane_state);
10162 }
10163
10164 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10165
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010166 /*
10167 * On some platforms writing CURCNTR first will also
10168 * cause CURPOS to be armed by the CURBASE write.
10169 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä83234d12018-11-14 23:07:17 +020010170 * arm itself. Thus we always update CURCNTR before
10171 * CURPOS.
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010172 *
10173 * On other platforms CURPOS always requires the
10174 * CURBASE write to arm the update. Additonally
10175 * a write to any of the cursor register will cancel
10176 * an already armed cursor update. Thus leaving out
10177 * the CURBASE write after CURPOS could lead to a
10178 * cursor that doesn't appear to move, or even change
10179 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010180 *
Ville Syrjälä83234d12018-11-14 23:07:17 +020010181 * The other registers are armed by by the CURBASE write
10182 * except when the plane is getting enabled at which time
10183 * the CURCNTR write arms the update.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010184 */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020010185
10186 if (INTEL_GEN(dev_priv) >= 9)
10187 skl_write_cursor_wm(plane, crtc_state);
10188
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010189 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010190 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010191 plane->cursor.cntl != cntl) {
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010192 if (HAS_CUR_FBC(dev_priv))
10193 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
Ville Syrjälä83234d12018-11-14 23:07:17 +020010194 I915_WRITE_FW(CURCNTR(pipe), cntl);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010195 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010196 I915_WRITE_FW(CURBASE(pipe), base);
10197
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010198 plane->cursor.base = base;
10199 plane->cursor.size = fbc_ctl;
10200 plane->cursor.cntl = cntl;
10201 } else {
10202 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010203 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010204 }
10205
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010206 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010207}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010208
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010209static void i9xx_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010210 const struct intel_crtc_state *crtc_state)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010211{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010212 i9xx_update_cursor(plane, crtc_state, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010213}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010214
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010215static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10216 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010217{
10218 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10219 enum intel_display_power_domain power_domain;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010220 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010221 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010222
10223 /*
10224 * Not 100% correct for planes that can move between pipes,
10225 * but that's only the case for gen2-3 which don't have any
10226 * display power wells.
10227 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010228 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010229 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10230 return false;
10231
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010232 val = I915_READ(CURCNTR(plane->pipe));
10233
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010234 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010235
10236 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10237 *pipe = plane->pipe;
10238 else
10239 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10240 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010241
10242 intel_display_power_put(dev_priv, power_domain);
10243
10244 return ret;
10245}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010246
Jesse Barnes79e53942008-11-07 14:24:08 -080010247/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010248static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010249 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10250 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10251};
10252
Daniel Vettera8bb6812014-02-10 18:00:39 +010010253struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010254intel_framebuffer_create(struct drm_i915_gem_object *obj,
10255 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010256{
10257 struct intel_framebuffer *intel_fb;
10258 int ret;
10259
10260 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010261 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010262 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010263
Chris Wilson24dbf512017-02-15 10:59:18 +000010264 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010265 if (ret)
10266 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010267
10268 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010269
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010270err:
10271 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010272 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010273}
10274
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010275static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10276 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010277{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010278 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010279 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010280 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010281
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010282 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010283 if (ret)
10284 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010285
10286 for_each_new_plane_in_state(state, plane, plane_state, i) {
10287 if (plane_state->crtc != crtc)
10288 continue;
10289
10290 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10291 if (ret)
10292 return ret;
10293
10294 drm_atomic_set_fb_for_plane(plane_state, NULL);
10295 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010296
10297 return 0;
10298}
10299
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010300int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010301 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010302 struct intel_load_detect_pipe *old,
10303 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010304{
10305 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010306 struct intel_encoder *intel_encoder =
10307 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010308 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010309 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010310 struct drm_crtc *crtc = NULL;
10311 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010312 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010313 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010314 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010315 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010316 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010317 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010318
Chris Wilsond2dff872011-04-19 08:36:26 +010010319 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010320 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010321 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010322
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010323 old->restore_state = NULL;
10324
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010325 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010326
Jesse Barnes79e53942008-11-07 14:24:08 -080010327 /*
10328 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010329 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010330 * - if the connector already has an assigned crtc, use it (but make
10331 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010332 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010333 * - try to find the first unused crtc that can drive this connector,
10334 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010335 */
10336
10337 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010338 if (connector->state->crtc) {
10339 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010340
Rob Clark51fd3712013-11-19 12:10:12 -050010341 ret = drm_modeset_lock(&crtc->mutex, ctx);
10342 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010343 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010344
10345 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010346 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010347 }
10348
10349 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010350 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010351 i++;
10352 if (!(encoder->possible_crtcs & (1 << i)))
10353 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010354
10355 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10356 if (ret)
10357 goto fail;
10358
10359 if (possible_crtc->state->enable) {
10360 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010361 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010362 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010363
10364 crtc = possible_crtc;
10365 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010366 }
10367
10368 /*
10369 * If we didn't find an unused CRTC, don't use any.
10370 */
10371 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010372 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010373 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010374 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010375 }
10376
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010377found:
10378 intel_crtc = to_intel_crtc(crtc);
10379
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010380 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010381 restore_state = drm_atomic_state_alloc(dev);
10382 if (!state || !restore_state) {
10383 ret = -ENOMEM;
10384 goto fail;
10385 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010386
10387 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010388 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010389
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010390 connector_state = drm_atomic_get_connector_state(state, connector);
10391 if (IS_ERR(connector_state)) {
10392 ret = PTR_ERR(connector_state);
10393 goto fail;
10394 }
10395
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010396 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10397 if (ret)
10398 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010399
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010400 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10401 if (IS_ERR(crtc_state)) {
10402 ret = PTR_ERR(crtc_state);
10403 goto fail;
10404 }
10405
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010406 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010407
Chris Wilson64927112011-04-20 07:25:26 +010010408 if (!mode)
10409 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010410
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010411 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010412 if (ret)
10413 goto fail;
10414
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010415 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010416 if (ret)
10417 goto fail;
10418
10419 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10420 if (!ret)
10421 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010422 if (!ret)
10423 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010424 if (ret) {
10425 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10426 goto fail;
10427 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010428
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010429 ret = drm_atomic_commit(state);
10430 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010431 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010432 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010433 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010434
10435 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010436 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010437
Jesse Barnes79e53942008-11-07 14:24:08 -080010438 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010439 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010440 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010441
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010442fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010443 if (state) {
10444 drm_atomic_state_put(state);
10445 state = NULL;
10446 }
10447 if (restore_state) {
10448 drm_atomic_state_put(restore_state);
10449 restore_state = NULL;
10450 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010451
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010452 if (ret == -EDEADLK)
10453 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010454
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010455 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010456}
10457
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010458void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010459 struct intel_load_detect_pipe *old,
10460 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010461{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010462 struct intel_encoder *intel_encoder =
10463 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010464 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010465 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010466 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010467
Chris Wilsond2dff872011-04-19 08:36:26 +010010468 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010469 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010470 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010471
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010472 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010473 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010474
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010475 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010476 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010477 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010478 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010479}
10480
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010481static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010482 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010483{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010484 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010485 u32 dpll = pipe_config->dpll_hw_state.dpll;
10486
10487 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010488 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010489 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010490 return 120000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010491 else if (!IS_GEN(dev_priv, 2))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010492 return 96000;
10493 else
10494 return 48000;
10495}
10496
Jesse Barnes79e53942008-11-07 14:24:08 -080010497/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010498static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010499 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010500{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010501 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010502 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010503 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010504 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010505 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010506 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010507 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010508 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010509
10510 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010511 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010512 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010513 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010514
10515 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010516 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010517 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10518 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010519 } else {
10520 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10521 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10522 }
10523
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010524 if (!IS_GEN(dev_priv, 2)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010525 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010526 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10527 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010528 else
10529 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010530 DPLL_FPA01_P1_POST_DIV_SHIFT);
10531
10532 switch (dpll & DPLL_MODE_MASK) {
10533 case DPLLB_MODE_DAC_SERIAL:
10534 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10535 5 : 10;
10536 break;
10537 case DPLLB_MODE_LVDS:
10538 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10539 7 : 14;
10540 break;
10541 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010542 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010543 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010544 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010545 }
10546
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010547 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010548 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010549 else
Imre Deakdccbea32015-06-22 23:35:51 +030010550 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010551 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010552 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010553 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010554
10555 if (is_lvds) {
10556 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10557 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010558
10559 if (lvds & LVDS_CLKB_POWER_UP)
10560 clock.p2 = 7;
10561 else
10562 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010563 } else {
10564 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10565 clock.p1 = 2;
10566 else {
10567 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10568 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10569 }
10570 if (dpll & PLL_P2_DIVIDE_BY_4)
10571 clock.p2 = 4;
10572 else
10573 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010574 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010575
Imre Deakdccbea32015-06-22 23:35:51 +030010576 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010577 }
10578
Ville Syrjälä18442d02013-09-13 16:00:08 +030010579 /*
10580 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010581 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010582 * encoder's get_config() function.
10583 */
Imre Deakdccbea32015-06-22 23:35:51 +030010584 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010585}
10586
Ville Syrjälä6878da02013-09-13 15:59:11 +030010587int intel_dotclock_calculate(int link_freq,
10588 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010589{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010590 /*
10591 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010592 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010593 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010594 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010595 *
10596 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010597 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010598 */
10599
Ville Syrjälä6878da02013-09-13 15:59:11 +030010600 if (!m_n->link_n)
10601 return 0;
10602
Chris Wilson31236982017-09-13 11:51:53 +010010603 return div_u64(mul_u32_u32(m_n->link_m, link_freq), m_n->link_n);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010604}
10605
Ville Syrjälä18442d02013-09-13 16:00:08 +030010606static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010607 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010608{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010610
10611 /* read out port_clock from the DPLL */
10612 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010613
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010614 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010615 * In case there is an active pipe without active ports,
10616 * we may need some idea for the dotclock anyway.
10617 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010618 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010619 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010620 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010621 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010622}
10623
Ville Syrjäläde330812017-10-09 19:19:50 +030010624/* Returns the currently programmed mode of the given encoder. */
10625struct drm_display_mode *
10626intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010627{
Ville Syrjäläde330812017-10-09 19:19:50 +030010628 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10629 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010630 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010631 struct intel_crtc *crtc;
10632 enum pipe pipe;
10633
10634 if (!encoder->get_hw_state(encoder, &pipe))
10635 return NULL;
10636
10637 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010638
10639 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10640 if (!mode)
10641 return NULL;
10642
Ville Syrjäläde330812017-10-09 19:19:50 +030010643 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10644 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010645 kfree(mode);
10646 return NULL;
10647 }
10648
Ville Syrjäläde330812017-10-09 19:19:50 +030010649 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010650
Ville Syrjäläde330812017-10-09 19:19:50 +030010651 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10652 kfree(crtc_state);
10653 kfree(mode);
10654 return NULL;
10655 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010656
Ville Syrjäläde330812017-10-09 19:19:50 +030010657 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010658
Ville Syrjäläde330812017-10-09 19:19:50 +030010659 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010660
Ville Syrjäläde330812017-10-09 19:19:50 +030010661 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010662
Jesse Barnes79e53942008-11-07 14:24:08 -080010663 return mode;
10664}
10665
10666static void intel_crtc_destroy(struct drm_crtc *crtc)
10667{
10668 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10669
10670 drm_crtc_cleanup(crtc);
10671 kfree(intel_crtc);
10672}
10673
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010674/**
10675 * intel_wm_need_update - Check whether watermarks need updating
Chris Wilson6bf19812018-12-31 14:35:05 +000010676 * @cur: current plane state
10677 * @new: new plane state
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010678 *
10679 * Check current plane state versus the new one to determine whether
10680 * watermarks need to be recalculated.
10681 *
10682 * Returns true or false.
10683 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010684static bool intel_wm_need_update(struct intel_plane_state *cur,
10685 struct intel_plane_state *new)
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010686{
Matt Roperd21fbe82015-09-24 15:53:12 -070010687 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010688 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010689 return true;
10690
10691 if (!cur->base.fb || !new->base.fb)
10692 return false;
10693
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010694 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010695 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010696 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10697 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10698 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10699 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010700 return true;
10701
10702 return false;
10703}
10704
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010705static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010706{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010707 int src_w = drm_rect_width(&state->base.src) >> 16;
10708 int src_h = drm_rect_height(&state->base.src) >> 16;
10709 int dst_w = drm_rect_width(&state->base.dst);
10710 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010711
10712 return (src_w != dst_w || src_h != dst_h);
10713}
10714
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010715int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10716 struct drm_crtc_state *crtc_state,
10717 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010718 struct drm_plane_state *plane_state)
10719{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010720 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010721 struct drm_crtc *crtc = crtc_state->crtc;
10722 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010723 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010724 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010725 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010726 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010727 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010728 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010729 bool turn_off, turn_on, visible, was_visible;
10730 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010731 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010732
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010733 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010734 ret = skl_update_scaler_plane(
10735 to_intel_crtc_state(crtc_state),
10736 to_intel_plane_state(plane_state));
10737 if (ret)
10738 return ret;
10739 }
10740
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010741 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010742 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010743
10744 if (!was_crtc_enabled && WARN_ON(was_visible))
10745 was_visible = false;
10746
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010747 /*
10748 * Visibility is calculated as if the crtc was on, but
10749 * after scaler setup everything depends on it being off
10750 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010751 *
10752 * FIXME this is wrong for watermarks. Watermarks should also
10753 * be computed as if the pipe would be active. Perhaps move
10754 * per-plane wm computation to the .check_plane() hook, and
10755 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010756 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010757 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010758 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010759 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10760 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010761
10762 if (!was_visible && !visible)
10763 return 0;
10764
Maarten Lankhorste8861672016-02-24 11:24:26 +010010765 if (fb != old_plane_state->base.fb)
10766 pipe_config->fb_changed = true;
10767
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010768 turn_off = was_visible && (!visible || mode_changed);
10769 turn_on = visible && (!was_visible || mode_changed);
10770
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010771 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010772 intel_crtc->base.base.id, intel_crtc->base.name,
10773 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010774 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010775
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010776 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] visible %i -> %i, off %i, on %i, ms %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010777 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010778 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010779 turn_off, turn_on, mode_changed);
10780
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010781 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010782 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010783 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010784
10785 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010786 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010787 pipe_config->disable_cxsr = true;
10788 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010789 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010790 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010791
Ville Syrjälä852eb002015-06-24 22:00:07 +030010792 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010793 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010794 pipe_config->disable_cxsr = true;
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010795 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
10796 to_intel_plane_state(plane_state))) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010797 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010798 /* FIXME bollocks */
10799 pipe_config->update_wm_pre = true;
10800 pipe_config->update_wm_post = true;
10801 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030010802 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010803
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070010804 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010805 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030010806
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010807 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010808 * ILK/SNB DVSACNTR/Sprite Enable
10809 * IVB SPR_CTL/Sprite Enable
10810 * "When in Self Refresh Big FIFO mode, a write to enable the
10811 * plane will be internally buffered and delayed while Big FIFO
10812 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010813 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010814 * Which means that enabling the sprite can take an extra frame
10815 * when we start in big FIFO mode (LP1+). Thus we need to drop
10816 * down to LP0 and wait for vblank in order to make sure the
10817 * sprite gets enabled on the next vblank after the register write.
10818 * Doing otherwise would risk enabling the sprite one frame after
10819 * we've already signalled flip completion. We can resume LP1+
10820 * once the sprite has been enabled.
10821 *
10822 *
10823 * WaCxSRDisabledForSpriteScaling:ivb
10824 * IVB SPR_SCALE/Scaling Enable
10825 * "Low Power watermarks must be disabled for at least one
10826 * frame before enabling sprite scaling, and kept disabled
10827 * until sprite scaling is disabled."
10828 *
10829 * ILK/SNB DVSASCALE/Scaling Enable
10830 * "When in Self Refresh Big FIFO mode, scaling enable will be
10831 * masked off while Big FIFO mode is exiting."
10832 *
10833 * Despite the w/a only being listed for IVB we assume that
10834 * the ILK/SNB note has similar ramifications, hence we apply
10835 * the w/a on all three platforms.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010836 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010837 if (plane->id == PLANE_SPRITE0 &&
Lucas De Marchif3ce44a2018-12-12 10:10:44 -080010838 (IS_GEN_RANGE(dev_priv, 5, 6) ||
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010839 IS_IVYBRIDGE(dev_priv)) &&
10840 (turn_on || (!needs_scaling(old_plane_state) &&
10841 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010842 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010843
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010844 return 0;
10845}
10846
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010847static bool encoders_cloneable(const struct intel_encoder *a,
10848 const struct intel_encoder *b)
10849{
10850 /* masks could be asymmetric, so check both ways */
10851 return a == b || (a->cloneable & (1 << b->type) &&
10852 b->cloneable & (1 << a->type));
10853}
10854
10855static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10856 struct intel_crtc *crtc,
10857 struct intel_encoder *encoder)
10858{
10859 struct intel_encoder *source_encoder;
10860 struct drm_connector *connector;
10861 struct drm_connector_state *connector_state;
10862 int i;
10863
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010010864 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010865 if (connector_state->crtc != &crtc->base)
10866 continue;
10867
10868 source_encoder =
10869 to_intel_encoder(connector_state->best_encoder);
10870 if (!encoders_cloneable(encoder, source_encoder))
10871 return false;
10872 }
10873
10874 return true;
10875}
10876
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010877static int icl_add_linked_planes(struct intel_atomic_state *state)
10878{
10879 struct intel_plane *plane, *linked;
10880 struct intel_plane_state *plane_state, *linked_plane_state;
10881 int i;
10882
10883 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10884 linked = plane_state->linked_plane;
10885
10886 if (!linked)
10887 continue;
10888
10889 linked_plane_state = intel_atomic_get_plane_state(state, linked);
10890 if (IS_ERR(linked_plane_state))
10891 return PTR_ERR(linked_plane_state);
10892
10893 WARN_ON(linked_plane_state->linked_plane != plane);
10894 WARN_ON(linked_plane_state->slave == plane_state->slave);
10895 }
10896
10897 return 0;
10898}
10899
10900static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
10901{
10902 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10903 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10904 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
10905 struct intel_plane *plane, *linked;
10906 struct intel_plane_state *plane_state;
10907 int i;
10908
10909 if (INTEL_GEN(dev_priv) < 11)
10910 return 0;
10911
10912 /*
10913 * Destroy all old plane links and make the slave plane invisible
10914 * in the crtc_state->active_planes mask.
10915 */
10916 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10917 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
10918 continue;
10919
10920 plane_state->linked_plane = NULL;
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010921 if (plane_state->slave && !plane_state->base.visible) {
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010922 crtc_state->active_planes &= ~BIT(plane->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010923 crtc_state->update_planes |= BIT(plane->id);
10924 }
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010925
10926 plane_state->slave = false;
10927 }
10928
10929 if (!crtc_state->nv12_planes)
10930 return 0;
10931
10932 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10933 struct intel_plane_state *linked_state = NULL;
10934
10935 if (plane->pipe != crtc->pipe ||
10936 !(crtc_state->nv12_planes & BIT(plane->id)))
10937 continue;
10938
10939 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
10940 if (!icl_is_nv12_y_plane(linked->id))
10941 continue;
10942
10943 if (crtc_state->active_planes & BIT(linked->id))
10944 continue;
10945
10946 linked_state = intel_atomic_get_plane_state(state, linked);
10947 if (IS_ERR(linked_state))
10948 return PTR_ERR(linked_state);
10949
10950 break;
10951 }
10952
10953 if (!linked_state) {
10954 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
10955 hweight8(crtc_state->nv12_planes));
10956
10957 return -EINVAL;
10958 }
10959
10960 plane_state->linked_plane = linked;
10961
10962 linked_state->slave = true;
10963 linked_state->linked_plane = plane;
10964 crtc_state->active_planes |= BIT(linked->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010965 crtc_state->update_planes |= BIT(linked->id);
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010966 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
10967 }
10968
10969 return 0;
10970}
10971
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010972static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10973 struct drm_crtc_state *crtc_state)
10974{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010975 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010976 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010977 struct intel_crtc_state *pipe_config =
10978 to_intel_crtc_state(crtc_state);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020010979 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010980 bool mode_changed = needs_modeset(crtc_state);
10981
Ville Syrjälä852eb002015-06-24 22:00:07 +030010982 if (mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010983 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020010984
Maarten Lankhorstad421372015-06-15 12:33:42 +020010985 if (mode_changed && crtc_state->enable &&
10986 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020010987 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020010988 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10989 pipe_config);
10990 if (ret)
10991 return ret;
10992 }
10993
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010994 if (crtc_state->color_mgmt_changed) {
Matt Roper302da0c2018-12-10 13:54:15 -080010995 ret = intel_color_check(pipe_config);
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010996 if (ret)
10997 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010010998
10999 /*
11000 * Changing color management on Intel hardware is
11001 * handled as part of planes update.
11002 */
11003 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000011004 }
11005
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011006 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070011007 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010011008 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011009 if (ret) {
11010 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070011011 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080011012 }
11013 }
11014
Ville Syrjäläf255c622018-11-08 17:10:13 +020011015 if (dev_priv->display.compute_intermediate_wm) {
Matt Ropered4a6a72016-02-23 17:20:13 -080011016 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11017 return 0;
11018
11019 /*
11020 * Calculate 'intermediate' watermarks that satisfy both the
11021 * old state and the new state. We can program these
11022 * immediately.
11023 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011024 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011025 if (ret) {
11026 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11027 return ret;
11028 }
Matt Roper86c8bbb2015-09-24 15:53:16 -070011029 }
11030
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011031 if (INTEL_GEN(dev_priv) >= 9) {
Hans de Goede2c5c4152018-12-17 15:19:03 +010011032 if (mode_changed || pipe_config->update_pipe)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011033 ret = skl_update_scaler_crtc(pipe_config);
11034
11035 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011036 ret = icl_check_nv12_planes(pipe_config);
11037 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053011038 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11039 pipe_config);
11040 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020011041 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011042 pipe_config);
11043 }
11044
Maarten Lankhorst24f28452017-11-22 19:39:01 +010011045 if (HAS_IPS(dev_priv))
11046 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11047
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011048 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011049}
11050
Jani Nikula65b38e02015-04-13 11:26:56 +030011051static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011052 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010011053};
11054
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011055static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11056{
11057 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011058 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011059
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011060 drm_connector_list_iter_begin(dev, &conn_iter);
11061 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020011062 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011063 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020011064
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011065 if (connector->base.encoder) {
11066 connector->base.state->best_encoder =
11067 connector->base.encoder;
11068 connector->base.state->crtc =
11069 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020011070
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011071 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011072 } else {
11073 connector->base.state->best_encoder = NULL;
11074 connector->base.state->crtc = NULL;
11075 }
11076 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011077 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011078}
11079
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011080static int
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011081compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11082 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011083{
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011084 struct drm_connector *connector = conn_state->connector;
11085 const struct drm_display_info *info = &connector->display_info;
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011086 int bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011087
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011088 switch (conn_state->max_bpc) {
11089 case 6 ... 7:
11090 bpp = 6 * 3;
11091 break;
11092 case 8 ... 9:
11093 bpp = 8 * 3;
11094 break;
11095 case 10 ... 11:
11096 bpp = 10 * 3;
11097 break;
11098 case 12:
11099 bpp = 12 * 3;
11100 break;
11101 default:
11102 return -EINVAL;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011103 }
11104
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011105 if (bpp < pipe_config->pipe_bpp) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011106 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11107 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11108 connector->base.id, connector->name,
11109 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011110 pipe_config->pipe_bpp);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011111
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011112 pipe_config->pipe_bpp = bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011113 }
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011114
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011115 return 0;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011116}
11117
11118static int
11119compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011120 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011121{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011122 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011123 struct drm_atomic_state *state = pipe_config->base.state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011124 struct drm_connector *connector;
11125 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011126 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011127
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011128 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11129 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011130 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011131 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011132 bpp = 12*3;
11133 else
11134 bpp = 8*3;
11135
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011136 pipe_config->pipe_bpp = bpp;
11137
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011138 /* Clamp display bpp to connector max bpp */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011139 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011140 int ret;
11141
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011142 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011143 continue;
11144
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011145 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11146 if (ret)
11147 return ret;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011148 }
11149
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011150 return 0;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011151}
11152
Daniel Vetter644db712013-09-19 14:53:58 +020011153static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11154{
11155 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11156 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010011157 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020011158 mode->crtc_hdisplay, mode->crtc_hsync_start,
11159 mode->crtc_hsync_end, mode->crtc_htotal,
11160 mode->crtc_vdisplay, mode->crtc_vsync_start,
11161 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11162}
11163
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011164static inline void
11165intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011166 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011167{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011168 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11169 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011170 m_n->gmch_m, m_n->gmch_n,
11171 m_n->link_m, m_n->link_n, m_n->tu);
11172}
11173
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011174#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11175
11176static const char * const output_type_str[] = {
11177 OUTPUT_TYPE(UNUSED),
11178 OUTPUT_TYPE(ANALOG),
11179 OUTPUT_TYPE(DVO),
11180 OUTPUT_TYPE(SDVO),
11181 OUTPUT_TYPE(LVDS),
11182 OUTPUT_TYPE(TVOUT),
11183 OUTPUT_TYPE(HDMI),
11184 OUTPUT_TYPE(DP),
11185 OUTPUT_TYPE(EDP),
11186 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011187 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011188 OUTPUT_TYPE(DP_MST),
11189};
11190
11191#undef OUTPUT_TYPE
11192
11193static void snprintf_output_types(char *buf, size_t len,
11194 unsigned int output_types)
11195{
11196 char *str = buf;
11197 int i;
11198
11199 str[0] = '\0';
11200
11201 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11202 int r;
11203
11204 if ((output_types & BIT(i)) == 0)
11205 continue;
11206
11207 r = snprintf(str, len, "%s%s",
11208 str != buf ? "," : "", output_type_str[i]);
11209 if (r >= len)
11210 break;
11211 str += r;
11212 len -= r;
11213
11214 output_types &= ~BIT(i);
11215 }
11216
11217 WARN_ON_ONCE(output_types != 0);
11218}
11219
Shashank Sharmad9facae2018-10-12 11:53:07 +053011220static const char * const output_format_str[] = {
11221 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11222 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011223 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011224 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011225};
11226
11227static const char *output_formats(enum intel_output_format format)
11228{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011229 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011230 format = INTEL_OUTPUT_FORMAT_INVALID;
11231 return output_format_str[format];
11232}
11233
Daniel Vetterc0b03412013-05-28 12:05:54 +020011234static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011235 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011236 const char *context)
11237{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011238 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011239 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011240 struct drm_plane *plane;
11241 struct intel_plane *intel_plane;
11242 struct intel_plane_state *state;
11243 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011244 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011245
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011246 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11247 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011248
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011249 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11250 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11251 buf, pipe_config->output_types);
11252
Shashank Sharmad9facae2018-10-12 11:53:07 +053011253 DRM_DEBUG_KMS("output format: %s\n",
11254 output_formats(pipe_config->output_format));
11255
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011256 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11257 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011258 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011259
11260 if (pipe_config->has_pch_encoder)
11261 intel_dump_m_n_config(pipe_config, "fdi",
11262 pipe_config->fdi_lanes,
11263 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011264
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011265 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011266 intel_dump_m_n_config(pipe_config, "dp m_n",
11267 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011268 if (pipe_config->has_drrs)
11269 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11270 pipe_config->lane_count,
11271 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011272 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011273
Daniel Vetter55072d12014-11-20 16:10:28 +010011274 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011275 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011276
Daniel Vetterc0b03412013-05-28 12:05:54 +020011277 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011278 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011279 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011280 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11281 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011282 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011283 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011284 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11285 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011286
11287 if (INTEL_GEN(dev_priv) >= 9)
11288 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11289 crtc->num_scalers,
11290 pipe_config->scaler_state.scaler_users,
11291 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011292
11293 if (HAS_GMCH_DISPLAY(dev_priv))
11294 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11295 pipe_config->gmch_pfit.control,
11296 pipe_config->gmch_pfit.pgm_ratios,
11297 pipe_config->gmch_pfit.lvds_border_bits);
11298 else
11299 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11300 pipe_config->pch_pfit.pos,
11301 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011302 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011303
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011304 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11305 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011306
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011307 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011308
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011309 DRM_DEBUG_KMS("planes on this crtc\n");
11310 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011311 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011312 intel_plane = to_intel_plane(plane);
11313 if (intel_plane->pipe != crtc->pipe)
11314 continue;
11315
11316 state = to_intel_plane_state(plane->state);
11317 fb = state->base.fb;
11318 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011319 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11320 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011321 continue;
11322 }
11323
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011324 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11325 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011326 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011327 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011328 if (INTEL_GEN(dev_priv) >= 9)
11329 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11330 state->scaler_id,
11331 state->base.src.x1 >> 16,
11332 state->base.src.y1 >> 16,
11333 drm_rect_width(&state->base.src) >> 16,
11334 drm_rect_height(&state->base.src) >> 16,
11335 state->base.dst.x1, state->base.dst.y1,
11336 drm_rect_width(&state->base.dst),
11337 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011338 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011339}
11340
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011341static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011342{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011343 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011344 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011345 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011346 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011347 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011348 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011349
11350 /*
11351 * Walk the connector list instead of the encoder
11352 * list to detect the problem on ddi platforms
11353 * where there's just one encoder per digital port.
11354 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011355 drm_connector_list_iter_begin(dev, &conn_iter);
11356 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011357 struct drm_connector_state *connector_state;
11358 struct intel_encoder *encoder;
11359
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011360 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011361 if (!connector_state)
11362 connector_state = connector->state;
11363
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011364 if (!connector_state->best_encoder)
11365 continue;
11366
11367 encoder = to_intel_encoder(connector_state->best_encoder);
11368
11369 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011370
11371 switch (encoder->type) {
11372 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011373 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011374 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011375 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011376 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011377 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011378 case INTEL_OUTPUT_HDMI:
11379 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011380 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011381
11382 /* the same port mustn't appear more than once */
11383 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011384 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011385
11386 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011387 break;
11388 case INTEL_OUTPUT_DP_MST:
11389 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011390 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011391 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011392 default:
11393 break;
11394 }
11395 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011396 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011397
Ville Syrjälä477321e2016-07-28 17:50:40 +030011398 /* can't mix MST and SST/HDMI on the same port */
11399 if (used_ports & used_mst_ports)
11400 return false;
11401
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011402 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011403}
11404
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011405static void
11406clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11407{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011408 struct drm_i915_private *dev_priv =
11409 to_i915(crtc_state->base.crtc->dev);
Chandra Konduru663a3642015-04-07 15:28:41 -070011410 struct intel_crtc_scaler_state scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011411 struct intel_dpll_hw_state dpll_hw_state;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011412 struct intel_shared_dpll *shared_dpll;
Ville Syrjäläff32c542017-03-02 19:14:57 +020011413 struct intel_crtc_wm_state wm_state;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011414 bool force_thru, ips_force_disable;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011415
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011416 /* FIXME: before the switch to atomic started, a new pipe_config was
11417 * kzalloc'd. Code that depends on any field being zero should be
11418 * fixed, so that the crtc_state can be safely duplicated. For now,
11419 * only fields that are know to not cause problems are preserved. */
11420
Chandra Konduru663a3642015-04-07 15:28:41 -070011421 scaler_state = crtc_state->scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011422 shared_dpll = crtc_state->shared_dpll;
11423 dpll_hw_state = crtc_state->dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011424 force_thru = crtc_state->pch_pfit.force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011425 ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011426 if (IS_G4X(dev_priv) ||
11427 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011428 wm_state = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011429
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011430 /* Keep base drm_crtc_state intact, only clear our extended struct */
11431 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11432 memset(&crtc_state->base + 1, 0,
11433 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011434
Chandra Konduru663a3642015-04-07 15:28:41 -070011435 crtc_state->scaler_state = scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011436 crtc_state->shared_dpll = shared_dpll;
11437 crtc_state->dpll_hw_state = dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011438 crtc_state->pch_pfit.force_thru = force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011439 crtc_state->ips_force_disable = ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011440 if (IS_G4X(dev_priv) ||
11441 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011442 crtc_state->wm = wm_state;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011443}
11444
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011445static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011446intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011447 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011448{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011449 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011450 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011451 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011452 struct drm_connector_state *connector_state;
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011453 int base_bpp, ret;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011454 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011455 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011456
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011457 clear_intel_crtc_state(pipe_config);
Daniel Vetter7758a112012-07-08 19:40:39 +020011458
Daniel Vettere143a212013-07-04 12:01:15 +020011459 pipe_config->cpu_transcoder =
11460 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011461
Imre Deak2960bc92013-07-30 13:36:32 +030011462 /*
11463 * Sanitize sync polarity flags based on requested ones. If neither
11464 * positive or negative polarity is requested, treat this as meaning
11465 * negative polarity.
11466 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011467 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011468 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011469 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011470
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011471 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011472 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011473 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011474
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011475 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11476 pipe_config);
11477 if (ret)
11478 return ret;
11479
11480 base_bpp = pipe_config->pipe_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011481
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011482 /*
11483 * Determine the real pipe dimensions. Note that stereo modes can
11484 * increase the actual pipe size due to the frame doubling and
11485 * insertion of additional space for blanks between the frame. This
11486 * is stored in the crtc timings. We use the requested mode to do this
11487 * computation to clearly distinguish it from the adjusted mode, which
11488 * can be changed by the connectors in the below retry loop.
11489 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011490 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011491 &pipe_config->pipe_src_w,
11492 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011493
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011494 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011495 if (connector_state->crtc != crtc)
11496 continue;
11497
11498 encoder = to_intel_encoder(connector_state->best_encoder);
11499
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011500 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11501 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011502 return -EINVAL;
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011503 }
11504
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011505 /*
11506 * Determine output_types before calling the .compute_config()
11507 * hooks so that the hooks can use this information safely.
11508 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011509 if (encoder->compute_output_type)
11510 pipe_config->output_types |=
11511 BIT(encoder->compute_output_type(encoder, pipe_config,
11512 connector_state));
11513 else
11514 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011515 }
11516
Daniel Vettere29c22c2013-02-21 00:00:16 +010011517encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011518 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011519 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011520 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011521
Daniel Vetter135c81b2013-07-21 21:37:09 +020011522 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011523 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11524 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011525
Daniel Vetter7758a112012-07-08 19:40:39 +020011526 /* Pass our mode to the connectors and the CRTC to give them a chance to
11527 * adjust it according to limitations or connector properties, and also
11528 * a chance to reject the mode entirely.
11529 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011530 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011531 if (connector_state->crtc != crtc)
11532 continue;
11533
11534 encoder = to_intel_encoder(connector_state->best_encoder);
11535
Maarten Lankhorst0a478c22016-08-09 17:04:05 +020011536 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
Daniel Vetterefea6e82013-07-21 21:36:59 +020011537 DRM_DEBUG_KMS("Encoder config failure\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011538 return -EINVAL;
Daniel Vetter7758a112012-07-08 19:40:39 +020011539 }
11540 }
11541
Daniel Vetterff9a6752013-06-01 17:16:21 +020011542 /* Set default port clock if not overwritten by the encoder. Needs to be
11543 * done afterwards in case the encoder adjusts the mode. */
11544 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011545 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011546 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011547
Daniel Vettera43f6e02013-06-07 23:10:32 +020011548 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020011549 if (ret == -EDEADLK)
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011550 return ret;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011551 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011552 DRM_DEBUG_KMS("CRTC fixup failed\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011553 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011554 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011555
11556 if (ret == RETRY) {
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011557 if (WARN(!retry, "loop in pipe configuration computation\n"))
11558 return -EINVAL;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011559
11560 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11561 retry = false;
11562 goto encoder_retry;
11563 }
11564
Daniel Vettere8fa4272015-08-12 11:43:34 +020011565 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011566 * only enable it on 6bpc panels and when its not a compliance
11567 * test requesting 6bpc video pattern.
11568 */
11569 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11570 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011571 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011572 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011573
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011574 return 0;
Daniel Vetter7758a112012-07-08 19:40:39 +020011575}
11576
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011577static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011578{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011579 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011580
11581 if (clock1 == clock2)
11582 return true;
11583
11584 if (!clock1 || !clock2)
11585 return false;
11586
11587 diff = abs(clock1 - clock2);
11588
11589 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11590 return true;
11591
11592 return false;
11593}
11594
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011595static bool
11596intel_compare_m_n(unsigned int m, unsigned int n,
11597 unsigned int m2, unsigned int n2,
11598 bool exact)
11599{
11600 if (m == m2 && n == n2)
11601 return true;
11602
11603 if (exact || !m || !n || !m2 || !n2)
11604 return false;
11605
11606 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11607
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011608 if (n > n2) {
11609 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011610 m2 <<= 1;
11611 n2 <<= 1;
11612 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011613 } else if (n < n2) {
11614 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011615 m <<= 1;
11616 n <<= 1;
11617 }
11618 }
11619
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011620 if (n != n2)
11621 return false;
11622
11623 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011624}
11625
11626static bool
11627intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11628 struct intel_link_m_n *m2_n2,
11629 bool adjust)
11630{
11631 if (m_n->tu == m2_n2->tu &&
11632 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11633 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11634 intel_compare_m_n(m_n->link_m, m_n->link_n,
11635 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11636 if (adjust)
11637 *m2_n2 = *m_n;
11638
11639 return true;
11640 }
11641
11642 return false;
11643}
11644
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011645static void __printf(3, 4)
11646pipe_config_err(bool adjust, const char *name, const char *format, ...)
11647{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011648 struct va_format vaf;
11649 va_list args;
11650
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011651 va_start(args, format);
11652 vaf.fmt = format;
11653 vaf.va = &args;
11654
Joe Perches99a95482018-03-13 15:02:15 -070011655 if (adjust)
11656 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11657 else
11658 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011659
11660 va_end(args);
11661}
11662
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011663static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011664intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011665 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011666 struct intel_crtc_state *pipe_config,
11667 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011668{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011669 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011670 bool fixup_inherited = adjust &&
11671 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11672 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011673
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011674#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011675 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011676 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011677 "(expected 0x%08x, found 0x%08x)\n", \
11678 current_config->name, \
11679 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011680 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011681 } \
11682} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011683
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011684#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011685 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011686 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011687 "(expected %i, found %i)\n", \
11688 current_config->name, \
11689 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011690 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011691 } \
11692} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011693
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011694#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011695 if (current_config->name != pipe_config->name) { \
11696 pipe_config_err(adjust, __stringify(name), \
11697 "(expected %s, found %s)\n", \
11698 yesno(current_config->name), \
11699 yesno(pipe_config->name)); \
11700 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011701 } \
11702} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011703
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011704/*
11705 * Checks state where we only read out the enabling, but not the entire
11706 * state itself (like full infoframes or ELD for audio). These states
11707 * require a full modeset on bootup to fix up.
11708 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011709#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011710 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11711 PIPE_CONF_CHECK_BOOL(name); \
11712 } else { \
11713 pipe_config_err(adjust, __stringify(name), \
11714 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11715 yesno(current_config->name), \
11716 yesno(pipe_config->name)); \
11717 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011718 } \
11719} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011720
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011721#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011722 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011723 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011724 "(expected %p, found %p)\n", \
11725 current_config->name, \
11726 pipe_config->name); \
11727 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011728 } \
11729} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011730
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011731#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011732 if (!intel_compare_link_m_n(&current_config->name, \
11733 &pipe_config->name,\
11734 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011735 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011736 "(expected tu %i gmch %i/%i link %i/%i, " \
11737 "found tu %i, gmch %i/%i link %i/%i)\n", \
11738 current_config->name.tu, \
11739 current_config->name.gmch_m, \
11740 current_config->name.gmch_n, \
11741 current_config->name.link_m, \
11742 current_config->name.link_n, \
11743 pipe_config->name.tu, \
11744 pipe_config->name.gmch_m, \
11745 pipe_config->name.gmch_n, \
11746 pipe_config->name.link_m, \
11747 pipe_config->name.link_n); \
11748 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011749 } \
11750} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011751
Daniel Vetter55c561a2016-03-30 11:34:36 +020011752/* This is required for BDW+ where there is only one set of registers for
11753 * switching between high and low RR.
11754 * This macro can be used whenever a comparison has to be made between one
11755 * hw state and multiple sw state variables.
11756 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011757#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011758 if (!intel_compare_link_m_n(&current_config->name, \
11759 &pipe_config->name, adjust) && \
11760 !intel_compare_link_m_n(&current_config->alt_name, \
11761 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011762 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011763 "(expected tu %i gmch %i/%i link %i/%i, " \
11764 "or tu %i gmch %i/%i link %i/%i, " \
11765 "found tu %i, gmch %i/%i link %i/%i)\n", \
11766 current_config->name.tu, \
11767 current_config->name.gmch_m, \
11768 current_config->name.gmch_n, \
11769 current_config->name.link_m, \
11770 current_config->name.link_n, \
11771 current_config->alt_name.tu, \
11772 current_config->alt_name.gmch_m, \
11773 current_config->alt_name.gmch_n, \
11774 current_config->alt_name.link_m, \
11775 current_config->alt_name.link_n, \
11776 pipe_config->name.tu, \
11777 pipe_config->name.gmch_m, \
11778 pipe_config->name.gmch_n, \
11779 pipe_config->name.link_m, \
11780 pipe_config->name.link_n); \
11781 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011782 } \
11783} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010011784
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011785#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011786 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011787 pipe_config_err(adjust, __stringify(name), \
11788 "(%x) (expected %i, found %i)\n", \
11789 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011790 current_config->name & (mask), \
11791 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011792 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011793 } \
11794} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011795
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011796#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011797 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011798 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011799 "(expected %i, found %i)\n", \
11800 current_config->name, \
11801 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011802 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011803 } \
11804} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030011805
Daniel Vetterbb760062013-06-06 14:55:52 +020011806#define PIPE_CONF_QUIRK(quirk) \
11807 ((current_config->quirks | pipe_config->quirks) & (quirk))
11808
Daniel Vettereccb1402013-05-22 00:50:22 +020011809 PIPE_CONF_CHECK_I(cpu_transcoder);
11810
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011811 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020011812 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011813 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020011814
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030011815 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030011816 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011817
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011818 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011819 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011820
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011821 if (current_config->has_drrs)
11822 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11823 } else
11824 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030011825
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011826 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020011827
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011828 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11829 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11830 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11831 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11832 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11833 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011834
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011835 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11836 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11837 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11838 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11839 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11840 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011841
Daniel Vetterc93f54c2013-06-27 19:47:19 +020011842 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053011843 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011844 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010011845 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010011846 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011847 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053011848
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011849 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11850 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011851 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020011852
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011853 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020011854
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011855 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011856 DRM_MODE_FLAG_INTERLACE);
11857
Daniel Vetterbb760062013-06-06 14:55:52 +020011858 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011859 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011860 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011861 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011862 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011863 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011864 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011865 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011866 DRM_MODE_FLAG_NVSYNC);
11867 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070011868
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011869 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020011870 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011871 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020011872 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011873 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020011874
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011875 if (!adjust) {
11876 PIPE_CONF_CHECK_I(pipe_src_w);
11877 PIPE_CONF_CHECK_I(pipe_src_h);
11878
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011879 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011880 if (current_config->pch_pfit.enabled) {
11881 PIPE_CONF_CHECK_X(pch_pfit.pos);
11882 PIPE_CONF_CHECK_X(pch_pfit.size);
11883 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020011884
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011885 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011886 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011887 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070011888
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011889 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030011890
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011891 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011892 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020011893 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011894 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11895 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030011896 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010011897 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000011898 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11899 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11900 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030011901 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11902 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11903 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11904 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11905 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11906 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11907 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11908 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11909 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11910 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11911 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11912 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070011913 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11914 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11915 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11916 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11917 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11918 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11919 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11920 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11921 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11922 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020011923
Ville Syrjälä47eacba2016-04-12 22:14:35 +030011924 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11925 PIPE_CONF_CHECK_X(dsi_pll.div);
11926
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011927 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030011928 PIPE_CONF_CHECK_I(pipe_bpp);
11929
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011930 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080011931 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030011932
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030011933 PIPE_CONF_CHECK_I(min_voltage_level);
11934
Daniel Vetter66e985c2013-06-05 13:34:20 +020011935#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020011936#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011937#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011938#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011939#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011940#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030011941#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020011942#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020011943
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011944 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011945}
11946
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011947static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11948 const struct intel_crtc_state *pipe_config)
11949{
11950 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020011951 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011952 &pipe_config->fdi_m_n);
11953 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11954
11955 /*
11956 * FDI already provided one idea for the dotclock.
11957 * Yell if the encoder disagrees.
11958 */
11959 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11960 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11961 fdi_dotclock, dotclock);
11962 }
11963}
11964
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020011965static void verify_wm_state(struct drm_crtc *crtc,
11966 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000011967{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011968 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000011969 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011970 struct skl_pipe_wm hw_wm, *sw_wm;
11971 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11972 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Ville Syrjäläff43bc32018-11-27 18:59:00 +020011973 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
11974 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011975 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11976 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011977 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000011978
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011979 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000011980 return;
11981
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011982 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020011983 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011984
Ville Syrjäläff43bc32018-11-27 18:59:00 +020011985 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
11986
Damien Lespiau08db6652014-11-04 17:06:52 +000011987 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11988 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11989
Mahesh Kumar74bd8002018-04-26 19:55:15 +053011990 if (INTEL_GEN(dev_priv) >= 11)
11991 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11992 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11993 sw_ddb->enabled_slices,
11994 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011995 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070011996 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011997 hw_plane_wm = &hw_wm.planes[plane];
11998 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000011999
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012000 /* Watermarks */
12001 for (level = 0; level <= max_level; level++) {
12002 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12003 &sw_plane_wm->wm[level]))
12004 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000012005
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012006 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",
12007 pipe_name(pipe), plane + 1, level,
12008 sw_plane_wm->wm[level].plane_en,
12009 sw_plane_wm->wm[level].plane_res_b,
12010 sw_plane_wm->wm[level].plane_res_l,
12011 hw_plane_wm->wm[level].plane_en,
12012 hw_plane_wm->wm[level].plane_res_b,
12013 hw_plane_wm->wm[level].plane_res_l);
12014 }
12015
12016 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12017 &sw_plane_wm->trans_wm)) {
12018 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",
12019 pipe_name(pipe), plane + 1,
12020 sw_plane_wm->trans_wm.plane_en,
12021 sw_plane_wm->trans_wm.plane_res_b,
12022 sw_plane_wm->trans_wm.plane_res_l,
12023 hw_plane_wm->trans_wm.plane_en,
12024 hw_plane_wm->trans_wm.plane_res_b,
12025 hw_plane_wm->trans_wm.plane_res_l);
12026 }
12027
12028 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012029 hw_ddb_entry = &hw_ddb_y[plane];
12030 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012031
12032 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012033 DRM_ERROR("mismatch in DDB state pipe %c plane %d (expected (%u,%u), found (%u,%u))\n",
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012034 pipe_name(pipe), plane + 1,
12035 sw_ddb_entry->start, sw_ddb_entry->end,
12036 hw_ddb_entry->start, hw_ddb_entry->end);
12037 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012038 }
12039
Lyude27082492016-08-24 07:48:10 +020012040 /*
12041 * cursor
12042 * If the cursor plane isn't active, we may not have updated it's ddb
12043 * allocation. In that case since the ddb allocation will be updated
12044 * once the plane becomes visible, we can skip this check
12045 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030012046 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012047 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12048 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012049
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012050 /* Watermarks */
12051 for (level = 0; level <= max_level; level++) {
12052 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12053 &sw_plane_wm->wm[level]))
12054 continue;
12055
12056 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",
12057 pipe_name(pipe), level,
12058 sw_plane_wm->wm[level].plane_en,
12059 sw_plane_wm->wm[level].plane_res_b,
12060 sw_plane_wm->wm[level].plane_res_l,
12061 hw_plane_wm->wm[level].plane_en,
12062 hw_plane_wm->wm[level].plane_res_b,
12063 hw_plane_wm->wm[level].plane_res_l);
12064 }
12065
12066 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12067 &sw_plane_wm->trans_wm)) {
12068 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12069 pipe_name(pipe),
12070 sw_plane_wm->trans_wm.plane_en,
12071 sw_plane_wm->trans_wm.plane_res_b,
12072 sw_plane_wm->trans_wm.plane_res_l,
12073 hw_plane_wm->trans_wm.plane_en,
12074 hw_plane_wm->trans_wm.plane_res_b,
12075 hw_plane_wm->trans_wm.plane_res_l);
12076 }
12077
12078 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012079 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12080 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012081
12082 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012083 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020012084 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012085 sw_ddb_entry->start, sw_ddb_entry->end,
12086 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020012087 }
Damien Lespiau08db6652014-11-04 17:06:52 +000012088 }
12089}
12090
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012091static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012092verify_connector_state(struct drm_device *dev,
12093 struct drm_atomic_state *state,
12094 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012095{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012096 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012097 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012098 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012099
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012100 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012101 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012102 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012103
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012104 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012105 continue;
12106
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012107 if (crtc)
12108 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12109
12110 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012111
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012112 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012113 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012114 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012115}
12116
12117static void
Daniel Vetter86b04262017-03-01 10:52:26 +010012118verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012119{
12120 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010012121 struct drm_connector *connector;
12122 struct drm_connector_state *old_conn_state, *new_conn_state;
12123 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012124
Damien Lespiaub2784e12014-08-05 11:29:37 +010012125 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010012126 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012127 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012128
12129 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12130 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030012131 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012132
Daniel Vetter86b04262017-03-01 10:52:26 +010012133 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12134 new_conn_state, i) {
12135 if (old_conn_state->best_encoder == &encoder->base)
12136 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012137
Daniel Vetter86b04262017-03-01 10:52:26 +010012138 if (new_conn_state->best_encoder != &encoder->base)
12139 continue;
12140 found = enabled = true;
12141
12142 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012143 encoder->base.crtc,
12144 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012145 }
Daniel Vetter86b04262017-03-01 10:52:26 +010012146
12147 if (!found)
12148 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100012149
Rob Clarke2c719b2014-12-15 13:56:32 -050012150 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012151 "encoder's enabled state mismatch "
12152 "(expected %i, found %i)\n",
12153 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012154
12155 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012156 bool active;
12157
12158 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012159 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012160 "encoder detached but still enabled on pipe %c.\n",
12161 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012162 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012163 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012164}
12165
12166static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012167verify_crtc_state(struct drm_crtc *crtc,
12168 struct drm_crtc_state *old_crtc_state,
12169 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012170{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012171 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010012172 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012173 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012174 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12175 struct intel_crtc_state *pipe_config, *sw_config;
12176 struct drm_atomic_state *old_state;
12177 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012178
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012179 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012180 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012181 pipe_config = to_intel_crtc_state(old_crtc_state);
12182 memset(pipe_config, 0, sizeof(*pipe_config));
12183 pipe_config->base.crtc = crtc;
12184 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012185
Ville Syrjälä78108b72016-05-27 20:59:19 +030012186 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012187
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012188 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012189
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012190 /* we keep both pipes enabled on 830 */
12191 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012192 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012193
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012194 I915_STATE_WARN(new_crtc_state->active != active,
12195 "crtc active state doesn't match with hw state "
12196 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012197
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012198 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12199 "transitional active state does not match atomic hw state "
12200 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012201
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012202 for_each_encoder_on_crtc(dev, crtc, encoder) {
12203 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012204
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012205 active = encoder->get_hw_state(encoder, &pipe);
12206 I915_STATE_WARN(active != new_crtc_state->active,
12207 "[ENCODER:%i] active %i with crtc active %i\n",
12208 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012209
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012210 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12211 "Encoder connected to wrong pipe %c\n",
12212 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012213
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012214 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012215 encoder->get_config(encoder, pipe_config);
12216 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012217
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012218 intel_crtc_compute_pixel_rate(pipe_config);
12219
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012220 if (!new_crtc_state->active)
12221 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012222
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012223 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012224
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012225 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012226 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012227 pipe_config, false)) {
12228 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12229 intel_dump_pipe_config(intel_crtc, pipe_config,
12230 "[hw state]");
12231 intel_dump_pipe_config(intel_crtc, sw_config,
12232 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012233 }
12234}
12235
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012236static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012237intel_verify_planes(struct intel_atomic_state *state)
12238{
12239 struct intel_plane *plane;
12240 const struct intel_plane_state *plane_state;
12241 int i;
12242
12243 for_each_new_intel_plane_in_state(state, plane,
12244 plane_state, i)
12245 assert_plane(plane, plane_state->base.visible);
12246}
12247
12248static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012249verify_single_dpll_state(struct drm_i915_private *dev_priv,
12250 struct intel_shared_dpll *pll,
12251 struct drm_crtc *crtc,
12252 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012253{
12254 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012255 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012256 bool active;
12257
12258 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12259
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012260 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012261
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012262 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012263
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012264 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012265 I915_STATE_WARN(!pll->on && pll->active_mask,
12266 "pll in active use but not on in sw tracking\n");
12267 I915_STATE_WARN(pll->on && !pll->active_mask,
12268 "pll is on but not used by any active crtc\n");
12269 I915_STATE_WARN(pll->on != active,
12270 "pll on state mismatch (expected %i, found %i)\n",
12271 pll->on, active);
12272 }
12273
12274 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012275 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012276 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012277 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012278
12279 return;
12280 }
12281
Ville Syrjälä40560e22018-06-26 22:47:11 +030012282 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012283
12284 if (new_state->active)
12285 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12286 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12287 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12288 else
12289 I915_STATE_WARN(pll->active_mask & crtc_mask,
12290 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12291 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12292
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012293 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012294 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012295 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012296
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012297 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012298 &dpll_hw_state,
12299 sizeof(dpll_hw_state)),
12300 "pll hw state mismatch\n");
12301}
12302
12303static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012304verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12305 struct drm_crtc_state *old_crtc_state,
12306 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012307{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012308 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012309 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12310 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12311
12312 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012313 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012314
12315 if (old_state->shared_dpll &&
12316 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012317 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012318 struct intel_shared_dpll *pll = old_state->shared_dpll;
12319
12320 I915_STATE_WARN(pll->active_mask & crtc_mask,
12321 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12322 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012323 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012324 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12325 pipe_name(drm_crtc_index(crtc)));
12326 }
12327}
12328
12329static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012330intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012331 struct drm_atomic_state *state,
12332 struct drm_crtc_state *old_state,
12333 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012334{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012335 if (!needs_modeset(new_state) &&
12336 !to_intel_crtc_state(new_state)->update_pipe)
12337 return;
12338
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012339 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012340 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012341 verify_crtc_state(crtc, old_state, new_state);
12342 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012343}
12344
12345static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012346verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012347{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012348 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012349 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012350
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012351 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012352 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012353}
Daniel Vetter53589012013-06-05 13:34:16 +020012354
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012355static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012356intel_modeset_verify_disabled(struct drm_device *dev,
12357 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012358{
Daniel Vetter86b04262017-03-01 10:52:26 +010012359 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012360 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012361 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012362}
12363
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012364static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012365{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012366 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012367 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012368
12369 /*
12370 * The scanline counter increments at the leading edge of hsync.
12371 *
12372 * On most platforms it starts counting from vtotal-1 on the
12373 * first active line. That means the scanline counter value is
12374 * always one less than what we would expect. Ie. just after
12375 * start of vblank, which also occurs at start of hsync (on the
12376 * last active line), the scanline counter will read vblank_start-1.
12377 *
12378 * On gen2 the scanline counter starts counting from 1 instead
12379 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12380 * to keep the value positive), instead of adding one.
12381 *
12382 * On HSW+ the behaviour of the scanline counter depends on the output
12383 * type. For DP ports it behaves like most other platforms, but on HDMI
12384 * there's an extra 1 line difference. So we need to add two instead of
12385 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012386 *
12387 * On VLV/CHV DSI the scanline counter would appear to increment
12388 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12389 * that means we can't tell whether we're in vblank or not while
12390 * we're on that particular line. We must still set scanline_offset
12391 * to 1 so that the vblank timestamps come out correct when we query
12392 * the scanline counter from within the vblank interrupt handler.
12393 * However if queried just before the start of vblank we'll get an
12394 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012395 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080012396 if (IS_GEN(dev_priv, 2)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012397 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012398 int vtotal;
12399
Ville Syrjälä124abe02015-09-08 13:40:45 +030012400 vtotal = adjusted_mode->crtc_vtotal;
12401 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012402 vtotal /= 2;
12403
12404 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012405 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012406 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012407 crtc->scanline_offset = 2;
12408 } else
12409 crtc->scanline_offset = 1;
12410}
12411
Maarten Lankhorstad421372015-06-15 12:33:42 +020012412static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012413{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012414 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012415 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012416 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012417 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012418 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012419
12420 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012421 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012422
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012423 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012424 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012425 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012426 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012427
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012428 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012429 continue;
12430
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012431 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012432
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012433 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012434 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012435
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012436 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012437 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012438}
12439
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012440/*
12441 * This implements the workaround described in the "notes" section of the mode
12442 * set sequence documentation. When going from no pipes or single pipe to
12443 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12444 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12445 */
12446static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12447{
12448 struct drm_crtc_state *crtc_state;
12449 struct intel_crtc *intel_crtc;
12450 struct drm_crtc *crtc;
12451 struct intel_crtc_state *first_crtc_state = NULL;
12452 struct intel_crtc_state *other_crtc_state = NULL;
12453 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12454 int i;
12455
12456 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012457 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012458 intel_crtc = to_intel_crtc(crtc);
12459
12460 if (!crtc_state->active || !needs_modeset(crtc_state))
12461 continue;
12462
12463 if (first_crtc_state) {
12464 other_crtc_state = to_intel_crtc_state(crtc_state);
12465 break;
12466 } else {
12467 first_crtc_state = to_intel_crtc_state(crtc_state);
12468 first_pipe = intel_crtc->pipe;
12469 }
12470 }
12471
12472 /* No workaround needed? */
12473 if (!first_crtc_state)
12474 return 0;
12475
12476 /* w/a possibly needed, check how many crtc's are already enabled. */
12477 for_each_intel_crtc(state->dev, intel_crtc) {
12478 struct intel_crtc_state *pipe_config;
12479
12480 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12481 if (IS_ERR(pipe_config))
12482 return PTR_ERR(pipe_config);
12483
12484 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12485
12486 if (!pipe_config->base.active ||
12487 needs_modeset(&pipe_config->base))
12488 continue;
12489
12490 /* 2 or more enabled crtcs means no need for w/a */
12491 if (enabled_pipe != INVALID_PIPE)
12492 return 0;
12493
12494 enabled_pipe = intel_crtc->pipe;
12495 }
12496
12497 if (enabled_pipe != INVALID_PIPE)
12498 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12499 else if (other_crtc_state)
12500 other_crtc_state->hsw_workaround_pipe = first_pipe;
12501
12502 return 0;
12503}
12504
Ville Syrjälä8d965612016-11-14 18:35:10 +020012505static int intel_lock_all_pipes(struct drm_atomic_state *state)
12506{
12507 struct drm_crtc *crtc;
12508
12509 /* Add all pipes to the state */
12510 for_each_crtc(state->dev, crtc) {
12511 struct drm_crtc_state *crtc_state;
12512
12513 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12514 if (IS_ERR(crtc_state))
12515 return PTR_ERR(crtc_state);
12516 }
12517
12518 return 0;
12519}
12520
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012521static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12522{
12523 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012524
Ville Syrjälä8d965612016-11-14 18:35:10 +020012525 /*
12526 * Add all pipes to the state, and force
12527 * a modeset on all the active ones.
12528 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012529 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012530 struct drm_crtc_state *crtc_state;
12531 int ret;
12532
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012533 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12534 if (IS_ERR(crtc_state))
12535 return PTR_ERR(crtc_state);
12536
12537 if (!crtc_state->active || needs_modeset(crtc_state))
12538 continue;
12539
12540 crtc_state->mode_changed = true;
12541
12542 ret = drm_atomic_add_affected_connectors(state, crtc);
12543 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012544 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012545
12546 ret = drm_atomic_add_affected_planes(state, crtc);
12547 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012548 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012549 }
12550
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012551 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012552}
12553
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012554static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012555{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012556 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012557 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012558 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012559 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012560 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012561
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012562 if (!check_digital_port_conflicts(state)) {
12563 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12564 return -EINVAL;
12565 }
12566
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012567 intel_state->modeset = true;
12568 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012569 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12570 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012571
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012572 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12573 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012574 intel_state->active_crtcs |= 1 << i;
12575 else
12576 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012577
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012578 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012579 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012580 }
12581
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012582 /*
12583 * See if the config requires any additional preparation, e.g.
12584 * to adjust global state with pipes off. We need to do this
12585 * here so we can get the modeset_pipe updated config for the new
12586 * mode set on this crtc. For other crtcs we need to use the
12587 * adjusted_mode bits in the crtc directly.
12588 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012589 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012590 ret = dev_priv->display.modeset_calc_cdclk(state);
12591 if (ret < 0)
12592 return ret;
12593
Ville Syrjälä8d965612016-11-14 18:35:10 +020012594 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012595 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012596 * holding all the crtc locks, even if we don't end up
12597 * touching the hardware
12598 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012599 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12600 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012601 ret = intel_lock_all_pipes(state);
12602 if (ret < 0)
12603 return ret;
12604 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012605
Ville Syrjälä8d965612016-11-14 18:35:10 +020012606 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012607 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12608 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012609 ret = intel_modeset_all_pipes(state);
12610 if (ret < 0)
12611 return ret;
12612 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012613
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012614 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12615 intel_state->cdclk.logical.cdclk,
12616 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012617 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12618 intel_state->cdclk.logical.voltage_level,
12619 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012620 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012621 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012622 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012623
Maarten Lankhorstad421372015-06-15 12:33:42 +020012624 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012625
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012626 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012627 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012628
Maarten Lankhorstad421372015-06-15 12:33:42 +020012629 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012630}
12631
Matt Roperaa363132015-09-24 15:53:18 -070012632/*
12633 * Handle calculation of various watermark data at the end of the atomic check
12634 * phase. The code here should be run after the per-crtc and per-plane 'check'
12635 * handlers to ensure that all derived state has been updated.
12636 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012637static int calc_watermark_data(struct intel_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012638{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012639 struct drm_device *dev = state->base.dev;
Matt Roper98d39492016-05-12 07:06:03 -070012640 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012641
12642 /* Is there platform-specific watermark information to calculate? */
12643 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012644 return dev_priv->display.compute_global_watermarks(state);
12645
12646 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012647}
12648
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012649/**
12650 * intel_atomic_check - validate state object
12651 * @dev: drm device
12652 * @state: state to validate
12653 */
12654static int intel_atomic_check(struct drm_device *dev,
12655 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012656{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012657 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012658 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012659 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012660 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012661 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012662 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012663
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012664 /* Catch I915_MODE_FLAG_INHERITED */
12665 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12666 crtc_state, i) {
12667 if (crtc_state->mode.private_flags !=
12668 old_crtc_state->mode.private_flags)
12669 crtc_state->mode_changed = true;
12670 }
12671
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012672 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012673 if (ret)
12674 return ret;
12675
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012676 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012677 struct intel_crtc_state *pipe_config =
12678 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012679
Daniel Vetter26495482015-07-15 14:15:52 +020012680 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012681 continue;
12682
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012683 if (!crtc_state->enable) {
12684 any_ms = true;
12685 continue;
12686 }
12687
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012688 ret = intel_modeset_pipe_config(crtc, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020012689 if (ret == -EDEADLK)
12690 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012691 if (ret) {
12692 intel_dump_pipe_config(to_intel_crtc(crtc),
12693 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012694 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012695 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012696
Michal Wajdeczko4f044a82017-09-19 19:38:44 +000012697 if (i915_modparams.fastboot &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012698 intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012699 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012700 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012701 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012702 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012703 }
12704
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012705 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012706 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012707
Daniel Vetter26495482015-07-15 14:15:52 +020012708 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12709 needs_modeset(crtc_state) ?
12710 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012711 }
12712
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012713 if (any_ms) {
12714 ret = intel_modeset_checks(state);
12715
12716 if (ret)
12717 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012718 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012719 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012720 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012721
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012722 ret = icl_add_linked_planes(intel_state);
12723 if (ret)
12724 return ret;
12725
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012726 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012727 if (ret)
12728 return ret;
12729
Ville Syrjälädd576022017-11-17 21:19:14 +020012730 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012731 return calc_watermark_data(intel_state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012732}
12733
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012734static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012735 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012736{
Chris Wilsonfd700752017-07-26 17:00:36 +010012737 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012738}
12739
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012740u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12741{
12742 struct drm_device *dev = crtc->base.dev;
12743
12744 if (!dev->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080012745 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012746
12747 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12748}
12749
Lyude896e5bb2016-08-24 07:48:09 +020012750static void intel_update_crtc(struct drm_crtc *crtc,
12751 struct drm_atomic_state *state,
12752 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012753 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020012754{
12755 struct drm_device *dev = crtc->dev;
12756 struct drm_i915_private *dev_priv = to_i915(dev);
12757 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012758 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12759 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012760 struct intel_plane_state *new_plane_state =
12761 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12762 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020012763
12764 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012765 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012766 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012767
12768 /* vblanks work again, re-enable pipe CRC. */
12769 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020012770 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012771 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12772 pipe_config);
Hans de Goede608ed4a2018-12-20 14:21:18 +010012773
12774 if (pipe_config->update_pipe)
12775 intel_encoders_update_pipe(crtc, pipe_config, state);
Lyude896e5bb2016-08-24 07:48:09 +020012776 }
12777
Maarten Lankhorst50c42fc2018-12-20 16:17:19 +010012778 if (pipe_config->update_pipe && !pipe_config->enable_fbc)
12779 intel_fbc_disable(intel_crtc);
12780 else if (new_plane_state)
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012781 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020012782
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012783 intel_begin_crtc_commit(crtc, old_crtc_state);
12784
Ville Syrjälä5f2e5112018-11-14 23:07:27 +020012785 if (INTEL_GEN(dev_priv) >= 9)
12786 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
12787 else
12788 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012789
12790 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012791}
12792
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012793static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020012794{
12795 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012796 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020012797 int i;
12798
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012799 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12800 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020012801 continue;
12802
12803 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012804 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012805 }
12806}
12807
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012808static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020012809{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012810 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020012811 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12812 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040012813 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012814 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040012815 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020012816 unsigned int updated = 0;
12817 bool progress;
12818 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012819 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012820 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12821 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012822 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012823
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012824 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012825 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012826 if (new_crtc_state->active)
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012827 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012828
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012829 /* If 2nd DBuf slice required, enable it here */
12830 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12831 icl_dbuf_slices_update(dev_priv, required_slices);
12832
Lyude27082492016-08-24 07:48:10 +020012833 /*
12834 * Whenever the number of active pipes changes, we need to make sure we
12835 * update the pipes in the right order so that their ddb allocations
12836 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12837 * cause pipe underruns and other bad stuff.
12838 */
12839 do {
Lyude27082492016-08-24 07:48:10 +020012840 progress = false;
12841
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012842 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020012843 bool vbl_wait = false;
12844 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040012845
12846 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030012847 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040012848 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020012849
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012850 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020012851 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012852
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012853 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
Mika Kahola2b685042017-10-10 13:17:03 +030012854 entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012855 INTEL_INFO(dev_priv)->num_pipes, i))
Lyude27082492016-08-24 07:48:10 +020012856 continue;
12857
12858 updated |= cmask;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012859 entries[i] = cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012860
12861 /*
12862 * If this is an already active pipe, it's DDB changed,
12863 * and this isn't the last pipe that needs updating
12864 * then we need to wait for a vblank to pass for the
12865 * new ddb allocation to take effect.
12866 */
Lyudece0ba282016-09-15 10:46:35 -040012867 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010012868 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012869 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020012870 intel_state->wm_results.dirty_pipes != updated)
12871 vbl_wait = true;
12872
12873 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012874 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020012875
12876 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012877 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020012878
12879 progress = true;
12880 }
12881 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012882
12883 /* If 2nd DBuf slice is no more required disable it */
12884 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12885 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020012886}
12887
Chris Wilsonba318c62017-02-02 20:47:41 +000012888static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12889{
12890 struct intel_atomic_state *state, *next;
12891 struct llist_node *freed;
12892
12893 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12894 llist_for_each_entry_safe(state, next, freed, freed)
12895 drm_atomic_state_put(&state->base);
12896}
12897
12898static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12899{
12900 struct drm_i915_private *dev_priv =
12901 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12902
12903 intel_atomic_helper_free_state(dev_priv);
12904}
12905
Daniel Vetter9db529a2017-08-08 10:08:28 +020012906static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12907{
12908 struct wait_queue_entry wait_fence, wait_reset;
12909 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12910
12911 init_wait_entry(&wait_fence, 0);
12912 init_wait_entry(&wait_reset, 0);
12913 for (;;) {
12914 prepare_to_wait(&intel_state->commit_ready.wait,
12915 &wait_fence, TASK_UNINTERRUPTIBLE);
12916 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12917 &wait_reset, TASK_UNINTERRUPTIBLE);
12918
12919
12920 if (i915_sw_fence_done(&intel_state->commit_ready)
12921 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12922 break;
12923
12924 schedule();
12925 }
12926 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12927 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12928}
12929
Chris Wilson8d52e442018-06-23 11:39:51 +010012930static void intel_atomic_cleanup_work(struct work_struct *work)
12931{
12932 struct drm_atomic_state *state =
12933 container_of(work, struct drm_atomic_state, commit_work);
12934 struct drm_i915_private *i915 = to_i915(state->dev);
12935
12936 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12937 drm_atomic_helper_commit_cleanup_done(state);
12938 drm_atomic_state_put(state);
12939
12940 intel_atomic_helper_free_state(i915);
12941}
12942
Daniel Vetter94f05022016-06-14 18:01:00 +020012943static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012944{
Daniel Vetter94f05022016-06-14 18:01:00 +020012945 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012946 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012947 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012948 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012949 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020012950 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012951 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020012952 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilsone95433c2016-10-28 13:58:27 +010012953 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020012954
Daniel Vetter9db529a2017-08-08 10:08:28 +020012955 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020012956
Daniel Vetterea0000f2016-06-13 16:13:46 +020012957 drm_atomic_helper_wait_for_dependencies(state);
12958
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010012959 if (intel_state->modeset)
Daniel Vetter5a21b662016-05-24 17:13:53 +020012960 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012961
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012962 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012963 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12964 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12965 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012966
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012967 if (needs_modeset(new_crtc_state) ||
12968 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012969
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012970 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020012971 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012972 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012973 }
12974
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012975 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012976 continue;
12977
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012978 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010012979
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020012980 if (old_crtc_state->active) {
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020012981 intel_crtc_disable_planes(intel_state, intel_crtc);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012982
12983 /*
12984 * We need to disable pipe CRC before disabling the pipe,
12985 * or we race against vblank off.
12986 */
12987 intel_crtc_disable_pipe_crc(intel_crtc);
12988
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020012989 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020012990 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020012991 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020012992 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020012993
12994 /*
12995 * Underruns don't always raise
12996 * interrupts, so check manually.
12997 */
12998 intel_check_cpu_fifo_underruns(dev_priv);
12999 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010013000
Ville Syrjäläa748fae2018-10-25 16:05:36 +030013001 /* FIXME unify this for all platforms */
13002 if (!new_crtc_state->active &&
13003 !HAS_GMCH_DISPLAY(dev_priv) &&
13004 dev_priv->display.initial_watermarks)
13005 dev_priv->display.initial_watermarks(intel_state,
13006 new_intel_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013007 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010013008 }
Daniel Vetter7758a112012-07-08 19:40:39 +020013009
Daniel Vetter7a1530d72017-12-07 15:32:02 +010013010 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
13011 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
13012 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020013013
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013014 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013015 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010013016
Ville Syrjäläb0587e42017-01-26 21:52:01 +020013017 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010013018
Lyude656d1b82016-08-17 15:55:54 -040013019 /*
13020 * SKL workaround: bspec recommends we disable the SAGV when we
13021 * have more then one pipe enabled
13022 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030013023 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013024 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013025
Maarten Lankhorst677100c2016-11-08 13:55:41 +010013026 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013027 }
Daniel Vetter47fab732012-10-26 10:58:18 +020013028
Lyude896e5bb2016-08-24 07:48:09 +020013029 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013030 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13031 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013032
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013033 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013034 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013035 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013036 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013037 spin_unlock_irq(&dev->event_lock);
13038
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013039 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013040 }
Matt Ropered4a6a72016-02-23 17:20:13 -080013041 }
13042
Lyude896e5bb2016-08-24 07:48:09 +020013043 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013044 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020013045
Daniel Vetter94f05022016-06-14 18:01:00 +020013046 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13047 * already, but still need the state for the delayed optimization. To
13048 * fix this:
13049 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13050 * - schedule that vblank worker _before_ calling hw_done
13051 * - at the start of commit_tail, cancel it _synchrously
13052 * - switch over to the vblank wait helper in the core after that since
13053 * we don't need out special handling any more.
13054 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013055 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013056
13057 /*
13058 * Now that the vblank has passed, we can go ahead and program the
13059 * optimal watermarks on platforms that need two-step watermark
13060 * programming.
13061 *
13062 * TODO: Move this (and other cleanup) to an async worker eventually.
13063 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013064 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013065 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013066
13067 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013068 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013069 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013070 }
13071
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013072 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013073 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13074
13075 if (put_domains[i])
13076 modeset_put_power_domains(dev_priv, put_domains[i]);
13077
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013078 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013079 }
13080
Ville Syrjäläcff109f2017-11-17 21:19:17 +020013081 if (intel_state->modeset)
13082 intel_verify_planes(intel_state);
13083
Paulo Zanoni56feca92016-09-22 18:00:28 -030013084 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013085 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013086
Daniel Vetter94f05022016-06-14 18:01:00 +020013087 drm_atomic_helper_commit_hw_done(state);
13088
Chris Wilsond5553c02017-05-04 12:55:08 +010013089 if (intel_state->modeset) {
13090 /* As one of the primary mmio accessors, KMS has a high
13091 * likelihood of triggering bugs in unclaimed access. After we
13092 * finish modesetting, see if an error has been flagged, and if
13093 * so enable debugging for the next modeset - and hope we catch
13094 * the culprit.
13095 */
13096 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013097 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
Chris Wilsond5553c02017-05-04 12:55:08 +010013098 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013099
Chris Wilson8d52e442018-06-23 11:39:51 +010013100 /*
13101 * Defer the cleanup of the old state to a separate worker to not
13102 * impede the current task (userspace for blocking modesets) that
13103 * are executed inline. For out-of-line asynchronous modesets/flips,
13104 * deferring to a new worker seems overkill, but we would place a
13105 * schedule point (cond_resched()) here anyway to keep latencies
13106 * down.
13107 */
13108 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010013109 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020013110}
13111
13112static void intel_atomic_commit_work(struct work_struct *work)
13113{
Chris Wilsonc004a902016-10-28 13:58:45 +010013114 struct drm_atomic_state *state =
13115 container_of(work, struct drm_atomic_state, commit_work);
13116
Daniel Vetter94f05022016-06-14 18:01:00 +020013117 intel_atomic_commit_tail(state);
13118}
13119
Chris Wilsonc004a902016-10-28 13:58:45 +010013120static int __i915_sw_fence_call
13121intel_atomic_commit_ready(struct i915_sw_fence *fence,
13122 enum i915_sw_fence_notify notify)
13123{
13124 struct intel_atomic_state *state =
13125 container_of(fence, struct intel_atomic_state, commit_ready);
13126
13127 switch (notify) {
13128 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020013129 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010013130 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010013131 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000013132 {
13133 struct intel_atomic_helper *helper =
13134 &to_i915(state->base.dev)->atomic_helper;
13135
13136 if (llist_add(&state->freed, &helper->free_list))
13137 schedule_work(&helper->free_work);
13138 break;
13139 }
Chris Wilsonc004a902016-10-28 13:58:45 +010013140 }
13141
13142 return NOTIFY_DONE;
13143}
13144
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013145static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13146{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013147 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013148 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013149 int i;
13150
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013151 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013152 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013153 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013154 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013155}
13156
Daniel Vetter94f05022016-06-14 18:01:00 +020013157/**
13158 * intel_atomic_commit - commit validated state object
13159 * @dev: DRM device
13160 * @state: the top-level driver state object
13161 * @nonblock: nonblocking commit
13162 *
13163 * This function commits a top-level state object that has been validated
13164 * with drm_atomic_helper_check().
13165 *
Daniel Vetter94f05022016-06-14 18:01:00 +020013166 * RETURNS
13167 * Zero for success or -errno.
13168 */
13169static int intel_atomic_commit(struct drm_device *dev,
13170 struct drm_atomic_state *state,
13171 bool nonblock)
13172{
13173 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013174 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013175 int ret = 0;
13176
Chris Wilsonc004a902016-10-28 13:58:45 +010013177 drm_atomic_state_get(state);
13178 i915_sw_fence_init(&intel_state->commit_ready,
13179 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013180
Ville Syrjälä440df932017-03-29 17:21:23 +030013181 /*
13182 * The intel_legacy_cursor_update() fast path takes care
13183 * of avoiding the vblank waits for simple cursor
13184 * movement and flips. For cursor on/off and size changes,
13185 * we want to perform the vblank waits so that watermark
13186 * updates happen during the correct frames. Gen9+ have
13187 * double buffered watermarks and so shouldn't need this.
13188 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013189 * Unset state->legacy_cursor_update before the call to
13190 * drm_atomic_helper_setup_commit() because otherwise
13191 * drm_atomic_helper_wait_for_flip_done() is a noop and
13192 * we get FIFO underruns because we didn't wait
13193 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013194 *
13195 * FIXME doing watermarks and fb cleanup from a vblank worker
13196 * (assuming we had any) would solve these problems.
13197 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013198 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13199 struct intel_crtc_state *new_crtc_state;
13200 struct intel_crtc *crtc;
13201 int i;
13202
13203 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13204 if (new_crtc_state->wm.need_postvbl_update ||
13205 new_crtc_state->update_wm_post)
13206 state->legacy_cursor_update = false;
13207 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013208
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013209 ret = intel_atomic_prepare_commit(dev, state);
13210 if (ret) {
13211 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13212 i915_sw_fence_commit(&intel_state->commit_ready);
13213 return ret;
13214 }
13215
13216 ret = drm_atomic_helper_setup_commit(state, nonblock);
13217 if (!ret)
13218 ret = drm_atomic_helper_swap_state(state, true);
13219
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013220 if (ret) {
13221 i915_sw_fence_commit(&intel_state->commit_ready);
13222
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013223 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013224 return ret;
13225 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013226 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013227 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013228 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013229
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013230 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013231 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13232 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013233 memcpy(dev_priv->min_voltage_level,
13234 intel_state->min_voltage_level,
13235 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013236 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013237 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13238 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013239 }
13240
Chris Wilson08536952016-10-14 13:18:18 +010013241 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013242 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013243
13244 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013245 if (nonblock && intel_state->modeset) {
13246 queue_work(dev_priv->modeset_wq, &state->commit_work);
13247 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013248 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013249 } else {
13250 if (intel_state->modeset)
13251 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013252 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013253 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013254
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013255 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013256}
13257
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013258static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013259 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013260 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013261 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013262 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013263 .atomic_duplicate_state = intel_crtc_duplicate_state,
13264 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013265 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013266 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013267 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013268};
13269
Chris Wilson74d290f2017-08-17 13:37:06 +010013270struct wait_rps_boost {
13271 struct wait_queue_entry wait;
13272
13273 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013274 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013275};
13276
13277static int do_rps_boost(struct wait_queue_entry *_wait,
13278 unsigned mode, int sync, void *key)
13279{
13280 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013281 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013282
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013283 /*
13284 * If we missed the vblank, but the request is already running it
13285 * is reasonable to assume that it will complete before the next
13286 * vblank without our intervention, so leave RPS alone.
13287 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013288 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013289 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013290 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013291
13292 drm_crtc_vblank_put(wait->crtc);
13293
13294 list_del(&wait->wait.entry);
13295 kfree(wait);
13296 return 1;
13297}
13298
13299static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13300 struct dma_fence *fence)
13301{
13302 struct wait_rps_boost *wait;
13303
13304 if (!dma_fence_is_i915(fence))
13305 return;
13306
13307 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13308 return;
13309
13310 if (drm_crtc_vblank_get(crtc))
13311 return;
13312
13313 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13314 if (!wait) {
13315 drm_crtc_vblank_put(crtc);
13316 return;
13317 }
13318
13319 wait->request = to_request(dma_fence_get(fence));
13320 wait->crtc = crtc;
13321
13322 wait->wait.func = do_rps_boost;
13323 wait->wait.flags = 0;
13324
13325 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13326}
13327
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013328static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13329{
13330 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13331 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13332 struct drm_framebuffer *fb = plane_state->base.fb;
13333 struct i915_vma *vma;
13334
13335 if (plane->id == PLANE_CURSOR &&
José Roberto de Souzad53db442018-11-30 15:20:48 -080013336 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013337 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13338 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013339 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013340
Chris Wilson4a477652018-08-17 09:24:05 +010013341 err = i915_gem_object_attach_phys(obj, align);
13342 if (err)
13343 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013344 }
13345
13346 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013347 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013348 intel_plane_uses_fence(plane_state),
13349 &plane_state->flags);
13350 if (IS_ERR(vma))
13351 return PTR_ERR(vma);
13352
13353 plane_state->vma = vma;
13354
13355 return 0;
13356}
13357
13358static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13359{
13360 struct i915_vma *vma;
13361
13362 vma = fetch_and_zero(&old_plane_state->vma);
13363 if (vma)
13364 intel_unpin_fb_vma(vma, old_plane_state->flags);
13365}
13366
Chris Wilsonb7268c52018-04-18 19:40:52 +010013367static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13368{
13369 struct i915_sched_attr attr = {
13370 .priority = I915_PRIORITY_DISPLAY,
13371 };
13372
13373 i915_gem_object_wait_priority(obj, 0, &attr);
13374}
13375
Matt Roper6beb8c232014-12-01 15:40:14 -080013376/**
13377 * intel_prepare_plane_fb - Prepare fb for usage on plane
13378 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013379 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013380 *
13381 * Prepares a framebuffer for usage on a display plane. Generally this
13382 * involves pinning the underlying object and updating the frontbuffer tracking
13383 * bits. Some older platforms need special physical address handling for
13384 * cursor planes.
13385 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013386 * Must be called with struct_mutex held.
13387 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013388 * Returns 0 on success, negative error code on failure.
13389 */
13390int
13391intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013392 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013393{
Chris Wilsonc004a902016-10-28 13:58:45 +010013394 struct intel_atomic_state *intel_state =
13395 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013396 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013397 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013398 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013399 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013400 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013401
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013402 if (old_obj) {
13403 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013404 drm_atomic_get_new_crtc_state(new_state->state,
13405 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013406
13407 /* Big Hammer, we also need to ensure that any pending
13408 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13409 * current scanout is retired before unpinning the old
13410 * framebuffer. Note that we rely on userspace rendering
13411 * into the buffer attached to the pipe they are waiting
13412 * on. If not, userspace generates a GPU hang with IPEHR
13413 * point to the MI_WAIT_FOR_EVENT.
13414 *
13415 * This should only fail upon a hung GPU, in which case we
13416 * can safely continue.
13417 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013418 if (needs_modeset(crtc_state)) {
13419 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13420 old_obj->resv, NULL,
13421 false, 0,
13422 GFP_KERNEL);
13423 if (ret < 0)
13424 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013425 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013426 }
13427
Chris Wilsonc004a902016-10-28 13:58:45 +010013428 if (new_state->fence) { /* explicit fencing */
13429 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13430 new_state->fence,
13431 I915_FENCE_TIMEOUT,
13432 GFP_KERNEL);
13433 if (ret < 0)
13434 return ret;
13435 }
13436
Chris Wilsonc37efb92016-06-17 08:28:47 +010013437 if (!obj)
13438 return 0;
13439
Chris Wilson4d3088c2017-07-26 17:00:38 +010013440 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013441 if (ret)
13442 return ret;
13443
Chris Wilson4d3088c2017-07-26 17:00:38 +010013444 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13445 if (ret) {
13446 i915_gem_object_unpin_pages(obj);
13447 return ret;
13448 }
13449
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013450 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013451
Chris Wilsonfd700752017-07-26 17:00:36 +010013452 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013453 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013454 if (ret)
13455 return ret;
13456
Chris Wilsone2f34962018-10-01 15:47:54 +010013457 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013458 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13459
Chris Wilsonc004a902016-10-28 13:58:45 +010013460 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013461 struct dma_fence *fence;
13462
Chris Wilsonc004a902016-10-28 13:58:45 +010013463 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13464 obj->resv, NULL,
13465 false, I915_FENCE_TIMEOUT,
13466 GFP_KERNEL);
13467 if (ret < 0)
13468 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013469
13470 fence = reservation_object_get_excl_rcu(obj->resv);
13471 if (fence) {
13472 add_rps_boost_after_vblank(new_state->crtc, fence);
13473 dma_fence_put(fence);
13474 }
13475 } else {
13476 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013477 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013478
Chris Wilson60548c52018-07-31 14:26:29 +010013479 /*
13480 * We declare pageflips to be interactive and so merit a small bias
13481 * towards upclocking to deliver the frame on time. By only changing
13482 * the RPS thresholds to sample more regularly and aim for higher
13483 * clocks we can hopefully deliver low power workloads (like kodi)
13484 * that are not quite steady state without resorting to forcing
13485 * maximum clocks following a vblank miss (see do_rps_boost()).
13486 */
13487 if (!intel_state->rps_interactive) {
13488 intel_rps_mark_interactive(dev_priv, true);
13489 intel_state->rps_interactive = true;
13490 }
13491
Chris Wilsond07f0e52016-10-28 13:58:44 +010013492 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013493}
13494
Matt Roper38f3ce32014-12-02 07:45:25 -080013495/**
13496 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13497 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013498 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013499 *
13500 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013501 *
13502 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013503 */
13504void
13505intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013506 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013507{
Chris Wilson60548c52018-07-31 14:26:29 +010013508 struct intel_atomic_state *intel_state =
13509 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013510 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013511
Chris Wilson60548c52018-07-31 14:26:29 +010013512 if (intel_state->rps_interactive) {
13513 intel_rps_mark_interactive(dev_priv, false);
13514 intel_state->rps_interactive = false;
13515 }
13516
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013517 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013518 mutex_lock(&dev_priv->drm.struct_mutex);
13519 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13520 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013521}
13522
Chandra Konduru6156a452015-04-27 13:48:39 -070013523int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013524skl_max_scale(const struct intel_crtc_state *crtc_state,
13525 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013526{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013527 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13528 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013529 int max_scale, mult;
13530 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013531
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013532 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013533 return DRM_PLANE_HELPER_NO_SCALING;
13534
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013535 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13536 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13537
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013538 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013539 max_dotclk *= 2;
13540
13541 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013542 return DRM_PLANE_HELPER_NO_SCALING;
13543
13544 /*
13545 * skl max scale is lower of:
13546 * close to 3 but not 3, -1 is for that purpose
13547 * or
13548 * cdclk/crtc_clock
13549 */
Chandra Konduru77224cd2018-04-09 09:11:13 +053013550 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13551 tmpclk1 = (1 << 16) * mult - 1;
13552 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13553 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013554
13555 return max_scale;
13556}
13557
Daniel Vetter5a21b662016-05-24 17:13:53 +020013558static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13559 struct drm_crtc_state *old_crtc_state)
13560{
13561 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013562 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013563 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013564 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013565 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013566 struct intel_atomic_state *old_intel_state =
13567 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013568 struct intel_crtc_state *intel_cstate =
13569 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13570 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013571
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013572 if (!modeset &&
13573 (intel_cstate->base.color_mgmt_changed ||
13574 intel_cstate->update_pipe)) {
Matt Roper302da0c2018-12-10 13:54:15 -080013575 intel_color_set_csc(intel_cstate);
13576 intel_color_load_luts(intel_cstate);
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013577 }
13578
Daniel Vetter5a21b662016-05-24 17:13:53 +020013579 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013580 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013581
13582 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013583 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013584
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013585 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013586 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013587 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013588 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013589
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013590out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013591 if (dev_priv->display.atomic_update_watermarks)
13592 dev_priv->display.atomic_update_watermarks(old_intel_state,
13593 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013594}
13595
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013596void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13597 struct intel_crtc_state *crtc_state)
13598{
13599 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13600
Lucas De Marchicf819ef2018-12-12 10:10:43 -080013601 if (!IS_GEN(dev_priv, 2))
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013602 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13603
13604 if (crtc_state->has_pch_encoder) {
13605 enum pipe pch_transcoder =
13606 intel_crtc_pch_transcoder(crtc);
13607
13608 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13609 }
13610}
13611
Daniel Vetter5a21b662016-05-24 17:13:53 +020013612static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13613 struct drm_crtc_state *old_crtc_state)
13614{
13615 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013616 struct intel_atomic_state *old_intel_state =
13617 to_intel_atomic_state(old_crtc_state->state);
13618 struct intel_crtc_state *new_crtc_state =
13619 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013620
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013621 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013622
13623 if (new_crtc_state->update_pipe &&
13624 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013625 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13626 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013627}
13628
Matt Ropercf4c7c12014-12-04 10:27:42 -080013629/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013630 * intel_plane_destroy - destroy a plane
13631 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013632 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013633 * Common destruction function for all types of planes (primary, cursor,
13634 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013635 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013636void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013637{
Matt Roper465c1202014-05-29 08:06:54 -070013638 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013639 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013640}
13641
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013642static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13643 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013644{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013645 switch (modifier) {
13646 case DRM_FORMAT_MOD_LINEAR:
13647 case I915_FORMAT_MOD_X_TILED:
13648 break;
13649 default:
13650 return false;
13651 }
13652
Ben Widawsky714244e2017-08-01 09:58:16 -070013653 switch (format) {
13654 case DRM_FORMAT_C8:
13655 case DRM_FORMAT_RGB565:
13656 case DRM_FORMAT_XRGB1555:
13657 case DRM_FORMAT_XRGB8888:
13658 return modifier == DRM_FORMAT_MOD_LINEAR ||
13659 modifier == I915_FORMAT_MOD_X_TILED;
13660 default:
13661 return false;
13662 }
13663}
13664
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013665static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13666 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013667{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013668 switch (modifier) {
13669 case DRM_FORMAT_MOD_LINEAR:
13670 case I915_FORMAT_MOD_X_TILED:
13671 break;
13672 default:
13673 return false;
13674 }
13675
Ben Widawsky714244e2017-08-01 09:58:16 -070013676 switch (format) {
13677 case DRM_FORMAT_C8:
13678 case DRM_FORMAT_RGB565:
13679 case DRM_FORMAT_XRGB8888:
13680 case DRM_FORMAT_XBGR8888:
13681 case DRM_FORMAT_XRGB2101010:
13682 case DRM_FORMAT_XBGR2101010:
13683 return modifier == DRM_FORMAT_MOD_LINEAR ||
13684 modifier == I915_FORMAT_MOD_X_TILED;
13685 default:
13686 return false;
13687 }
13688}
13689
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013690static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13691 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013692{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013693 return modifier == DRM_FORMAT_MOD_LINEAR &&
13694 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013695}
13696
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013697static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013698 .update_plane = drm_atomic_helper_update_plane,
13699 .disable_plane = drm_atomic_helper_disable_plane,
13700 .destroy = intel_plane_destroy,
13701 .atomic_get_property = intel_plane_atomic_get_property,
13702 .atomic_set_property = intel_plane_atomic_set_property,
13703 .atomic_duplicate_state = intel_plane_duplicate_state,
13704 .atomic_destroy_state = intel_plane_destroy_state,
13705 .format_mod_supported = i965_plane_format_mod_supported,
13706};
13707
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013708static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013709 .update_plane = drm_atomic_helper_update_plane,
13710 .disable_plane = drm_atomic_helper_disable_plane,
13711 .destroy = intel_plane_destroy,
13712 .atomic_get_property = intel_plane_atomic_get_property,
13713 .atomic_set_property = intel_plane_atomic_set_property,
13714 .atomic_duplicate_state = intel_plane_duplicate_state,
13715 .atomic_destroy_state = intel_plane_destroy_state,
13716 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013717};
13718
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013719static int
13720intel_legacy_cursor_update(struct drm_plane *plane,
13721 struct drm_crtc *crtc,
13722 struct drm_framebuffer *fb,
13723 int crtc_x, int crtc_y,
13724 unsigned int crtc_w, unsigned int crtc_h,
13725 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013726 uint32_t src_w, uint32_t src_h,
13727 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013728{
13729 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13730 int ret;
13731 struct drm_plane_state *old_plane_state, *new_plane_state;
13732 struct intel_plane *intel_plane = to_intel_plane(plane);
13733 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013734 struct intel_crtc_state *crtc_state =
13735 to_intel_crtc_state(crtc->state);
13736 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013737
13738 /*
13739 * When crtc is inactive or there is a modeset pending,
13740 * wait for it to complete in the slowpath
13741 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013742 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13743 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013744 goto slow;
13745
13746 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013747 /*
13748 * Don't do an async update if there is an outstanding commit modifying
13749 * the plane. This prevents our async update's changes from getting
13750 * overridden by a previous synchronous update's state.
13751 */
13752 if (old_plane_state->commit &&
13753 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13754 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013755
13756 /*
13757 * If any parameters change that may affect watermarks,
13758 * take the slowpath. Only changing fb or position should be
13759 * in the fastpath.
13760 */
13761 if (old_plane_state->crtc != crtc ||
13762 old_plane_state->src_w != src_w ||
13763 old_plane_state->src_h != src_h ||
13764 old_plane_state->crtc_w != crtc_w ||
13765 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013766 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013767 goto slow;
13768
13769 new_plane_state = intel_plane_duplicate_state(plane);
13770 if (!new_plane_state)
13771 return -ENOMEM;
13772
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013773 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13774 if (!new_crtc_state) {
13775 ret = -ENOMEM;
13776 goto out_free;
13777 }
13778
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013779 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13780
13781 new_plane_state->src_x = src_x;
13782 new_plane_state->src_y = src_y;
13783 new_plane_state->src_w = src_w;
13784 new_plane_state->src_h = src_h;
13785 new_plane_state->crtc_x = crtc_x;
13786 new_plane_state->crtc_y = crtc_y;
13787 new_plane_state->crtc_w = crtc_w;
13788 new_plane_state->crtc_h = crtc_h;
13789
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013790 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13791 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013792 to_intel_plane_state(new_plane_state));
13793 if (ret)
13794 goto out_free;
13795
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013796 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13797 if (ret)
13798 goto out_free;
13799
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013800 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13801 if (ret)
13802 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013803
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080013804 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013805
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013806 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013807 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13808 intel_plane->frontbuffer_bit);
13809
13810 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013811 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013812
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013813 /*
13814 * We cannot swap crtc_state as it may be in use by an atomic commit or
13815 * page flip that's running simultaneously. If we swap crtc_state and
13816 * destroy the old state, we will cause a use-after-free there.
13817 *
13818 * Only update active_planes, which is needed for our internal
13819 * bookkeeping. Either value will do the right thing when updating
13820 * planes atomically. If the cursor was part of the atomic update then
13821 * we would have taken the slowpath.
13822 */
13823 crtc_state->active_planes = new_crtc_state->active_planes;
13824
Ville Syrjälä72259532017-03-02 19:15:05 +020013825 if (plane->state->visible) {
13826 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013827 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013828 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020013829 } else {
13830 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020013831 intel_plane->disable_plane(intel_plane, crtc_state);
Ville Syrjälä72259532017-03-02 19:15:05 +020013832 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013833
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013834 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013835
13836out_unlock:
13837 mutex_unlock(&dev_priv->drm.struct_mutex);
13838out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013839 if (new_crtc_state)
13840 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013841 if (ret)
13842 intel_plane_destroy_state(plane, new_plane_state);
13843 else
13844 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013845 return ret;
13846
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013847slow:
13848 return drm_atomic_helper_update_plane(plane, crtc, fb,
13849 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013850 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013851}
13852
13853static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13854 .update_plane = intel_legacy_cursor_update,
13855 .disable_plane = drm_atomic_helper_disable_plane,
13856 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013857 .atomic_get_property = intel_plane_atomic_get_property,
13858 .atomic_set_property = intel_plane_atomic_set_property,
13859 .atomic_duplicate_state = intel_plane_duplicate_state,
13860 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013861 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013862};
13863
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013864static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13865 enum i9xx_plane_id i9xx_plane)
13866{
13867 if (!HAS_FBC(dev_priv))
13868 return false;
13869
13870 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13871 return i9xx_plane == PLANE_A; /* tied to pipe A */
13872 else if (IS_IVYBRIDGE(dev_priv))
13873 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13874 i9xx_plane == PLANE_C;
13875 else if (INTEL_GEN(dev_priv) >= 4)
13876 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13877 else
13878 return i9xx_plane == PLANE_A;
13879}
13880
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013881static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020013882intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070013883{
Ville Syrjälä881440a2018-10-05 15:58:17 +030013884 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013885 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013886 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030013887 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030013888 const u64 *modifiers;
13889 const u32 *formats;
13890 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013891 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013892
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013893 if (INTEL_GEN(dev_priv) >= 9)
13894 return skl_universal_plane_create(dev_priv, pipe,
13895 PLANE_PRIMARY);
13896
Ville Syrjälä881440a2018-10-05 15:58:17 +030013897 plane = intel_plane_alloc();
13898 if (IS_ERR(plane))
13899 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080013900
Ville Syrjälä881440a2018-10-05 15:58:17 +030013901 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013902 /*
13903 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13904 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13905 */
13906 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013907 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013908 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013909 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13910 plane->id = PLANE_PRIMARY;
13911 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013912
Ville Syrjälä881440a2018-10-05 15:58:17 +030013913 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13914 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013915 struct intel_fbc *fbc = &dev_priv->fbc;
13916
Ville Syrjälä881440a2018-10-05 15:58:17 +030013917 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013918 }
13919
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013920 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013921 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010013922 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013923 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013924
Ville Syrjälä881440a2018-10-05 15:58:17 +030013925 plane->max_stride = i9xx_plane_max_stride;
13926 plane->update_plane = i9xx_update_plane;
13927 plane->disable_plane = i9xx_disable_plane;
13928 plane->get_hw_state = i9xx_plane_get_hw_state;
13929 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013930
13931 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013932 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013933 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013934 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013935 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013936
Ville Syrjälä881440a2018-10-05 15:58:17 +030013937 plane->max_stride = i9xx_plane_max_stride;
13938 plane->update_plane = i9xx_update_plane;
13939 plane->disable_plane = i9xx_disable_plane;
13940 plane->get_hw_state = i9xx_plane_get_hw_state;
13941 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013942
13943 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070013944 }
13945
Ville Syrjälädeb19682018-10-05 15:58:08 +030013946 possible_crtcs = BIT(pipe);
13947
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013948 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030013949 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013950 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013951 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013952 DRM_PLANE_TYPE_PRIMARY,
13953 "primary %c", pipe_name(pipe));
13954 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013955 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013956 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013957 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013958 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020013959 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030013960 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013961 if (ret)
13962 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053013963
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013964 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020013965 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013966 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13967 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100013968 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013969 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013970 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013971 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040013972 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013973 }
13974
Dave Airlie5481e272016-10-25 16:36:13 +100013975 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013976 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013977 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013978 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053013979
Ville Syrjälä881440a2018-10-05 15:58:17 +030013980 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080013981
Ville Syrjälä881440a2018-10-05 15:58:17 +030013982 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013983
13984fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030013985 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013986
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013987 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070013988}
13989
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013990static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013991intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13992 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070013993{
Ville Syrjälädeb19682018-10-05 15:58:08 +030013994 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030013995 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013996 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070013997
Ville Syrjäläc539b572018-10-05 15:58:14 +030013998 cursor = intel_plane_alloc();
13999 if (IS_ERR(cursor))
14000 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080014001
Matt Roper3d7d6512014-06-10 08:28:13 -070014002 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020014003 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020014004 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020014005 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014006
14007 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014008 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014009 cursor->update_plane = i845_update_cursor;
14010 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014011 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014012 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014013 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014014 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014015 cursor->update_plane = i9xx_update_cursor;
14016 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014017 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014018 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014019 }
Matt Roper3d7d6512014-06-10 08:28:13 -070014020
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030014021 cursor->cursor.base = ~0;
14022 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030014023
14024 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14025 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014026
Ville Syrjälädeb19682018-10-05 15:58:08 +030014027 possible_crtcs = BIT(pipe);
14028
Ville Syrjälä580503c2016-10-31 22:37:00 +020014029 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014030 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014031 intel_cursor_formats,
14032 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070014033 cursor_format_modifiers,
14034 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014035 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014036 if (ret)
14037 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014038
Dave Airlie5481e272016-10-25 16:36:13 +100014039 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014040 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014041 DRM_MODE_ROTATE_0,
14042 DRM_MODE_ROTATE_0 |
14043 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014044
Matt Roperea2c67b2014-12-23 10:41:52 -080014045 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14046
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014047 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014048
14049fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030014050 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014051
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014052 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070014053}
14054
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014055static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14056 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014057{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014058 struct intel_crtc_scaler_state *scaler_state =
14059 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014060 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014061 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014062
Jani Nikula02584042018-12-31 16:56:41 +020014063 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014064 if (!crtc->num_scalers)
14065 return;
14066
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014067 for (i = 0; i < crtc->num_scalers; i++) {
14068 struct intel_scaler *scaler = &scaler_state->scalers[i];
14069
14070 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020014071 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014072 }
14073
14074 scaler_state->scaler_id = -1;
14075}
14076
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014077static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080014078{
14079 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014080 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014081 struct intel_plane *primary = NULL;
14082 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014083 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014084
Daniel Vetter955382f2013-09-19 14:05:45 +020014085 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014086 if (!intel_crtc)
14087 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080014088
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014089 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014090 if (!crtc_state) {
14091 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014092 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014093 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030014094 intel_crtc->config = crtc_state;
14095 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080014096 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014097
Ville Syrjälä580503c2016-10-31 22:37:00 +020014098 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014099 if (IS_ERR(primary)) {
14100 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070014101 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014102 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014103 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014104
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014105 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014106 struct intel_plane *plane;
14107
Ville Syrjälä580503c2016-10-31 22:37:00 +020014108 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014109 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014110 ret = PTR_ERR(plane);
14111 goto fail;
14112 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014113 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014114 }
14115
Ville Syrjälä580503c2016-10-31 22:37:00 +020014116 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014117 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014118 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070014119 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014120 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014121 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014122
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014123 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014124 &primary->base, &cursor->base,
14125 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030014126 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070014127 if (ret)
14128 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080014129
Jesse Barnes80824002009-09-10 15:28:06 -070014130 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070014131
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014132 /* initialize shared scalers */
14133 intel_crtc_init_scalers(intel_crtc, crtc_state);
14134
Ville Syrjälä1947fd12018-03-05 19:41:22 +020014135 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14136 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14137 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14138
14139 if (INTEL_GEN(dev_priv) < 9) {
14140 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14141
14142 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14143 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14144 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14145 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080014146
Jesse Barnes79e53942008-11-07 14:24:08 -080014147 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020014148
Matt Roper302da0c2018-12-10 13:54:15 -080014149 intel_color_init(intel_crtc);
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000014150
Daniel Vetter87b6b102014-05-15 15:33:46 +020014151 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014152
14153 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014154
14155fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014156 /*
14157 * drm_mode_config_cleanup() will free up any
14158 * crtcs/planes already initialized.
14159 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014160 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070014161 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014162
14163 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014164}
14165
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020014166int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14167 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070014168{
Carl Worth08d7b3d2009-04-29 14:43:54 -070014169 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040014170 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020014171 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014172
Keith Packard418da172017-03-14 23:25:07 -070014173 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014174 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014175 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014176
Rob Clark7707e652014-07-17 23:30:04 -040014177 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014178 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014179
Daniel Vetterc05422d2009-08-11 16:05:30 +020014180 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014181}
14182
Daniel Vetter66a92782012-07-12 20:08:18 +020014183static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014184{
Daniel Vetter66a92782012-07-12 20:08:18 +020014185 struct drm_device *dev = encoder->base.dev;
14186 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014187 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014188 int entry = 0;
14189
Damien Lespiaub2784e12014-08-05 11:29:37 +010014190 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014191 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014192 index_mask |= (1 << entry);
14193
Jesse Barnes79e53942008-11-07 14:24:08 -080014194 entry++;
14195 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014196
Jesse Barnes79e53942008-11-07 14:24:08 -080014197 return index_mask;
14198}
14199
Ville Syrjälä646d5772016-10-31 22:37:14 +020014200static bool has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014201{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014202 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014203 return false;
14204
14205 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14206 return false;
14207
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014208 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014209 return false;
14210
14211 return true;
14212}
14213
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014214static bool intel_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014215{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014216 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014217 return false;
14218
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014219 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014220 return false;
14221
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014222 if (IS_CHERRYVIEW(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014223 return false;
14224
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014225 if (HAS_PCH_LPT_H(dev_priv) &&
14226 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014227 return false;
14228
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014229 /* DDI E can't be used if DDI A requires 4 lanes */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014230 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014231 return false;
14232
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014233 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014234 return false;
14235
14236 return true;
14237}
14238
Imre Deak8090ba82016-08-10 14:07:33 +030014239void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14240{
14241 int pps_num;
14242 int pps_idx;
14243
14244 if (HAS_DDI(dev_priv))
14245 return;
14246 /*
14247 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14248 * everywhere where registers can be write protected.
14249 */
14250 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14251 pps_num = 2;
14252 else
14253 pps_num = 1;
14254
14255 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14256 u32 val = I915_READ(PP_CONTROL(pps_idx));
14257
14258 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14259 I915_WRITE(PP_CONTROL(pps_idx), val);
14260 }
14261}
14262
Imre Deak44cb7342016-08-10 14:07:29 +030014263static void intel_pps_init(struct drm_i915_private *dev_priv)
14264{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014265 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014266 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14267 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14268 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14269 else
14270 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014271
14272 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014273}
14274
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014275static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014276{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014277 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014278 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014279
Imre Deak44cb7342016-08-10 14:07:29 +030014280 intel_pps_init(dev_priv);
14281
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080014282 if (!HAS_DISPLAY(dev_priv))
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014283 return;
14284
Imre Deak97a824e12016-06-21 11:51:47 +030014285 /*
14286 * intel_edp_init_connector() depends on this completing first, to
14287 * prevent the registeration of both eDP and LVDS and the incorrect
14288 * sharing of the PPS.
14289 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014290 intel_lvds_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014291
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014292 if (intel_crt_present(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014293 intel_crt_init(dev_priv);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014294
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014295 if (IS_ICELAKE(dev_priv)) {
14296 intel_ddi_init(dev_priv, PORT_A);
14297 intel_ddi_init(dev_priv, PORT_B);
14298 intel_ddi_init(dev_priv, PORT_C);
14299 intel_ddi_init(dev_priv, PORT_D);
14300 intel_ddi_init(dev_priv, PORT_E);
14301 intel_ddi_init(dev_priv, PORT_F);
Madhav Chauhanbf4d57f2018-10-30 13:56:23 +020014302 icl_dsi_init(dev_priv);
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014303 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014304 /*
14305 * FIXME: Broxton doesn't support port detection via the
14306 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14307 * detect the ports.
14308 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014309 intel_ddi_init(dev_priv, PORT_A);
14310 intel_ddi_init(dev_priv, PORT_B);
14311 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014312
Jani Nikulae5186342018-07-05 16:25:08 +030014313 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014314 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014315 int found;
14316
Jesse Barnesde31fac2015-03-06 15:53:32 -080014317 /*
14318 * Haswell uses DDI functions to detect digital outputs.
14319 * On SKL pre-D0 the strap isn't connected, so we assume
14320 * it's there.
14321 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014322 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014323 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014324 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014325 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014326
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014327 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014328 * register */
14329 found = I915_READ(SFUSE_STRAP);
14330
14331 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014332 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014333 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014334 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014335 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014336 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014337 if (found & SFUSE_STRAP_DDIF_DETECTED)
14338 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014339 /*
14340 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14341 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014342 if (IS_GEN9_BC(dev_priv) &&
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014343 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14344 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14345 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014346 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014347
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014348 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014349 int found;
Jani Nikula7b91bf72017-08-18 12:30:19 +030014350 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014351
Ville Syrjälä646d5772016-10-31 22:37:14 +020014352 if (has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014353 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014354
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014355 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014356 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014357 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014358 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014359 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014360 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014361 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014362 }
14363
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014364 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014365 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014366
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014367 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014368 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014369
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014370 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014371 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014372
Daniel Vetter270b3042012-10-27 15:52:05 +020014373 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014374 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014375 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014376 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014377
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014378 /*
14379 * The DP_DETECTED bit is the latched state of the DDC
14380 * SDA pin at boot. However since eDP doesn't require DDC
14381 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14382 * eDP ports may have been muxed to an alternate function.
14383 * Thus we can't rely on the DP_DETECTED bit alone to detect
14384 * eDP ports. Consult the VBT as well as DP_DETECTED to
14385 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014386 *
14387 * Sadly the straps seem to be missing sometimes even for HDMI
14388 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14389 * and VBT for the presence of the port. Additionally we can't
14390 * trust the port type the VBT declares as we've seen at least
14391 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014392 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014393 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014394 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14395 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014396 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014397 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014398 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014399
Jani Nikula7b91bf72017-08-18 12:30:19 +030014400 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014401 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14402 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014403 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014404 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014405 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014406
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014407 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014408 /*
14409 * eDP not supported on port D,
14410 * so no need to worry about it
14411 */
14412 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14413 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014414 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014415 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014416 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014417 }
14418
Jani Nikulae5186342018-07-05 16:25:08 +030014419 vlv_dsi_init(dev_priv);
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014420 } else if (!IS_GEN(dev_priv, 2) && !IS_PINEVIEW(dev_priv)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014421 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014422
Paulo Zanonie2debe92013-02-18 19:00:27 -030014423 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014424 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014425 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014426 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014427 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014428 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014429 }
Ma Ling27185ae2009-08-24 13:50:23 +080014430
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014431 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014432 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014433 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014434
14435 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014436
Paulo Zanonie2debe92013-02-18 19:00:27 -030014437 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014438 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014439 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014440 }
Ma Ling27185ae2009-08-24 13:50:23 +080014441
Paulo Zanonie2debe92013-02-18 19:00:27 -030014442 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014443
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014444 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014445 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014446 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014447 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014448 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014449 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014450 }
Ma Ling27185ae2009-08-24 13:50:23 +080014451
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014452 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014453 intel_dp_init(dev_priv, DP_D, PORT_D);
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014454 } else if (IS_GEN(dev_priv, 2))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014455 intel_dvo_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014456
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +000014457 if (SUPPORTS_TV(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014458 intel_tv_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014459
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014460 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014461
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014462 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014463 encoder->base.possible_crtcs = encoder->crtc_mask;
14464 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014465 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014466 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014467
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014468 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014469
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014470 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014471}
14472
14473static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14474{
14475 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014476 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014477
Daniel Vetteref2d6332014-02-10 18:00:38 +010014478 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014479
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014480 i915_gem_object_lock(obj);
14481 WARN_ON(!obj->framebuffer_references--);
14482 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014483
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014484 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014485
Jesse Barnes79e53942008-11-07 14:24:08 -080014486 kfree(intel_fb);
14487}
14488
14489static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014490 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014491 unsigned int *handle)
14492{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014493 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014494
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014495 if (obj->userptr.mm) {
14496 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14497 return -EINVAL;
14498 }
14499
Chris Wilson05394f32010-11-08 19:18:58 +000014500 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014501}
14502
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014503static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14504 struct drm_file *file,
14505 unsigned flags, unsigned color,
14506 struct drm_clip_rect *clips,
14507 unsigned num_clips)
14508{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014509 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014510
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014511 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014512 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014513
14514 return 0;
14515}
14516
Jesse Barnes79e53942008-11-07 14:24:08 -080014517static const struct drm_framebuffer_funcs intel_fb_funcs = {
14518 .destroy = intel_user_framebuffer_destroy,
14519 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014520 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014521};
14522
Damien Lespiaub3218032015-02-27 11:15:18 +000014523static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014524u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014525 u32 pixel_format, u64 fb_modifier)
Damien Lespiaub3218032015-02-27 11:15:18 +000014526{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014527 struct intel_crtc *crtc;
14528 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014529
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014530 /*
14531 * We assume the primary plane for pipe A has
14532 * the highest stride limits of them all.
14533 */
14534 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14535 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014536
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014537 return plane->max_stride(plane, pixel_format, fb_modifier,
14538 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014539}
14540
Chris Wilson24dbf512017-02-15 10:59:18 +000014541static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14542 struct drm_i915_gem_object *obj,
14543 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014544{
Chris Wilson24dbf512017-02-15 10:59:18 +000014545 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014546 struct drm_framebuffer *fb = &intel_fb->base;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014547 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014548 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014549 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014550 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014551
Chris Wilsondd689282017-03-01 15:41:28 +000014552 i915_gem_object_lock(obj);
14553 obj->framebuffer_references++;
14554 tiling = i915_gem_object_get_tiling(obj);
14555 stride = i915_gem_object_get_stride(obj);
14556 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014557
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014558 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014559 /*
14560 * If there's a fence, enforce that
14561 * the fb modifier and tiling mode match.
14562 */
14563 if (tiling != I915_TILING_NONE &&
14564 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014565 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014566 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014567 }
14568 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014569 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014570 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014571 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014572 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014573 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014574 }
14575 }
14576
Ville Syrjälä17e8fd12018-10-29 20:34:53 +020014577 if (!drm_any_plane_has_format(&dev_priv->drm,
14578 mode_cmd->pixel_format,
14579 mode_cmd->modifier[0])) {
14580 struct drm_format_name_buf format_name;
14581
14582 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14583 drm_get_format_name(mode_cmd->pixel_format,
14584 &format_name),
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014585 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014586 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014587 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014588
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014589 /*
14590 * gen2/3 display engine uses the fence if present,
14591 * so the tiling mode must match the fb modifier exactly.
14592 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014593 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014594 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014595 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014596 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014597 }
14598
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014599 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14600 mode_cmd->modifier[0]);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014601 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014602 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014603 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014604 "tiled" : "linear",
14605 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014606 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014607 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014608
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014609 /*
14610 * If there's a fence, enforce that
14611 * the fb pitch and fence stride match.
14612 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014613 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14614 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14615 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014616 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014617 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014618
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014619 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14620 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014621 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014622
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014623 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014624
Chandra Kondurue44134f2018-05-12 03:03:15 +053014625 if (fb->format->format == DRM_FORMAT_NV12 &&
14626 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14627 fb->height < SKL_MIN_YUV_420_SRC_H ||
14628 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14629 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
Ville Syrjälä3b909462018-10-29 16:00:31 +020014630 goto err;
Chandra Kondurue44134f2018-05-12 03:03:15 +053014631 }
14632
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014633 for (i = 0; i < fb->format->num_planes; i++) {
14634 u32 stride_alignment;
14635
14636 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14637 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014638 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014639 }
14640
14641 stride_alignment = intel_fb_stride_alignment(fb, i);
14642
14643 /*
14644 * Display WA #0531: skl,bxt,kbl,glk
14645 *
14646 * Render decompression and plane width > 3840
14647 * combined with horizontal panning requires the
14648 * plane stride to be a multiple of 4. We'll just
14649 * require the entire fb to accommodate that to avoid
14650 * potential runtime errors at plane configuration time.
14651 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014652 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014653 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014654 stride_alignment *= 4;
14655
14656 if (fb->pitches[i] & (stride_alignment - 1)) {
14657 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14658 i, fb->pitches[i], stride_alignment);
14659 goto err;
14660 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014661
Daniel Stonea268bcd2018-05-18 15:30:08 +010014662 fb->obj[i] = &obj->base;
14663 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014664
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014665 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014666 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014667 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014668
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014669 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014670 if (ret) {
14671 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014672 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014673 }
14674
Jesse Barnes79e53942008-11-07 14:24:08 -080014675 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014676
14677err:
Chris Wilsondd689282017-03-01 15:41:28 +000014678 i915_gem_object_lock(obj);
14679 obj->framebuffer_references--;
14680 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014681 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014682}
14683
Jesse Barnes79e53942008-11-07 14:24:08 -080014684static struct drm_framebuffer *
14685intel_user_framebuffer_create(struct drm_device *dev,
14686 struct drm_file *filp,
Ville Syrjälä1eb83452015-11-11 19:11:29 +020014687 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014688{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014689 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014690 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014691 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014692
Chris Wilson03ac0642016-07-20 13:31:51 +010014693 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14694 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014695 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014696
Chris Wilson24dbf512017-02-15 10:59:18 +000014697 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014698 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014699 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014700
14701 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014702}
14703
Chris Wilson778e23a2016-12-05 14:29:39 +000014704static void intel_atomic_state_free(struct drm_atomic_state *state)
14705{
14706 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14707
14708 drm_atomic_state_default_release(state);
14709
14710 i915_sw_fence_fini(&intel_state->commit_ready);
14711
14712 kfree(state);
14713}
14714
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014715static enum drm_mode_status
14716intel_mode_valid(struct drm_device *dev,
14717 const struct drm_display_mode *mode)
14718{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014719 struct drm_i915_private *dev_priv = to_i915(dev);
14720 int hdisplay_max, htotal_max;
14721 int vdisplay_max, vtotal_max;
14722
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030014723 /*
14724 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14725 * of DBLSCAN modes to the output's mode list when they detect
14726 * the scaling mode property on the connector. And they don't
14727 * ask the kernel to validate those modes in any way until
14728 * modeset time at which point the client gets a protocol error.
14729 * So in order to not upset those clients we silently ignore the
14730 * DBLSCAN flag on such connectors. For other connectors we will
14731 * reject modes with the DBLSCAN flag in encoder->compute_config().
14732 * And we always reject DBLSCAN modes in connector->mode_valid()
14733 * as we never want such modes on the connector's mode list.
14734 */
14735
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014736 if (mode->vscan > 1)
14737 return MODE_NO_VSCAN;
14738
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014739 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14740 return MODE_H_ILLEGAL;
14741
14742 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14743 DRM_MODE_FLAG_NCSYNC |
14744 DRM_MODE_FLAG_PCSYNC))
14745 return MODE_HSYNC;
14746
14747 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14748 DRM_MODE_FLAG_PIXMUX |
14749 DRM_MODE_FLAG_CLKDIV2))
14750 return MODE_BAD;
14751
Ville Syrjäläad77c532018-06-15 20:44:05 +030014752 if (INTEL_GEN(dev_priv) >= 9 ||
14753 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14754 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14755 vdisplay_max = 4096;
14756 htotal_max = 8192;
14757 vtotal_max = 8192;
14758 } else if (INTEL_GEN(dev_priv) >= 3) {
14759 hdisplay_max = 4096;
14760 vdisplay_max = 4096;
14761 htotal_max = 8192;
14762 vtotal_max = 8192;
14763 } else {
14764 hdisplay_max = 2048;
14765 vdisplay_max = 2048;
14766 htotal_max = 4096;
14767 vtotal_max = 4096;
14768 }
14769
14770 if (mode->hdisplay > hdisplay_max ||
14771 mode->hsync_start > htotal_max ||
14772 mode->hsync_end > htotal_max ||
14773 mode->htotal > htotal_max)
14774 return MODE_H_ILLEGAL;
14775
14776 if (mode->vdisplay > vdisplay_max ||
14777 mode->vsync_start > vtotal_max ||
14778 mode->vsync_end > vtotal_max ||
14779 mode->vtotal > vtotal_max)
14780 return MODE_V_ILLEGAL;
14781
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014782 return MODE_OK;
14783}
14784
Jesse Barnes79e53942008-11-07 14:24:08 -080014785static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080014786 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070014787 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020014788 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014789 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080014790 .atomic_check = intel_atomic_check,
14791 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020014792 .atomic_state_alloc = intel_atomic_state_alloc,
14793 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000014794 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080014795};
14796
Imre Deak88212942016-03-16 13:38:53 +020014797/**
14798 * intel_init_display_hooks - initialize the display modesetting hooks
14799 * @dev_priv: device private
14800 */
14801void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070014802{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020014803 intel_init_cdclk_hooks(dev_priv);
14804
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014805 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014806 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014807 dev_priv->display.get_initial_plane_config =
14808 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014809 dev_priv->display.crtc_compute_clock =
14810 haswell_crtc_compute_clock;
14811 dev_priv->display.crtc_enable = haswell_crtc_enable;
14812 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014813 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014814 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014815 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014816 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020014817 dev_priv->display.crtc_compute_clock =
14818 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020014819 dev_priv->display.crtc_enable = haswell_crtc_enable;
14820 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014821 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014822 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014823 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014824 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020014825 dev_priv->display.crtc_compute_clock =
14826 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014827 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14828 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014829 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070014830 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014831 dev_priv->display.get_initial_plane_config =
14832 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014833 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14834 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14835 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14836 } else if (IS_VALLEYVIEW(dev_priv)) {
14837 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14838 dev_priv->display.get_initial_plane_config =
14839 i9xx_get_initial_plane_config;
14840 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070014841 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14842 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020014843 } else if (IS_G4X(dev_priv)) {
14844 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14845 dev_priv->display.get_initial_plane_config =
14846 i9xx_get_initial_plane_config;
14847 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14848 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14849 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020014850 } else if (IS_PINEVIEW(dev_priv)) {
14851 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14852 dev_priv->display.get_initial_plane_config =
14853 i9xx_get_initial_plane_config;
14854 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14855 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14856 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014857 } else if (!IS_GEN(dev_priv, 2)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014858 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014859 dev_priv->display.get_initial_plane_config =
14860 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020014861 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014862 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14863 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014864 } else {
14865 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14866 dev_priv->display.get_initial_plane_config =
14867 i9xx_get_initial_plane_config;
14868 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14869 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14870 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070014871 }
Jesse Barnese70236a2009-09-21 10:42:27 -070014872
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014873 if (IS_GEN(dev_priv, 5)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014874 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014875 } else if (IS_GEN(dev_priv, 6)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014876 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014877 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014878 /* FIXME: detect B0+ stepping and use auto training */
14879 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014880 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014881 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030014882 }
14883
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070014884 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020014885 dev_priv->display.update_crtcs = skl_update_crtcs;
14886 else
14887 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070014888}
14889
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014890/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000014891static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014892{
David Weinehall52a05c32016-08-22 13:32:44 +030014893 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014894 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014895 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014896
Ville Syrjälä2b37c612014-01-22 21:32:38 +020014897 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030014898 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070014899 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014900 sr1 = inb(VGA_SR_DATA);
14901 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030014902 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014903 udelay(300);
14904
Ville Syrjälä01f5a622014-12-16 18:38:37 +020014905 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014906 POSTING_READ(vga_reg);
14907}
14908
Daniel Vetterf8175862012-04-10 15:50:11 +020014909void intel_modeset_init_hw(struct drm_device *dev)
14910{
Chris Wilsonfac5e232016-07-04 11:34:36 +010014911 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010014912
Ville Syrjälä4c75b942016-10-31 22:37:12 +020014913 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030014914 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020014915 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020014916}
14917
Matt Roperd93c0372015-12-03 11:37:41 -080014918/*
14919 * Calculate what we think the watermarks should be for the state we've read
14920 * out of the hardware and then immediately program those watermarks so that
14921 * we ensure the hardware settings match our internal state.
14922 *
14923 * We can calculate what we think WM's should be by creating a duplicate of the
14924 * current state (which was constructed during hardware readout) and running it
14925 * through the atomic check code to calculate new watermark values in the
14926 * state object.
14927 */
14928static void sanitize_watermarks(struct drm_device *dev)
14929{
14930 struct drm_i915_private *dev_priv = to_i915(dev);
14931 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014932 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014933 struct drm_crtc *crtc;
14934 struct drm_crtc_state *cstate;
14935 struct drm_modeset_acquire_ctx ctx;
14936 int ret;
14937 int i;
14938
14939 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080014940 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080014941 return;
14942
14943 /*
14944 * We need to hold connection_mutex before calling duplicate_state so
14945 * that the connector loop is protected.
14946 */
14947 drm_modeset_acquire_init(&ctx, 0);
14948retry:
Matt Roper0cd12622016-01-12 07:13:37 -080014949 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080014950 if (ret == -EDEADLK) {
14951 drm_modeset_backoff(&ctx);
14952 goto retry;
14953 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080014954 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014955 }
14956
14957 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14958 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080014959 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014960
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014961 intel_state = to_intel_atomic_state(state);
14962
Matt Ropered4a6a72016-02-23 17:20:13 -080014963 /*
14964 * Hardware readout is the only time we don't want to calculate
14965 * intermediate watermarks (since we don't trust the current
14966 * watermarks).
14967 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020014968 if (!HAS_GMCH_DISPLAY(dev_priv))
14969 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080014970
Matt Roperd93c0372015-12-03 11:37:41 -080014971 ret = intel_atomic_check(dev, state);
14972 if (ret) {
14973 /*
14974 * If we fail here, it means that the hardware appears to be
14975 * programmed in a way that shouldn't be possible, given our
14976 * understanding of watermark requirements. This might mean a
14977 * mistake in the hardware readout code or a mistake in the
14978 * watermark calculations for a given platform. Raise a WARN
14979 * so that this is noticeable.
14980 *
14981 * If this actually happens, we'll have to just leave the
14982 * BIOS-programmed watermarks untouched and hope for the best.
14983 */
14984 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014985 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014986 }
14987
14988 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010014989 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080014990 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14991
Matt Ropered4a6a72016-02-23 17:20:13 -080014992 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014993 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010014994
14995 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080014996 }
14997
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014998put_state:
Chris Wilson08536952016-10-14 13:18:18 +010014999 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080015000fail:
Matt Roperd93c0372015-12-03 11:37:41 -080015001 drm_modeset_drop_locks(&ctx);
15002 drm_modeset_acquire_fini(&ctx);
15003}
15004
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015005static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15006{
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015007 if (IS_GEN(dev_priv, 5)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015008 u32 fdi_pll_clk =
15009 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15010
15011 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015012 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015013 dev_priv->fdi_pll_freq = 270000;
15014 } else {
15015 return;
15016 }
15017
15018 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15019}
15020
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015021static int intel_initial_commit(struct drm_device *dev)
15022{
15023 struct drm_atomic_state *state = NULL;
15024 struct drm_modeset_acquire_ctx ctx;
15025 struct drm_crtc *crtc;
15026 struct drm_crtc_state *crtc_state;
15027 int ret = 0;
15028
15029 state = drm_atomic_state_alloc(dev);
15030 if (!state)
15031 return -ENOMEM;
15032
15033 drm_modeset_acquire_init(&ctx, 0);
15034
15035retry:
15036 state->acquire_ctx = &ctx;
15037
15038 drm_for_each_crtc(crtc, dev) {
15039 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15040 if (IS_ERR(crtc_state)) {
15041 ret = PTR_ERR(crtc_state);
15042 goto out;
15043 }
15044
15045 if (crtc_state->active) {
15046 ret = drm_atomic_add_affected_planes(state, crtc);
15047 if (ret)
15048 goto out;
Ville Syrjäläfa6af5142018-11-20 15:54:49 +020015049
15050 /*
15051 * FIXME hack to force a LUT update to avoid the
15052 * plane update forcing the pipe gamma on without
15053 * having a proper LUT loaded. Remove once we
15054 * have readout for pipe gamma enable.
15055 */
15056 crtc_state->color_mgmt_changed = true;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015057 }
15058 }
15059
15060 ret = drm_atomic_commit(state);
15061
15062out:
15063 if (ret == -EDEADLK) {
15064 drm_atomic_state_clear(state);
15065 drm_modeset_backoff(&ctx);
15066 goto retry;
15067 }
15068
15069 drm_atomic_state_put(state);
15070
15071 drm_modeset_drop_locks(&ctx);
15072 drm_modeset_acquire_fini(&ctx);
15073
15074 return ret;
15075}
15076
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015077int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080015078{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030015079 struct drm_i915_private *dev_priv = to_i915(dev);
15080 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000015081 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080015082 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015083 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080015084
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015085 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15086
Jesse Barnes79e53942008-11-07 14:24:08 -080015087 drm_mode_config_init(dev);
15088
15089 dev->mode_config.min_width = 0;
15090 dev->mode_config.min_height = 0;
15091
Dave Airlie019d96c2011-09-29 16:20:42 +010015092 dev->mode_config.preferred_depth = 24;
15093 dev->mode_config.prefer_shadow = 1;
15094
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015095 dev->mode_config.allow_fb_modifiers = true;
15096
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015097 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015098
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015099 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015100 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015101 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015102
Jani Nikula27a981b2018-10-17 12:35:39 +030015103 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015104
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015105 intel_fbc_init(dev_priv);
15106
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015107 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015108
Lukas Wunner69f92f62015-07-15 13:57:35 +020015109 /*
15110 * There may be no VBT; and if the BIOS enabled SSC we can
15111 * just keep using it to avoid unnecessary flicker. Whereas if the
15112 * BIOS isn't using it, don't assume it will work even if the VBT
15113 * indicates as much.
15114 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015115 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015116 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15117 DREF_SSC1_ENABLE);
15118
15119 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15120 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15121 bios_lvds_use_ssc ? "en" : "dis",
15122 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15123 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15124 }
15125 }
15126
Ville Syrjäläad77c532018-06-15 20:44:05 +030015127 /* maximum framebuffer dimensions */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015128 if (IS_GEN(dev_priv, 2)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015129 dev->mode_config.max_width = 2048;
15130 dev->mode_config.max_height = 2048;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015131 } else if (IS_GEN(dev_priv, 3)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015132 dev->mode_config.max_width = 4096;
15133 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015134 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015135 dev->mode_config.max_width = 8192;
15136 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015137 }
Damien Lespiau068be562014-03-28 14:17:49 +000015138
Jani Nikula2a307c22016-11-30 17:43:04 +020015139 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15140 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015141 dev->mode_config.cursor_height = 1023;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015142 } else if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015143 dev->mode_config.cursor_width = 64;
15144 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015145 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015146 dev->mode_config.cursor_width = 256;
15147 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015148 }
15149
Matthew Auld73ebd502017-12-11 15:18:20 +000015150 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015151
Zhao Yakui28c97732009-10-09 11:39:41 +080015152 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015153 INTEL_INFO(dev_priv)->num_pipes,
15154 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015155
Damien Lespiau055e3932014-08-18 13:49:10 +010015156 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015157 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015158 if (ret) {
15159 drm_mode_config_cleanup(dev);
15160 return ret;
15161 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015162 }
15163
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015164 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015165 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015166
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015167 intel_update_czclk(dev_priv);
15168 intel_modeset_init_hw(dev);
15169
Ville Syrjäläb2045352016-05-13 23:41:27 +030015170 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015171 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015172
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015173 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015174 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015175 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015176
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015177 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015178 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015179 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015180
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015181 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015182 struct intel_initial_plane_config plane_config = {};
15183
Jesse Barnes46f297f2014-03-07 08:57:48 -080015184 if (!crtc->active)
15185 continue;
15186
Jesse Barnes46f297f2014-03-07 08:57:48 -080015187 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015188 * Note that reserving the BIOS fb up front prevents us
15189 * from stuffing other stolen allocations like the ring
15190 * on top. This prevents some ugliness at boot time, and
15191 * can even allow for smooth boot transitions if the BIOS
15192 * fb is large enough for the active pipe configuration.
15193 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015194 dev_priv->display.get_initial_plane_config(crtc,
15195 &plane_config);
15196
15197 /*
15198 * If the fb is shared between multiple heads, we'll
15199 * just get the first one.
15200 */
15201 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015202 }
Matt Roperd93c0372015-12-03 11:37:41 -080015203
15204 /*
15205 * Make sure hardware watermarks really match the state we read out.
15206 * Note that we need to do this after reconstructing the BIOS fb's
15207 * since the watermark calculation done here will use pstate->fb.
15208 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020015209 if (!HAS_GMCH_DISPLAY(dev_priv))
15210 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015211
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015212 /*
15213 * Force all active planes to recompute their states. So that on
15214 * mode_setcrtc after probe, all the intel_plane_state variables
15215 * are already calculated and there is no assert_plane warnings
15216 * during bootup.
15217 */
15218 ret = intel_initial_commit(dev);
15219 if (ret)
15220 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15221
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015222 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015223}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015224
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015225void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15226{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015227 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015228 /* 640x480@60Hz, ~25175 kHz */
15229 struct dpll clock = {
15230 .m1 = 18,
15231 .m2 = 7,
15232 .p1 = 13,
15233 .p2 = 4,
15234 .n = 2,
15235 };
15236 u32 dpll, fp;
15237 int i;
15238
15239 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15240
15241 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15242 pipe_name(pipe), clock.vco, clock.dot);
15243
15244 fp = i9xx_dpll_compute_fp(&clock);
15245 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15246 DPLL_VGA_MODE_DIS |
15247 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15248 PLL_P2_DIVIDE_BY_4 |
15249 PLL_REF_INPUT_DREFCLK |
15250 DPLL_VCO_ENABLE;
15251
15252 I915_WRITE(FP0(pipe), fp);
15253 I915_WRITE(FP1(pipe), fp);
15254
15255 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15256 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15257 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15258 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15259 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15260 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15261 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15262
15263 /*
15264 * Apparently we need to have VGA mode enabled prior to changing
15265 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15266 * dividers, even though the register value does change.
15267 */
15268 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15269 I915_WRITE(DPLL(pipe), dpll);
15270
15271 /* Wait for the clocks to stabilize. */
15272 POSTING_READ(DPLL(pipe));
15273 udelay(150);
15274
15275 /* The pixel multiplier can only be updated once the
15276 * DPLL is enabled and the clocks are stable.
15277 *
15278 * So write it again.
15279 */
15280 I915_WRITE(DPLL(pipe), dpll);
15281
15282 /* We do this three times for luck */
15283 for (i = 0; i < 3 ; i++) {
15284 I915_WRITE(DPLL(pipe), dpll);
15285 POSTING_READ(DPLL(pipe));
15286 udelay(150); /* wait for warmup */
15287 }
15288
15289 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15290 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015291
15292 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015293}
15294
15295void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15296{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015297 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15298
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015299 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15300 pipe_name(pipe));
15301
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015302 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15303 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15304 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015305 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15306 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015307
15308 I915_WRITE(PIPECONF(pipe), 0);
15309 POSTING_READ(PIPECONF(pipe));
15310
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015311 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015312
15313 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15314 POSTING_READ(DPLL(pipe));
15315}
15316
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015317static void
15318intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15319{
15320 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015321
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015322 if (INTEL_GEN(dev_priv) >= 4)
15323 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015324
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015325 for_each_intel_crtc(&dev_priv->drm, crtc) {
15326 struct intel_plane *plane =
15327 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015328 struct intel_crtc *plane_crtc;
15329 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015330
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015331 if (!plane->get_hw_state(plane, &pipe))
15332 continue;
15333
15334 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015335 continue;
15336
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015337 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15338 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015339
15340 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15341 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015342 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015343}
15344
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015345static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15346{
15347 struct drm_device *dev = crtc->base.dev;
15348 struct intel_encoder *encoder;
15349
15350 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15351 return true;
15352
15353 return false;
15354}
15355
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015356static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15357{
15358 struct drm_device *dev = encoder->base.dev;
15359 struct intel_connector *connector;
15360
15361 for_each_connector_on_encoder(dev, &encoder->base, connector)
15362 return connector;
15363
15364 return NULL;
15365}
15366
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015367static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015368 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015369{
15370 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015371 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015372}
15373
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015374static void intel_sanitize_crtc(struct intel_crtc *crtc,
15375 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015376{
15377 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015378 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015379 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15380 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015381
Daniel Vetter24929352012-07-02 20:28:59 +020015382 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015383 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015384 i915_reg_t reg = PIPECONF(cpu_transcoder);
15385
15386 I915_WRITE(reg,
15387 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15388 }
Daniel Vetter24929352012-07-02 20:28:59 +020015389
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015390 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015391 struct intel_plane *plane;
15392
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015393 /* Disable everything but the primary plane */
15394 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015395 const struct intel_plane_state *plane_state =
15396 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015397
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015398 if (plane_state->base.visible &&
15399 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15400 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015401 }
Daniel Vetter96256042015-02-13 21:03:42 +010015402 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015403
Daniel Vetter24929352012-07-02 20:28:59 +020015404 /* Adjust the state of the output pipe according to whether we
15405 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015406 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015407 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015408
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015409 if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015410 /*
15411 * We start out with underrun reporting disabled to avoid races.
15412 * For correct bookkeeping mark this on active crtcs.
15413 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015414 * Also on gmch platforms we dont have any hardware bits to
15415 * disable the underrun reporting. Which means we need to start
15416 * out with underrun reporting disabled also on inactive pipes,
15417 * since otherwise we'll complain about the garbage we read when
15418 * e.g. coming up after runtime pm.
15419 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015420 * No protection against concurrent access is required - at
15421 * worst a fifo underrun happens which also sets this to false.
15422 */
15423 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015424 /*
15425 * We track the PCH trancoder underrun reporting state
15426 * within the crtc. With crtc for pipe A housing the underrun
15427 * reporting state for PCH transcoder A, crtc for pipe B housing
15428 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15429 * and marking underrun reporting as disabled for the non-existing
15430 * PCH transcoders B and C would prevent enabling the south
15431 * error interrupt (see cpt_can_enable_serr_int()).
15432 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015433 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015434 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015435 }
Daniel Vetter24929352012-07-02 20:28:59 +020015436}
15437
15438static void intel_sanitize_encoder(struct intel_encoder *encoder)
15439{
Imre Deak70332ac2018-11-01 16:04:27 +020015440 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015441 struct intel_connector *connector;
Daniel Vetter24929352012-07-02 20:28:59 +020015442
15443 /* We need to check both for a crtc link (meaning that the
15444 * encoder is active and trying to read from a pipe) and the
15445 * pipe itself being active. */
15446 bool has_active_crtc = encoder->base.crtc &&
15447 to_intel_crtc(encoder->base.crtc)->active;
15448
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015449 connector = intel_encoder_find_connector(encoder);
15450 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015451 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15452 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015453 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015454
15455 /* Connector is active, but has no active pipe. This is
15456 * fallout from our resume register restoring. Disable
15457 * the encoder manually again. */
15458 if (encoder->base.crtc) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015459 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15460
Daniel Vetter24929352012-07-02 20:28:59 +020015461 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15462 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015463 encoder->base.name);
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015464 if (encoder->disable)
15465 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015466 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015467 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Daniel Vetter24929352012-07-02 20:28:59 +020015468 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015469 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015470
15471 /* Inconsistent output/port/pipe state happens presumably due to
15472 * a bug in one of the get_hw_state functions. Or someplace else
15473 * in our code, like the register restore mess on resume. Clamp
15474 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015475
15476 connector->base.dpms = DRM_MODE_DPMS_OFF;
15477 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015478 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015479
15480 /* notify opregion of the sanitized encoder state */
15481 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Imre Deak70332ac2018-11-01 16:04:27 +020015482
15483 if (INTEL_GEN(dev_priv) >= 11)
15484 icl_sanitize_encoder_pll_mapping(encoder);
Daniel Vetter24929352012-07-02 20:28:59 +020015485}
15486
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015487void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015488{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015489 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015490
Imre Deak04098752014-02-18 00:02:16 +020015491 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15492 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015493 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015494 }
15495}
15496
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015497void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015498{
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015499 /* This function can be called both from intel_modeset_setup_hw_state or
15500 * at a very early point in our resume sequence, where the power well
15501 * structures are not yet restored. Since this function is at a very
15502 * paranoid "someone might have enabled VGA while we were not looking"
15503 * level, just check if the power well is enabled instead of trying to
15504 * follow the "don't touch the power well if we don't need it" policy
15505 * the rest of the driver uses. */
Imre Deak6392f842016-02-12 18:55:13 +020015506 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015507 return;
15508
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015509 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015510
15511 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015512}
15513
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015514/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015515static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015516{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015517 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015518 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015519
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015520 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015521 struct intel_plane_state *plane_state =
15522 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015523 struct intel_crtc_state *crtc_state;
15524 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015525 bool visible;
15526
15527 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015528
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015529 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15530 crtc_state = to_intel_crtc_state(crtc->base.state);
15531
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015532 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015533
15534 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15535 plane->base.base.id, plane->base.name,
15536 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015537 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015538
15539 for_each_intel_crtc(&dev_priv->drm, crtc) {
15540 struct intel_crtc_state *crtc_state =
15541 to_intel_crtc_state(crtc->base.state);
15542
15543 fixup_active_planes(crtc_state);
15544 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015545}
15546
Daniel Vetter30e984d2013-06-05 13:34:17 +020015547static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015548{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015549 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015550 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015551 struct intel_crtc *crtc;
15552 struct intel_encoder *encoder;
15553 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015554 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015555 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015556
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015557 dev_priv->active_crtcs = 0;
15558
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015559 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015560 struct intel_crtc_state *crtc_state =
15561 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015562
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015563 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015564 memset(crtc_state, 0, sizeof(*crtc_state));
15565 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015566
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015567 crtc_state->base.active = crtc_state->base.enable =
15568 dev_priv->display.get_pipe_config(crtc, crtc_state);
15569
15570 crtc->base.enabled = crtc_state->base.enable;
15571 crtc->active = crtc_state->base.active;
15572
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015573 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015574 dev_priv->active_crtcs |= 1 << crtc->pipe;
15575
Ville Syrjälä78108b72016-05-27 20:59:19 +030015576 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15577 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015578 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015579 }
15580
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015581 readout_plane_state(dev_priv);
15582
Daniel Vetter53589012013-06-05 13:34:16 +020015583 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15584 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15585
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015586 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15587 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015588 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015589 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015590 struct intel_crtc_state *crtc_state =
15591 to_intel_crtc_state(crtc->base.state);
15592
15593 if (crtc_state->base.active &&
15594 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015595 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015596 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015597 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015598
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015599 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015600 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015601 }
15602
Damien Lespiaub2784e12014-08-05 11:29:37 +010015603 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015604 pipe = 0;
15605
15606 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015607 struct intel_crtc_state *crtc_state;
15608
Ville Syrjälä98187832016-10-31 22:37:10 +020015609 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015610 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015611
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015612 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015613 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015614 } else {
15615 encoder->base.crtc = NULL;
15616 }
15617
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015618 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015619 encoder->base.base.id, encoder->base.name,
15620 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015621 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015622 }
15623
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015624 drm_connector_list_iter_begin(dev, &conn_iter);
15625 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015626 if (connector->get_hw_state(connector)) {
15627 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015628
15629 encoder = connector->encoder;
15630 connector->base.encoder = &encoder->base;
15631
15632 if (encoder->base.crtc &&
15633 encoder->base.crtc->state->active) {
15634 /*
15635 * This has to be done during hardware readout
15636 * because anything calling .crtc_disable may
15637 * rely on the connector_mask being accurate.
15638 */
15639 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015640 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015641 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015642 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015643 }
15644
Daniel Vetter24929352012-07-02 20:28:59 +020015645 } else {
15646 connector->base.dpms = DRM_MODE_DPMS_OFF;
15647 connector->base.encoder = NULL;
15648 }
15649 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015650 connector->base.base.id, connector->base.name,
15651 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015652 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015653 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015654
15655 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015656 struct intel_crtc_state *crtc_state =
15657 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015658 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015659
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015660 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015661 if (crtc_state->base.active) {
15662 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015663 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15664 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015665 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015666 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15667
15668 /*
15669 * The initial mode needs to be set in order to keep
15670 * the atomic core happy. It wants a valid mode if the
15671 * crtc's enabled, so we do the above call.
15672 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010015673 * But we don't set all the derived state fully, hence
15674 * set a flag to indicate that a full recalculation is
15675 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015676 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015677 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030015678
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020015679 intel_crtc_compute_pixel_rate(crtc_state);
15680
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015681 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030015682 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015683 if (WARN_ON(min_cdclk < 0))
15684 min_cdclk = 0;
15685 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015686
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020015687 drm_calc_timestamping_constants(&crtc->base,
15688 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020015689 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015690 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020015691
Ville Syrjäläd305e062017-08-30 21:57:03 +030015692 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030015693 dev_priv->min_voltage_level[crtc->pipe] =
15694 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015695
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015696 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015697 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020015698}
15699
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015700static void
15701get_encoder_power_domains(struct drm_i915_private *dev_priv)
15702{
15703 struct intel_encoder *encoder;
15704
15705 for_each_intel_encoder(&dev_priv->drm, encoder) {
15706 u64 get_domains;
15707 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030015708 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015709
15710 if (!encoder->get_power_domains)
15711 continue;
15712
Imre Deak52528052018-06-21 21:44:49 +030015713 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030015714 * MST-primary and inactive encoders don't have a crtc state
15715 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030015716 */
Imre Deakb79ebe72018-07-05 15:26:54 +030015717 if (!encoder->base.crtc)
15718 continue;
Imre Deak52528052018-06-21 21:44:49 +030015719
Imre Deakb79ebe72018-07-05 15:26:54 +030015720 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030015721 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015722 for_each_power_domain(domain, get_domains)
15723 intel_display_power_get(dev_priv, domain);
15724 }
15725}
15726
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015727static void intel_early_display_was(struct drm_i915_private *dev_priv)
15728{
15729 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15730 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15731 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15732 DARBF_GATING_DIS);
15733
15734 if (IS_HASWELL(dev_priv)) {
15735 /*
15736 * WaRsPkgCStateDisplayPMReq:hsw
15737 * System hang if this isn't done before disabling all planes!
15738 */
15739 I915_WRITE(CHICKEN_PAR1_1,
15740 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15741 }
15742}
15743
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015744static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
15745 enum port port, i915_reg_t hdmi_reg)
15746{
15747 u32 val = I915_READ(hdmi_reg);
15748
15749 if (val & SDVO_ENABLE ||
15750 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
15751 return;
15752
15753 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
15754 port_name(port));
15755
15756 val &= ~SDVO_PIPE_SEL_MASK;
15757 val |= SDVO_PIPE_SEL(PIPE_A);
15758
15759 I915_WRITE(hdmi_reg, val);
15760}
15761
15762static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
15763 enum port port, i915_reg_t dp_reg)
15764{
15765 u32 val = I915_READ(dp_reg);
15766
15767 if (val & DP_PORT_EN ||
15768 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
15769 return;
15770
15771 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
15772 port_name(port));
15773
15774 val &= ~DP_PIPE_SEL_MASK;
15775 val |= DP_PIPE_SEL(PIPE_A);
15776
15777 I915_WRITE(dp_reg, val);
15778}
15779
15780static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
15781{
15782 /*
15783 * The BIOS may select transcoder B on some of the PCH
15784 * ports even it doesn't enable the port. This would trip
15785 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
15786 * Sanitize the transcoder select bits to prevent that. We
15787 * assume that the BIOS never actually enabled the port,
15788 * because if it did we'd actually have to toggle the port
15789 * on and back off to make the transcoder A select stick
15790 * (see. intel_dp_link_down(), intel_disable_hdmi(),
15791 * intel_disable_sdvo()).
15792 */
15793 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
15794 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
15795 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
15796
15797 /* PCH SDVOB multiplex with HDMIB */
15798 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
15799 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
15800 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
15801}
15802
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015803/* Scan out the current hw modeset state,
15804 * and sanitizes it to the current state
15805 */
15806static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015807intel_modeset_setup_hw_state(struct drm_device *dev,
15808 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020015809{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015810 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015811 struct intel_crtc *crtc;
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015812 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015813 struct intel_encoder *encoder;
Daniel Vetter35c95372013-07-17 06:55:04 +020015814 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015815
Imre Deak2cd9a682018-08-16 15:37:57 +030015816 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15817
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015818 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015819 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015820
15821 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015822 get_encoder_power_domains(dev_priv);
15823
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015824 if (HAS_PCH_IBX(dev_priv))
15825 ibx_sanitize_pch_ports(dev_priv);
15826
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015827 /*
15828 * intel_sanitize_plane_mapping() may need to do vblank
15829 * waits, so we need vblank interrupts restored beforehand.
15830 */
15831 for_each_intel_crtc(&dev_priv->drm, crtc) {
15832 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015833
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015834 if (crtc->base.state->active)
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015835 drm_crtc_vblank_on(&crtc->base);
Daniel Vetter24929352012-07-02 20:28:59 +020015836 }
15837
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015838 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015839
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015840 for_each_intel_encoder(dev, encoder)
15841 intel_sanitize_encoder(encoder);
15842
15843 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015844 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015845 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015846 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020015847 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020015848 }
Daniel Vetter9a935852012-07-05 22:34:27 +020015849
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020015850 intel_modeset_update_connector_atomic_state(dev);
15851
Daniel Vetter35c95372013-07-17 06:55:04 +020015852 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15853 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15854
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010015855 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020015856 continue;
15857
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015858 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15859 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020015860
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015861 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020015862 pll->on = false;
15863 }
15864
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015865 if (IS_G4X(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015866 g4x_wm_get_hw_state(dev_priv);
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015867 g4x_wm_sanitize(dev_priv);
15868 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015869 vlv_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015870 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070015871 } else if (INTEL_GEN(dev_priv) >= 9) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015872 skl_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015873 } else if (HAS_PCH_SPLIT(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015874 ilk_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015875 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015876
15877 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020015878 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015879
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015880 crtc_state = to_intel_crtc_state(crtc->base.state);
15881 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015882 if (WARN_ON(put_domains))
15883 modeset_put_power_domains(dev_priv, put_domains);
15884 }
Imre Deak2cd9a682018-08-16 15:37:57 +030015885
15886 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni010cf732016-01-19 11:35:48 -020015887
15888 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015889}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030015890
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015891void intel_display_resume(struct drm_device *dev)
15892{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015893 struct drm_i915_private *dev_priv = to_i915(dev);
15894 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15895 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015896 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020015897
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015898 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030015899 if (state)
15900 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015901
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015902 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015903
Maarten Lankhorst73974892016-08-05 23:28:27 +030015904 while (1) {
15905 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15906 if (ret != -EDEADLK)
15907 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015908
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015909 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015910 }
15911
Maarten Lankhorst73974892016-08-05 23:28:27 +030015912 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010015913 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030015914
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053015915 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015916 drm_modeset_drop_locks(&ctx);
15917 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015918
Chris Wilson08536952016-10-14 13:18:18 +010015919 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015920 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000015921 if (state)
15922 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010015923}
15924
Manasi Navare886c6b82017-10-26 14:52:00 -070015925static void intel_hpd_poll_fini(struct drm_device *dev)
15926{
15927 struct intel_connector *connector;
15928 struct drm_connector_list_iter conn_iter;
15929
Chris Wilson448aa912017-11-28 11:01:47 +000015930 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070015931 drm_connector_list_iter_begin(dev, &conn_iter);
15932 for_each_intel_connector_iter(connector, &conn_iter) {
15933 if (connector->modeset_retry_work.func)
15934 cancel_work_sync(&connector->modeset_retry_work);
Ramalingam Cd3dacc72018-10-29 15:15:46 +053015935 if (connector->hdcp.shim) {
15936 cancel_delayed_work_sync(&connector->hdcp.check_work);
15937 cancel_work_sync(&connector->hdcp.prop_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050015938 }
Manasi Navare886c6b82017-10-26 14:52:00 -070015939 }
15940 drm_connector_list_iter_end(&conn_iter);
15941}
15942
Jesse Barnes79e53942008-11-07 14:24:08 -080015943void intel_modeset_cleanup(struct drm_device *dev)
15944{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015945 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070015946
Chris Wilson8bcf9f72018-07-10 10:44:20 +010015947 flush_workqueue(dev_priv->modeset_wq);
15948
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015949 flush_work(&dev_priv->atomic_helper.free_work);
15950 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15951
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015952 /*
15953 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020015954 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015955 * experience fancy races otherwise.
15956 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020015957 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070015958
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015959 /*
15960 * Due to the hpd irq storm handling the hotplug work can re-arm the
15961 * poll handlers. Hence disable polling after hpd handling is shut down.
15962 */
Manasi Navare886c6b82017-10-26 14:52:00 -070015963 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015964
Daniel Vetter4f256d82017-07-15 00:46:55 +020015965 /* poll work can call into fbdev, hence clean that up afterwards */
15966 intel_fbdev_fini(dev_priv);
15967
Jesse Barnes723bfd72010-10-07 16:01:13 -070015968 intel_unregister_dsm_handler();
15969
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020015970 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050015971
Chris Wilson1630fe72011-07-08 12:22:42 +010015972 /* flush any delayed tasks or pending work */
15973 flush_scheduled_work();
15974
Jesse Barnes79e53942008-11-07 14:24:08 -080015975 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010015976
José Roberto de Souza58db08a72018-11-07 16:16:47 -080015977 intel_overlay_cleanup(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030015978
Tvrtko Ursulin40196442016-12-01 14:16:42 +000015979 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015980
15981 destroy_workqueue(dev_priv->modeset_wq);
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015982
15983 intel_fbc_cleanup_cfb(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080015984}
15985
Dave Airlie28d52042009-09-21 14:33:58 +100015986/*
15987 * set vga decode state - true == enable VGA decode
15988 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015989int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100015990{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015991 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100015992 u16 gmch_ctrl;
15993
Chris Wilson75fa0412014-02-07 18:37:02 -020015994 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15995 DRM_ERROR("failed to read control word\n");
15996 return -EIO;
15997 }
15998
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020015999 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16000 return 0;
16001
Dave Airlie28d52042009-09-21 14:33:58 +100016002 if (state)
16003 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16004 else
16005 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020016006
16007 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16008 DRM_ERROR("failed to write control word\n");
16009 return -EIO;
16010 }
16011
Dave Airlie28d52042009-09-21 14:33:58 +100016012 return 0;
16013}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016014
Chris Wilson98a2f412016-10-12 10:05:18 +010016015#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16016
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016017struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016018
16019 u32 power_well_driver;
16020
Chris Wilson63b66e52013-08-08 15:12:06 +020016021 int num_transcoders;
16022
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016023 struct intel_cursor_error_state {
16024 u32 control;
16025 u32 position;
16026 u32 base;
16027 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010016028 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016029
16030 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016031 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016032 u32 source;
Imre Deakf301b1e2014-04-18 15:55:04 +030016033 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010016034 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016035
16036 struct intel_plane_error_state {
16037 u32 control;
16038 u32 stride;
16039 u32 size;
16040 u32 pos;
16041 u32 addr;
16042 u32 surface;
16043 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010016044 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020016045
16046 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016047 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020016048 enum transcoder cpu_transcoder;
16049
16050 u32 conf;
16051
16052 u32 htotal;
16053 u32 hblank;
16054 u32 hsync;
16055 u32 vtotal;
16056 u32 vblank;
16057 u32 vsync;
16058 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016059};
16060
16061struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010016062intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016063{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016064 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020016065 int transcoders[] = {
16066 TRANSCODER_A,
16067 TRANSCODER_B,
16068 TRANSCODER_C,
16069 TRANSCODER_EDP,
16070 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016071 int i;
16072
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080016073 if (!HAS_DISPLAY(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016074 return NULL;
16075
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016076 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016077 if (error == NULL)
16078 return NULL;
16079
Chris Wilsonc0336662016-05-06 15:40:21 +010016080 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030016081 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016082
Damien Lespiau055e3932014-08-18 13:49:10 +010016083 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020016084 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016085 __intel_display_power_is_enabled(dev_priv,
16086 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020016087 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016088 continue;
16089
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030016090 error->cursor[i].control = I915_READ(CURCNTR(i));
16091 error->cursor[i].position = I915_READ(CURPOS(i));
16092 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016093
16094 error->plane[i].control = I915_READ(DSPCNTR(i));
16095 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016096 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030016097 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016098 error->plane[i].pos = I915_READ(DSPPOS(i));
16099 }
Chris Wilsonc0336662016-05-06 15:40:21 +010016100 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030016101 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016102 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016103 error->plane[i].surface = I915_READ(DSPSURF(i));
16104 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16105 }
16106
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016107 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e2014-04-18 15:55:04 +030016108
Chris Wilsonc0336662016-05-06 15:40:21 +010016109 if (HAS_GMCH_DISPLAY(dev_priv))
Imre Deakf301b1e2014-04-18 15:55:04 +030016110 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020016111 }
16112
Jani Nikula4d1de972016-03-18 17:05:42 +020016113 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010016114 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030016115 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016116 error->num_transcoders++; /* Account for eDP. */
16117
16118 for (i = 0; i < error->num_transcoders; i++) {
16119 enum transcoder cpu_transcoder = transcoders[i];
16120
Imre Deakddf9c532013-11-27 22:02:02 +020016121 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016122 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020016123 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016124 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016125 continue;
16126
Chris Wilson63b66e52013-08-08 15:12:06 +020016127 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16128
16129 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16130 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16131 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16132 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16133 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16134 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16135 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016136 }
16137
16138 return error;
16139}
16140
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016141#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16142
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016143void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016144intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016145 struct intel_display_error_state *error)
16146{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000016147 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016148 int i;
16149
Chris Wilson63b66e52013-08-08 15:12:06 +020016150 if (!error)
16151 return;
16152
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000016153 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010016154 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016155 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016156 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010016157 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016158 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020016159 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016160 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016161 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e2014-04-18 15:55:04 +030016162 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016163
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016164 err_printf(m, "Plane [%d]:\n", i);
16165 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16166 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016167 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016168 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16169 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016170 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016171 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016172 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016173 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016174 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16175 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016176 }
16177
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016178 err_printf(m, "Cursor [%d]:\n", i);
16179 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16180 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16181 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016182 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016183
16184 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016185 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016186 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016187 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016188 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016189 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16190 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16191 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16192 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16193 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16194 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16195 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16196 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016197}
Chris Wilson98a2f412016-10-12 10:05:18 +010016198
16199#endif