blob: 76eed9d47bc532925be87afaf6152b48ad0ecfa7 [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
27#include <linux/i2c.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010028#include <linux/input.h>
29#include <linux/intel-iommu.h>
Shaohua Li7662c8b2009-06-26 11:23:55 +080030#include <linux/kernel.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010031#include <linux/module.h>
32#include <linux/reservation.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Jesse Barnes9cce37f2010-08-13 15:11:26 -070034#include <linux/vgaarb.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010035
Xi Ruoyao319c1d42015-03-12 20:16:32 +080036#include <drm/drm_atomic.h>
Matt Roperc196e1d2015-01-21 16:35:48 -080037#include <drm/drm_atomic_helper.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010038#include <drm/drm_atomic_uapi.h>
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/drm_dp_helper.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010040#include <drm/drm_edid.h>
41#include <drm/drm_fourcc.h>
Matt Roper465c1202014-05-29 08:06:54 -070042#include <drm/drm_plane_helper.h>
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010043#include <drm/drm_probe_helper.h>
Matt Roper465c1202014-05-29 08:06:54 -070044#include <drm/drm_rect.h>
Sam Ravnborgd0e93592019-01-26 13:25:24 +010045#include <drm/i915_drm.h>
46
47#include "i915_drv.h"
48#include "i915_gem_clflush.h"
49#include "i915_trace.h"
50#include "intel_drv.h"
51#include "intel_dsi.h"
52#include "intel_frontbuffer.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080053
Chris Wilson9f588922019-01-16 15:33:04 +000054#include "intel_drv.h"
55#include "intel_dsi.h"
56#include "intel_frontbuffer.h"
57
58#include "i915_drv.h"
59#include "i915_gem_clflush.h"
60#include "i915_reset.h"
61#include "i915_trace.h"
62
Matt Roper465c1202014-05-29 08:06:54 -070063/* Primary plane formats for gen <= 3 */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020064static const u32 i8xx_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010065 DRM_FORMAT_C8,
66 DRM_FORMAT_RGB565,
Matt Roper465c1202014-05-29 08:06:54 -070067 DRM_FORMAT_XRGB1555,
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010068 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070069};
70
71/* Primary plane formats for gen >= 4 */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020072static const u32 i965_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010073 DRM_FORMAT_C8,
74 DRM_FORMAT_RGB565,
75 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070076 DRM_FORMAT_XBGR8888,
Damien Lespiau6c0fd452015-05-19 12:29:16 +010077 DRM_FORMAT_XRGB2101010,
78 DRM_FORMAT_XBGR2101010,
79};
80
Jani Nikulaba3f4d02019-01-18 14:01:23 +020081static const u64 i9xx_format_modifiers[] = {
Ben Widawsky714244e2017-08-01 09:58:16 -070082 I915_FORMAT_MOD_X_TILED,
83 DRM_FORMAT_MOD_LINEAR,
84 DRM_FORMAT_MOD_INVALID
85};
86
Matt Roper3d7d6512014-06-10 08:28:13 -070087/* Cursor formats */
Jani Nikulaba3f4d02019-01-18 14:01:23 +020088static const u32 intel_cursor_formats[] = {
Matt Roper3d7d6512014-06-10 08:28:13 -070089 DRM_FORMAT_ARGB8888,
90};
91
Jani Nikulaba3f4d02019-01-18 14:01:23 +020092static const u64 cursor_format_modifiers[] = {
Ben Widawsky714244e2017-08-01 09:58:16 -070093 DRM_FORMAT_MOD_LINEAR,
94 DRM_FORMAT_MOD_INVALID
95};
96
Jesse Barnesf1f644d2013-06-27 00:39:25 +030097static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020098 struct intel_crtc_state *pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +030099static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200100 struct intel_crtc_state *pipe_config);
Jesse Barnesf1f644d2013-06-27 00:39:25 +0300101
Chris Wilson24dbf512017-02-15 10:59:18 +0000102static int intel_framebuffer_init(struct intel_framebuffer *ifb,
103 struct drm_i915_gem_object *obj,
104 struct drm_mode_fb_cmd2 *mode_cmd);
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +0200105static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
106static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
Maarten Lankhorst4c354752018-10-11 12:04:49 +0200107static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
108 const struct intel_link_m_n *m_n,
109 const struct intel_link_m_n *m2_n2);
Maarten Lankhorstfdf73512018-10-04 11:45:52 +0200110static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
111static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
112static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
113static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200114static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200115 const struct intel_crtc_state *pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200116static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200117 const struct intel_crtc_state *pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200118static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
119static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
Nabendu Maiti1c74eea2016-11-29 11:23:14 +0530120static void intel_crtc_init_scalers(struct intel_crtc *crtc,
121 struct intel_crtc_state *crtc_state);
Maarten Lankhorstb2562712018-10-04 11:45:53 +0200122static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
123static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
124static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +0300125static void intel_modeset_setup_hw_state(struct drm_device *dev,
126 struct drm_modeset_acquire_ctx *ctx);
Ville Syrjälä2622a082016-03-09 19:07:26 +0200127static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
Damien Lespiaue7457a92013-08-08 22:28:59 +0100128
Ma Lingd4906092009-03-18 20:13:27 +0800129struct intel_limit {
Ander Conselvan de Oliveira4c5def92016-05-04 12:11:58 +0300130 struct {
131 int min, max;
132 } dot, vco, n, m, m1, m2, p, p1;
133
134 struct {
135 int dot_limit;
136 int p2_slow, p2_fast;
137 } p2;
Ma Lingd4906092009-03-18 20:13:27 +0800138};
Jesse Barnes79e53942008-11-07 14:24:08 -0800139
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300140/* returns HPLL frequency in kHz */
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200141int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300142{
143 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
144
145 /* Obtain SKU information */
146 mutex_lock(&dev_priv->sb_lock);
147 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
148 CCK_FUSE_HPLL_FREQ_MASK;
149 mutex_unlock(&dev_priv->sb_lock);
150
151 return vco_freq[hpll_freq] * 1000;
152}
153
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200154int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
155 const char *name, u32 reg, int ref_freq)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300156{
157 u32 val;
158 int divider;
159
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300160 mutex_lock(&dev_priv->sb_lock);
161 val = vlv_cck_read(dev_priv, reg);
162 mutex_unlock(&dev_priv->sb_lock);
163
164 divider = val & CCK_FREQUENCY_VALUES;
165
166 WARN((val & CCK_FREQUENCY_STATUS) !=
167 (divider << CCK_FREQUENCY_STATUS_SHIFT),
168 "%s change in progress\n", name);
169
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200170 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
171}
172
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +0200173int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
174 const char *name, u32 reg)
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200175{
176 if (dev_priv->hpll_freq == 0)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200177 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200178
179 return vlv_get_cck_clock(dev_priv, name, reg,
180 dev_priv->hpll_freq);
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300181}
182
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300183static void intel_update_czclk(struct drm_i915_private *dev_priv)
184{
Wayne Boyer666a4532015-12-09 12:29:35 -0800185 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300186 return;
187
188 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
189 CCK_CZ_CLOCK_CONTROL);
190
191 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
192}
193
Chris Wilson021357a2010-09-07 20:54:59 +0100194static inline u32 /* units of 100MHz */
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200195intel_fdi_link_freq(struct drm_i915_private *dev_priv,
196 const struct intel_crtc_state *pipe_config)
Chris Wilson021357a2010-09-07 20:54:59 +0100197{
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200198 if (HAS_DDI(dev_priv))
199 return pipe_config->port_clock; /* SPLL */
Ville Syrjäläe3b247d2016-02-17 21:41:09 +0200200 else
Chris Wilson58ecd9d2017-11-05 13:49:05 +0000201 return dev_priv->fdi_pll_freq;
Chris Wilson021357a2010-09-07 20:54:59 +0100202}
203
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300204static const struct intel_limit intel_limits_i8xx_dac = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400205 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200206 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200207 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400208 .m = { .min = 96, .max = 140 },
209 .m1 = { .min = 18, .max = 26 },
210 .m2 = { .min = 6, .max = 16 },
211 .p = { .min = 4, .max = 128 },
212 .p1 = { .min = 2, .max = 33 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700213 .p2 = { .dot_limit = 165000,
214 .p2_slow = 4, .p2_fast = 2 },
Keith Packarde4b36692009-06-05 19:22:17 -0700215};
216
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300217static const struct intel_limit intel_limits_i8xx_dvo = {
Daniel Vetter5d536e22013-07-06 12:52:06 +0200218 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200219 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200220 .n = { .min = 2, .max = 16 },
Daniel Vetter5d536e22013-07-06 12:52:06 +0200221 .m = { .min = 96, .max = 140 },
222 .m1 = { .min = 18, .max = 26 },
223 .m2 = { .min = 6, .max = 16 },
224 .p = { .min = 4, .max = 128 },
225 .p1 = { .min = 2, .max = 33 },
226 .p2 = { .dot_limit = 165000,
227 .p2_slow = 4, .p2_fast = 4 },
228};
229
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300230static const struct intel_limit intel_limits_i8xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400231 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200232 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200233 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400234 .m = { .min = 96, .max = 140 },
235 .m1 = { .min = 18, .max = 26 },
236 .m2 = { .min = 6, .max = 16 },
237 .p = { .min = 4, .max = 128 },
238 .p1 = { .min = 1, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700239 .p2 = { .dot_limit = 165000,
240 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700241};
Eric Anholt273e27c2011-03-30 13:01:10 -0700242
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300243static const struct intel_limit intel_limits_i9xx_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400244 .dot = { .min = 20000, .max = 400000 },
245 .vco = { .min = 1400000, .max = 2800000 },
246 .n = { .min = 1, .max = 6 },
247 .m = { .min = 70, .max = 120 },
Patrik Jakobsson4f7dfb62013-02-13 22:20:22 +0100248 .m1 = { .min = 8, .max = 18 },
249 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400250 .p = { .min = 5, .max = 80 },
251 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700252 .p2 = { .dot_limit = 200000,
253 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700254};
255
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300256static const struct intel_limit intel_limits_i9xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400257 .dot = { .min = 20000, .max = 400000 },
258 .vco = { .min = 1400000, .max = 2800000 },
259 .n = { .min = 1, .max = 6 },
260 .m = { .min = 70, .max = 120 },
Patrik Jakobsson53a7d2d2013-02-13 22:20:21 +0100261 .m1 = { .min = 8, .max = 18 },
262 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400263 .p = { .min = 7, .max = 98 },
264 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700265 .p2 = { .dot_limit = 112000,
266 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700267};
268
Eric Anholt273e27c2011-03-30 13:01:10 -0700269
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300270static const struct intel_limit intel_limits_g4x_sdvo = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700271 .dot = { .min = 25000, .max = 270000 },
272 .vco = { .min = 1750000, .max = 3500000},
273 .n = { .min = 1, .max = 4 },
274 .m = { .min = 104, .max = 138 },
275 .m1 = { .min = 17, .max = 23 },
276 .m2 = { .min = 5, .max = 11 },
277 .p = { .min = 10, .max = 30 },
278 .p1 = { .min = 1, .max = 3},
279 .p2 = { .dot_limit = 270000,
280 .p2_slow = 10,
281 .p2_fast = 10
Ma Ling044c7c42009-03-18 20:13:23 +0800282 },
Keith Packarde4b36692009-06-05 19:22:17 -0700283};
284
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300285static const struct intel_limit intel_limits_g4x_hdmi = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700286 .dot = { .min = 22000, .max = 400000 },
287 .vco = { .min = 1750000, .max = 3500000},
288 .n = { .min = 1, .max = 4 },
289 .m = { .min = 104, .max = 138 },
290 .m1 = { .min = 16, .max = 23 },
291 .m2 = { .min = 5, .max = 11 },
292 .p = { .min = 5, .max = 80 },
293 .p1 = { .min = 1, .max = 8},
294 .p2 = { .dot_limit = 165000,
295 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700296};
297
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300298static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700299 .dot = { .min = 20000, .max = 115000 },
300 .vco = { .min = 1750000, .max = 3500000 },
301 .n = { .min = 1, .max = 3 },
302 .m = { .min = 104, .max = 138 },
303 .m1 = { .min = 17, .max = 23 },
304 .m2 = { .min = 5, .max = 11 },
305 .p = { .min = 28, .max = 112 },
306 .p1 = { .min = 2, .max = 8 },
307 .p2 = { .dot_limit = 0,
308 .p2_slow = 14, .p2_fast = 14
Ma Ling044c7c42009-03-18 20:13:23 +0800309 },
Keith Packarde4b36692009-06-05 19:22:17 -0700310};
311
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300312static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700313 .dot = { .min = 80000, .max = 224000 },
314 .vco = { .min = 1750000, .max = 3500000 },
315 .n = { .min = 1, .max = 3 },
316 .m = { .min = 104, .max = 138 },
317 .m1 = { .min = 17, .max = 23 },
318 .m2 = { .min = 5, .max = 11 },
319 .p = { .min = 14, .max = 42 },
320 .p1 = { .min = 2, .max = 6 },
321 .p2 = { .dot_limit = 0,
322 .p2_slow = 7, .p2_fast = 7
Ma Ling044c7c42009-03-18 20:13:23 +0800323 },
Keith Packarde4b36692009-06-05 19:22:17 -0700324};
325
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300326static const struct intel_limit intel_limits_pineview_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400327 .dot = { .min = 20000, .max = 400000},
328 .vco = { .min = 1700000, .max = 3500000 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700329 /* Pineview's Ncounter is a ring counter */
Akshay Joshi0206e352011-08-16 15:34:10 -0400330 .n = { .min = 3, .max = 6 },
331 .m = { .min = 2, .max = 256 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700332 /* Pineview only has one combined m divider, which we treat as m2. */
Akshay Joshi0206e352011-08-16 15:34:10 -0400333 .m1 = { .min = 0, .max = 0 },
334 .m2 = { .min = 0, .max = 254 },
335 .p = { .min = 5, .max = 80 },
336 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700337 .p2 = { .dot_limit = 200000,
338 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700339};
340
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300341static const struct intel_limit intel_limits_pineview_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400342 .dot = { .min = 20000, .max = 400000 },
343 .vco = { .min = 1700000, .max = 3500000 },
344 .n = { .min = 3, .max = 6 },
345 .m = { .min = 2, .max = 256 },
346 .m1 = { .min = 0, .max = 0 },
347 .m2 = { .min = 0, .max = 254 },
348 .p = { .min = 7, .max = 112 },
349 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700350 .p2 = { .dot_limit = 112000,
351 .p2_slow = 14, .p2_fast = 14 },
Keith Packarde4b36692009-06-05 19:22:17 -0700352};
353
Eric Anholt273e27c2011-03-30 13:01:10 -0700354/* Ironlake / Sandybridge
355 *
356 * We calculate clock using (register_value + 2) for N/M1/M2, so here
357 * the range value for them is (actual_value - 2).
358 */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300359static const struct intel_limit intel_limits_ironlake_dac = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700360 .dot = { .min = 25000, .max = 350000 },
361 .vco = { .min = 1760000, .max = 3510000 },
362 .n = { .min = 1, .max = 5 },
363 .m = { .min = 79, .max = 127 },
364 .m1 = { .min = 12, .max = 22 },
365 .m2 = { .min = 5, .max = 9 },
366 .p = { .min = 5, .max = 80 },
367 .p1 = { .min = 1, .max = 8 },
368 .p2 = { .dot_limit = 225000,
369 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700370};
371
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300372static const struct intel_limit intel_limits_ironlake_single_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700373 .dot = { .min = 25000, .max = 350000 },
374 .vco = { .min = 1760000, .max = 3510000 },
375 .n = { .min = 1, .max = 3 },
376 .m = { .min = 79, .max = 118 },
377 .m1 = { .min = 12, .max = 22 },
378 .m2 = { .min = 5, .max = 9 },
379 .p = { .min = 28, .max = 112 },
380 .p1 = { .min = 2, .max = 8 },
381 .p2 = { .dot_limit = 225000,
382 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800383};
384
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300385static const struct intel_limit intel_limits_ironlake_dual_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700386 .dot = { .min = 25000, .max = 350000 },
387 .vco = { .min = 1760000, .max = 3510000 },
388 .n = { .min = 1, .max = 3 },
389 .m = { .min = 79, .max = 127 },
390 .m1 = { .min = 12, .max = 22 },
391 .m2 = { .min = 5, .max = 9 },
392 .p = { .min = 14, .max = 56 },
393 .p1 = { .min = 2, .max = 8 },
394 .p2 = { .dot_limit = 225000,
395 .p2_slow = 7, .p2_fast = 7 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800396};
397
Eric Anholt273e27c2011-03-30 13:01:10 -0700398/* LVDS 100mhz refclk limits. */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300399static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700400 .dot = { .min = 25000, .max = 350000 },
401 .vco = { .min = 1760000, .max = 3510000 },
402 .n = { .min = 1, .max = 2 },
403 .m = { .min = 79, .max = 126 },
404 .m1 = { .min = 12, .max = 22 },
405 .m2 = { .min = 5, .max = 9 },
406 .p = { .min = 28, .max = 112 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400407 .p1 = { .min = 2, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700408 .p2 = { .dot_limit = 225000,
409 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800410};
411
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300412static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700413 .dot = { .min = 25000, .max = 350000 },
414 .vco = { .min = 1760000, .max = 3510000 },
415 .n = { .min = 1, .max = 3 },
416 .m = { .min = 79, .max = 126 },
417 .m1 = { .min = 12, .max = 22 },
418 .m2 = { .min = 5, .max = 9 },
419 .p = { .min = 14, .max = 42 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400420 .p1 = { .min = 2, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700421 .p2 = { .dot_limit = 225000,
422 .p2_slow = 7, .p2_fast = 7 },
Zhao Yakui45476682009-12-31 16:06:04 +0800423};
424
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300425static const struct intel_limit intel_limits_vlv = {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300426 /*
427 * These are the data rate limits (measured in fast clocks)
428 * since those are the strictest limits we have. The fast
429 * clock and actual rate limits are more relaxed, so checking
430 * them would make no difference.
431 */
432 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
Daniel Vetter75e53982013-04-18 21:10:43 +0200433 .vco = { .min = 4000000, .max = 6000000 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700434 .n = { .min = 1, .max = 7 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700435 .m1 = { .min = 2, .max = 3 },
436 .m2 = { .min = 11, .max = 156 },
Ville Syrjäläb99ab662013-09-24 21:26:26 +0300437 .p1 = { .min = 2, .max = 3 },
Ville Syrjälä5fdc9c492013-09-24 21:26:29 +0300438 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700439};
440
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300441static const struct intel_limit intel_limits_chv = {
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300442 /*
443 * These are the data rate limits (measured in fast clocks)
444 * since those are the strictest limits we have. The fast
445 * clock and actual rate limits are more relaxed, so checking
446 * them would make no difference.
447 */
448 .dot = { .min = 25000 * 5, .max = 540000 * 5},
Ville Syrjälä17fe1022015-02-26 21:01:52 +0200449 .vco = { .min = 4800000, .max = 6480000 },
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 .m2 = { .min = 24 << 22, .max = 175 << 22 },
453 .p1 = { .min = 2, .max = 4 },
454 .p2 = { .p2_slow = 1, .p2_fast = 14 },
455};
456
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300457static const struct intel_limit intel_limits_bxt = {
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200458 /* FIXME: find real dot limits */
459 .dot = { .min = 0, .max = INT_MAX },
Vandana Kannane6292552015-07-01 17:02:57 +0530460 .vco = { .min = 4800000, .max = 6700000 },
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200461 .n = { .min = 1, .max = 1 },
462 .m1 = { .min = 2, .max = 2 },
463 /* FIXME: find real m2 limits */
464 .m2 = { .min = 2 << 22, .max = 255 << 22 },
465 .p1 = { .min = 2, .max = 4 },
466 .p2 = { .p2_slow = 1, .p2_fast = 20 },
467};
468
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530469static void
470skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
471{
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530472 if (enable)
473 I915_WRITE(CLKGATE_DIS_PSL(pipe),
474 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
475 else
476 I915_WRITE(CLKGATE_DIS_PSL(pipe),
477 I915_READ(CLKGATE_DIS_PSL(pipe)) &
478 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
479}
480
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200481static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100482needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200483{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200484 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200485}
486
Imre Deakdccbea32015-06-22 23:35:51 +0300487/*
488 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
489 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
490 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
491 * The helpers' return value is the rate of the clock that is fed to the
492 * display engine's pipe which can be the above fast dot clock rate or a
493 * divided-down version of it.
494 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500495/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300496static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800497{
Shaohua Li21778322009-02-23 15:19:16 +0800498 clock->m = clock->m2 + 2;
499 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200500 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300501 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300502 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
503 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300504
505 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800506}
507
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200508static u32 i9xx_dpll_compute_m(struct dpll *dpll)
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200509{
510 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
511}
512
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300513static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800514{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200515 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800516 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200517 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300518 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300519 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
520 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300521
522 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800523}
524
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300525static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300526{
527 clock->m = clock->m1 * clock->m2;
528 clock->p = clock->p1 * clock->p2;
529 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300530 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300531 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
532 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300533
534 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300535}
536
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300537int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300538{
539 clock->m = clock->m1 * clock->m2;
540 clock->p = clock->p1 * clock->p2;
541 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300542 return 0;
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200543 clock->vco = DIV_ROUND_CLOSEST_ULL((u64)refclk * clock->m,
544 clock->n << 22);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300545 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300546
547 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300548}
549
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800550#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000551
552/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800553 * Returns whether the given set of divisors are valid for a given refclk with
554 * the given connectors.
555 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100556static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300557 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300558 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800559{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300560 if (clock->n < limit->n.min || limit->n.max < clock->n)
561 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800562 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400563 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800564 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400565 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800566 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400567 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300568
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100569 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200570 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300571 if (clock->m1 <= clock->m2)
572 INTELPllInvalid("m1 <= m2\n");
573
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100574 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200575 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300576 if (clock->p < limit->p.min || limit->p.max < clock->p)
577 INTELPllInvalid("p out of range\n");
578 if (clock->m < limit->m.min || limit->m.max < clock->m)
579 INTELPllInvalid("m out of range\n");
580 }
581
Jesse Barnes79e53942008-11-07 14:24:08 -0800582 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400583 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800584 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
585 * connector, etc., rather than just a single range.
586 */
587 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400588 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800589
590 return true;
591}
592
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300593static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300594i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300595 const struct intel_crtc_state *crtc_state,
596 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800597{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300598 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800599
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300600 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800601 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100602 * For LVDS just rely on its current settings for dual-channel.
603 * We haven't figured out how to reliably set up different
604 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800605 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100606 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300607 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800608 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300609 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800610 } else {
611 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300612 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800613 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300614 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800615 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300616}
617
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200618/*
619 * Returns a set of divisors for the desired target clock with the given
620 * refclk, or FALSE. The returned values represent the clock equation:
621 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
622 *
623 * Target and reference clocks are specified in kHz.
624 *
625 * If match_clock is provided, then best_clock P divider must match the P
626 * divider from @match_clock used for LVDS downclocking.
627 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300628static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300629i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300630 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300631 int target, int refclk, struct dpll *match_clock,
632 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300633{
634 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300635 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300636 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800637
Akshay Joshi0206e352011-08-16 15:34:10 -0400638 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800639
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300640 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
641
Zhao Yakui42158662009-11-20 11:24:18 +0800642 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
643 clock.m1++) {
644 for (clock.m2 = limit->m2.min;
645 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200646 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800647 break;
648 for (clock.n = limit->n.min;
649 clock.n <= limit->n.max; clock.n++) {
650 for (clock.p1 = limit->p1.min;
651 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800652 int this_err;
653
Imre Deakdccbea32015-06-22 23:35:51 +0300654 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100655 if (!intel_PLL_is_valid(to_i915(dev),
656 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000657 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800658 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800659 if (match_clock &&
660 clock.p != match_clock->p)
661 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800662
663 this_err = abs(clock.dot - target);
664 if (this_err < err) {
665 *best_clock = clock;
666 err = this_err;
667 }
668 }
669 }
670 }
671 }
672
673 return (err != target);
674}
675
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200676/*
677 * Returns a set of divisors for the desired target clock with the given
678 * refclk, or FALSE. The returned values represent the clock equation:
679 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
680 *
681 * Target and reference clocks are specified in kHz.
682 *
683 * If match_clock is provided, then best_clock P divider must match the P
684 * divider from @match_clock used for LVDS downclocking.
685 */
Ma Lingd4906092009-03-18 20:13:27 +0800686static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300687pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200688 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300689 int target, int refclk, struct dpll *match_clock,
690 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200691{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300692 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300693 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200694 int err = target;
695
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200696 memset(best_clock, 0, sizeof(*best_clock));
697
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300698 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
699
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200700 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
701 clock.m1++) {
702 for (clock.m2 = limit->m2.min;
703 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200704 for (clock.n = limit->n.min;
705 clock.n <= limit->n.max; clock.n++) {
706 for (clock.p1 = limit->p1.min;
707 clock.p1 <= limit->p1.max; clock.p1++) {
708 int this_err;
709
Imre Deakdccbea32015-06-22 23:35:51 +0300710 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100711 if (!intel_PLL_is_valid(to_i915(dev),
712 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800713 &clock))
714 continue;
715 if (match_clock &&
716 clock.p != match_clock->p)
717 continue;
718
719 this_err = abs(clock.dot - target);
720 if (this_err < err) {
721 *best_clock = clock;
722 err = this_err;
723 }
724 }
725 }
726 }
727 }
728
729 return (err != target);
730}
731
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200732/*
733 * Returns a set of divisors for the desired target clock with the given
734 * refclk, or FALSE. The returned values represent the clock equation:
735 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200736 *
737 * Target and reference clocks are specified in kHz.
738 *
739 * If match_clock is provided, then best_clock P divider must match the P
740 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200741 */
Ma Lingd4906092009-03-18 20:13:27 +0800742static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300743g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200744 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300745 int target, int refclk, struct dpll *match_clock,
746 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800747{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300748 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300749 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800750 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300751 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400752 /* approximately equals target * 0.00585 */
753 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800754
755 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300756
757 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
758
Ma Lingd4906092009-03-18 20:13:27 +0800759 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200760 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800761 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200762 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800763 for (clock.m1 = limit->m1.max;
764 clock.m1 >= limit->m1.min; clock.m1--) {
765 for (clock.m2 = limit->m2.max;
766 clock.m2 >= limit->m2.min; clock.m2--) {
767 for (clock.p1 = limit->p1.max;
768 clock.p1 >= limit->p1.min; clock.p1--) {
769 int this_err;
770
Imre Deakdccbea32015-06-22 23:35:51 +0300771 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100772 if (!intel_PLL_is_valid(to_i915(dev),
773 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000774 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800775 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000776
777 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800778 if (this_err < err_most) {
779 *best_clock = clock;
780 err_most = this_err;
781 max_n = clock.n;
782 found = true;
783 }
784 }
785 }
786 }
787 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800788 return found;
789}
Ma Lingd4906092009-03-18 20:13:27 +0800790
Imre Deakd5dd62b2015-03-17 11:40:03 +0200791/*
792 * Check if the calculated PLL configuration is more optimal compared to the
793 * best configuration and error found so far. Return the calculated error.
794 */
795static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300796 const struct dpll *calculated_clock,
797 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200798 unsigned int best_error_ppm,
799 unsigned int *error_ppm)
800{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200801 /*
802 * For CHV ignore the error and consider only the P value.
803 * Prefer a bigger P value based on HW requirements.
804 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100805 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200806 *error_ppm = 0;
807
808 return calculated_clock->p > best_clock->p;
809 }
810
Imre Deak24be4e42015-03-17 11:40:04 +0200811 if (WARN_ON_ONCE(!target_freq))
812 return false;
813
Imre Deakd5dd62b2015-03-17 11:40:03 +0200814 *error_ppm = div_u64(1000000ULL *
815 abs(target_freq - calculated_clock->dot),
816 target_freq);
817 /*
818 * Prefer a better P value over a better (smaller) error if the error
819 * is small. Ensure this preference for future configurations too by
820 * setting the error to 0.
821 */
822 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
823 *error_ppm = 0;
824
825 return true;
826 }
827
828 return *error_ppm + 10 < best_error_ppm;
829}
830
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200831/*
832 * Returns a set of divisors for the desired target clock with the given
833 * refclk, or FALSE. The returned values represent the clock equation:
834 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
835 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800836static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300837vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200838 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300839 int target, int refclk, struct dpll *match_clock,
840 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700841{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200842 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300843 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300844 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300845 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300846 /* min update 19.2 MHz */
847 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300848 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700849
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300850 target *= 5; /* fast clock */
851
852 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700853
854 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300855 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300856 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300857 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300858 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300859 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700860 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300861 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200862 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300863
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300864 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
865 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300866
Imre Deakdccbea32015-06-22 23:35:51 +0300867 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300868
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100869 if (!intel_PLL_is_valid(to_i915(dev),
870 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300871 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300872 continue;
873
Imre Deakd5dd62b2015-03-17 11:40:03 +0200874 if (!vlv_PLL_is_optimal(dev, target,
875 &clock,
876 best_clock,
877 bestppm, &ppm))
878 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300879
Imre Deakd5dd62b2015-03-17 11:40:03 +0200880 *best_clock = clock;
881 bestppm = ppm;
882 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700883 }
884 }
885 }
886 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700887
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300888 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700889}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700890
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200891/*
892 * Returns a set of divisors for the desired target clock with the given
893 * refclk, or FALSE. The returned values represent the clock equation:
894 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
895 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300896static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300897chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200898 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300899 int target, int refclk, struct dpll *match_clock,
900 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300901{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200902 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300903 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200904 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300905 struct dpll clock;
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200906 u64 m2;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300907 int found = false;
908
909 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200910 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300911
912 /*
913 * Based on hardware doc, the n always set to 1, and m1 always
914 * set to 2. If requires to support 200Mhz refclk, we need to
915 * revisit this because n may not 1 anymore.
916 */
917 clock.n = 1, clock.m1 = 2;
918 target *= 5; /* fast clock */
919
920 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
921 for (clock.p2 = limit->p2.p2_fast;
922 clock.p2 >= limit->p2.p2_slow;
923 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200924 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300925
926 clock.p = clock.p1 * clock.p2;
927
Jani Nikulaba3f4d02019-01-18 14:01:23 +0200928 m2 = DIV_ROUND_CLOSEST_ULL(((u64)target * clock.p *
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300929 clock.n) << 22, refclk * clock.m1);
930
931 if (m2 > INT_MAX/clock.m1)
932 continue;
933
934 clock.m2 = m2;
935
Imre Deakdccbea32015-06-22 23:35:51 +0300936 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300937
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100938 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300939 continue;
940
Imre Deak9ca3ba02015-03-17 11:40:05 +0200941 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
942 best_error_ppm, &error_ppm))
943 continue;
944
945 *best_clock = clock;
946 best_error_ppm = error_ppm;
947 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300948 }
949 }
950
951 return found;
952}
953
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200954bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300955 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200956{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200957 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300958 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200959
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200960 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200961 target_clock, refclk, NULL, best_clock);
962}
963
Ville Syrjälä525b9312016-10-31 22:37:02 +0200964bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300965{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300966 /* Be paranoid as we can arrive here with only partial
967 * state retrieved from the hardware during setup.
968 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100969 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300970 * as Haswell has gained clock readout/fastboot support.
971 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300972 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300973 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700974 *
975 * FIXME: The intel_crtc->active here should be switched to
976 * crtc->state->active once we have proper CRTC states wired up
977 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300978 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200979 return crtc->active && crtc->base.primary->state->fb &&
980 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300981}
982
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200983enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
984 enum pipe pipe)
985{
Ville Syrjälä98187832016-10-31 22:37:10 +0200986 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200987
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200988 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200989}
990
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200991static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
992 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300993{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200994 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300995 u32 line1, line2;
996 u32 line_mask;
997
Lucas De Marchicf819ef2018-12-12 10:10:43 -0800998 if (IS_GEN(dev_priv, 2))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300999 line_mask = DSL_LINEMASK_GEN2;
1000 else
1001 line_mask = DSL_LINEMASK_GEN3;
1002
1003 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +02001004 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001005 line2 = I915_READ(reg) & line_mask;
1006
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001007 return line1 != line2;
1008}
1009
1010static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1011{
1012 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1013 enum pipe pipe = crtc->pipe;
1014
1015 /* Wait for the display line to settle/start moving */
1016 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1017 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1018 pipe_name(pipe), onoff(state));
1019}
1020
1021static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1022{
1023 wait_for_pipe_scanline_moving(crtc, false);
1024}
1025
1026static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1027{
1028 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001029}
1030
Ville Syrjälä4972f702017-11-29 17:37:32 +02001031static void
1032intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001033{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001034 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001036
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001037 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001038 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001039 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001040
Keith Packardab7ad7f2010-10-03 00:33:06 -07001041 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001042 if (intel_wait_for_register(dev_priv,
1043 reg, I965_PIPECONF_ACTIVE, 0,
1044 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001045 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001046 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001047 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001048 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001049}
1050
Jesse Barnesb24e7172011-01-04 15:09:30 -08001051/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001052void assert_pll(struct drm_i915_private *dev_priv,
1053 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001054{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001055 u32 val;
1056 bool cur_state;
1057
Ville Syrjälä649636e2015-09-22 19:50:01 +03001058 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001059 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001060 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001061 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001062 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001063}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001064
Jani Nikula23538ef2013-08-27 15:12:22 +03001065/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001066void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001067{
1068 u32 val;
1069 bool cur_state;
1070
Ville Syrjäläa5805162015-05-26 20:42:30 +03001071 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001072 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001073 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001074
1075 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001076 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001077 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001078 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001079}
Jani Nikula23538ef2013-08-27 15:12:22 +03001080
Jesse Barnes040484a2011-01-03 12:14:26 -08001081static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1082 enum pipe pipe, bool state)
1083{
Jesse Barnes040484a2011-01-03 12:14:26 -08001084 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001085 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1086 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001087
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001088 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001089 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001090 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001091 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001092 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001093 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001094 cur_state = !!(val & FDI_TX_ENABLE);
1095 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001096 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001097 "FDI TX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001098 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001099}
1100#define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1101#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1102
1103static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1104 enum pipe pipe, bool state)
1105{
Jesse Barnes040484a2011-01-03 12:14:26 -08001106 u32 val;
1107 bool cur_state;
1108
Ville Syrjälä649636e2015-09-22 19:50:01 +03001109 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001110 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001111 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001112 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001113 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001114}
1115#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1116#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1117
1118static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1119 enum pipe pipe)
1120{
Jesse Barnes040484a2011-01-03 12:14:26 -08001121 u32 val;
1122
1123 /* ILK FDI PLL is always enabled */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001124 if (IS_GEN(dev_priv, 5))
Jesse Barnes040484a2011-01-03 12:14:26 -08001125 return;
1126
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001127 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001128 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001129 return;
1130
Ville Syrjälä649636e2015-09-22 19:50:01 +03001131 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001132 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 -08001133}
1134
Daniel Vetter55607e82013-06-16 21:42:39 +02001135void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1136 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001137{
Jesse Barnes040484a2011-01-03 12:14:26 -08001138 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001139 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001140
Ville Syrjälä649636e2015-09-22 19:50:01 +03001141 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001142 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001143 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001144 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001145 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001146}
1147
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001148void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001149{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001150 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001151 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001152 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001153 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001154
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001155 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001156 return;
1157
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001158 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001159 u32 port_sel;
1160
Imre Deak44cb7342016-08-10 14:07:29 +03001161 pp_reg = PP_CONTROL(0);
1162 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001163
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001164 switch (port_sel) {
1165 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001166 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001167 break;
1168 case PANEL_PORT_SELECT_DPA:
1169 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1170 break;
1171 case PANEL_PORT_SELECT_DPC:
1172 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1173 break;
1174 case PANEL_PORT_SELECT_DPD:
1175 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1176 break;
1177 default:
1178 MISSING_CASE(port_sel);
1179 break;
1180 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001181 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001182 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001183 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001184 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001185 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001186 u32 port_sel;
1187
Imre Deak44cb7342016-08-10 14:07:29 +03001188 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001189 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1190
1191 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001192 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001193 }
1194
1195 val = I915_READ(pp_reg);
1196 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001197 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001198 locked = false;
1199
Rob Clarke2c719b2014-12-15 13:56:32 -05001200 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001201 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001202 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001203}
1204
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001205void assert_pipe(struct drm_i915_private *dev_priv,
1206 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001207{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001208 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001209 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1210 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001211 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001212 intel_wakeref_t wakeref;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001213
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001214 /* we keep both pipes enabled on 830 */
1215 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001216 state = true;
1217
Imre Deak4feed0e2016-02-12 18:55:14 +02001218 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001219 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
1220 if (wakeref) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001221 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001222 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001223
Chris Wilson0e6e0be2019-01-14 14:21:24 +00001224 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak4feed0e2016-02-12 18:55:14 +02001225 } else {
1226 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001227 }
1228
Rob Clarke2c719b2014-12-15 13:56:32 -05001229 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001230 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001231 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001232}
1233
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001234static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001235{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001236 enum pipe pipe;
1237 bool cur_state;
1238
1239 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001240
Rob Clarke2c719b2014-12-15 13:56:32 -05001241 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001242 "%s assertion failure (expected %s, current %s)\n",
1243 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001244}
1245
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001246#define assert_plane_enabled(p) assert_plane(p, true)
1247#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001248
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001249static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001250{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001251 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1252 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001253
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001254 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1255 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001256}
1257
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001258static void assert_vblank_disabled(struct drm_crtc *crtc)
1259{
Rob Clarke2c719b2014-12-15 13:56:32 -05001260 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001261 drm_crtc_vblank_put(crtc);
1262}
1263
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001264void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1265 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001266{
Jesse Barnes92f25842011-01-04 15:09:34 -08001267 u32 val;
1268 bool enabled;
1269
Ville Syrjälä649636e2015-09-22 19:50:01 +03001270 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001271 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001272 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001273 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1274 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001275}
1276
Jesse Barnes291906f2011-02-02 12:28:03 -08001277static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001278 enum pipe pipe, enum port port,
1279 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001280{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001281 enum pipe port_pipe;
1282 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001283
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001284 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1285
1286 I915_STATE_WARN(state && port_pipe == pipe,
1287 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1288 port_name(port), pipe_name(pipe));
1289
1290 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1291 "IBX PCH DP %c still using transcoder B\n",
1292 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001293}
1294
1295static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001296 enum pipe pipe, enum port port,
1297 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001298{
Ville Syrjälä76203462018-05-14 20:24:21 +03001299 enum pipe port_pipe;
1300 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001301
Ville Syrjälä76203462018-05-14 20:24:21 +03001302 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1303
1304 I915_STATE_WARN(state && port_pipe == pipe,
1305 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1306 port_name(port), pipe_name(pipe));
1307
1308 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1309 "IBX PCH HDMI %c still using transcoder B\n",
1310 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001311}
1312
1313static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1314 enum pipe pipe)
1315{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001316 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001317
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001318 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1319 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1320 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001321
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001322 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1323 port_pipe == pipe,
1324 "PCH VGA enabled on transcoder %c, should be disabled\n",
1325 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001326
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001327 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1328 port_pipe == pipe,
1329 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1330 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001331
Ville Syrjälä3aefb672018-11-08 16:36:35 +02001332 /* PCH SDVOB multiplex with HDMIB */
Ville Syrjälä76203462018-05-14 20:24:21 +03001333 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1334 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1335 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001336}
1337
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001338static void _vlv_enable_pll(struct intel_crtc *crtc,
1339 const struct intel_crtc_state *pipe_config)
1340{
1341 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1342 enum pipe pipe = crtc->pipe;
1343
1344 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1345 POSTING_READ(DPLL(pipe));
1346 udelay(150);
1347
Chris Wilson2c30b432016-06-30 15:32:54 +01001348 if (intel_wait_for_register(dev_priv,
1349 DPLL(pipe),
1350 DPLL_LOCK_VLV,
1351 DPLL_LOCK_VLV,
1352 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001353 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1354}
1355
Ville Syrjäläd288f652014-10-28 13:20:22 +02001356static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001357 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001358{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001359 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001360 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001361
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001362 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001363
Daniel Vetter87442f72013-06-06 00:52:17 +02001364 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001365 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001366
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001367 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1368 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001369
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001370 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1371 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001372}
1373
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001374
1375static void _chv_enable_pll(struct intel_crtc *crtc,
1376 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001377{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001378 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001379 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001380 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001381 u32 tmp;
1382
Ville Syrjäläa5805162015-05-26 20:42:30 +03001383 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001384
1385 /* Enable back the 10bit clock to display controller */
1386 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1387 tmp |= DPIO_DCLKP_EN;
1388 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1389
Ville Syrjälä54433e92015-05-26 20:42:31 +03001390 mutex_unlock(&dev_priv->sb_lock);
1391
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001392 /*
1393 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1394 */
1395 udelay(1);
1396
1397 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001398 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001399
1400 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001401 if (intel_wait_for_register(dev_priv,
1402 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1403 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001404 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001405}
1406
1407static void chv_enable_pll(struct intel_crtc *crtc,
1408 const struct intel_crtc_state *pipe_config)
1409{
1410 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1411 enum pipe pipe = crtc->pipe;
1412
1413 assert_pipe_disabled(dev_priv, pipe);
1414
1415 /* PLL is protected by panel, make sure we can write it */
1416 assert_panel_unlocked(dev_priv, pipe);
1417
1418 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1419 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001420
Ville Syrjäläc2317752016-03-15 16:39:56 +02001421 if (pipe != PIPE_A) {
1422 /*
1423 * WaPixelRepeatModeFixForC0:chv
1424 *
1425 * DPLLCMD is AWOL. Use chicken bits to propagate
1426 * the value from DPLLBMD to either pipe B or C.
1427 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001428 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001429 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1430 I915_WRITE(CBR4_VLV, 0);
1431 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1432
1433 /*
1434 * DPLLB VGA mode also seems to cause problems.
1435 * We should always have it disabled.
1436 */
1437 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1438 } else {
1439 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1440 POSTING_READ(DPLL_MD(pipe));
1441 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001442}
1443
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001444static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001445{
1446 struct intel_crtc *crtc;
1447 int count = 0;
1448
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001449 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001450 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001451 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1452 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001453
1454 return count;
1455}
1456
Ville Syrjälä939994d2017-09-13 17:08:56 +03001457static void i9xx_enable_pll(struct intel_crtc *crtc,
1458 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001459{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001460 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001461 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001462 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001463 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001464
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001465 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001466
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001467 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001468 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001469 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001470
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001471 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001472 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001473 /*
1474 * It appears to be important that we don't enable this
1475 * for the current pipe before otherwise configuring the
1476 * PLL. No idea how this should be handled if multiple
1477 * DVO outputs are enabled simultaneosly.
1478 */
1479 dpll |= DPLL_DVO_2X_MODE;
1480 I915_WRITE(DPLL(!crtc->pipe),
1481 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1482 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001483
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001484 /*
1485 * Apparently we need to have VGA mode enabled prior to changing
1486 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1487 * dividers, even though the register value does change.
1488 */
1489 I915_WRITE(reg, 0);
1490
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001491 I915_WRITE(reg, dpll);
1492
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001493 /* Wait for the clocks to stabilize. */
1494 POSTING_READ(reg);
1495 udelay(150);
1496
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001497 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001498 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001499 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001500 } else {
1501 /* The pixel multiplier can only be updated once the
1502 * DPLL is enabled and the clocks are stable.
1503 *
1504 * So write it again.
1505 */
1506 I915_WRITE(reg, dpll);
1507 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001508
1509 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001510 for (i = 0; i < 3; i++) {
1511 I915_WRITE(reg, dpll);
1512 POSTING_READ(reg);
1513 udelay(150); /* wait for warmup */
1514 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001515}
1516
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001517static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001518{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001519 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001520 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001521 enum pipe pipe = crtc->pipe;
1522
1523 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001524 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001525 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001526 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001527 I915_WRITE(DPLL(PIPE_B),
1528 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1529 I915_WRITE(DPLL(PIPE_A),
1530 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1531 }
1532
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001533 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001534 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001535 return;
1536
1537 /* Make sure the pipe isn't still relying on us */
1538 assert_pipe_disabled(dev_priv, pipe);
1539
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001540 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001541 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001542}
1543
Jesse Barnesf6071162013-10-01 10:41:38 -07001544static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1545{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001546 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001547
1548 /* Make sure the pipe isn't still relying on us */
1549 assert_pipe_disabled(dev_priv, pipe);
1550
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001551 val = DPLL_INTEGRATED_REF_CLK_VLV |
1552 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1553 if (pipe != PIPE_A)
1554 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1555
Jesse Barnesf6071162013-10-01 10:41:38 -07001556 I915_WRITE(DPLL(pipe), val);
1557 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001558}
1559
1560static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1561{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001562 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001563 u32 val;
1564
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001565 /* Make sure the pipe isn't still relying on us */
1566 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001567
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001568 val = DPLL_SSC_REF_CLK_CHV |
1569 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001570 if (pipe != PIPE_A)
1571 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001572
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001573 I915_WRITE(DPLL(pipe), val);
1574 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001575
Ville Syrjäläa5805162015-05-26 20:42:30 +03001576 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001577
1578 /* Disable 10bit clock to display controller */
1579 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1580 val &= ~DPIO_DCLKP_EN;
1581 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1582
Ville Syrjäläa5805162015-05-26 20:42:30 +03001583 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001584}
1585
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001586void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001587 struct intel_digital_port *dport,
1588 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001589{
1590 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001591 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001592
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001593 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001594 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001595 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001596 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001597 break;
1598 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001599 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001600 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001601 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001602 break;
1603 case PORT_D:
1604 port_mask = DPLL_PORTD_READY_MASK;
1605 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001606 break;
1607 default:
1608 BUG();
1609 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001610
Chris Wilson370004d2016-06-30 15:32:56 +01001611 if (intel_wait_for_register(dev_priv,
1612 dpll_reg, port_mask, expected_mask,
1613 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001614 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 +02001615 port_name(dport->base.port),
1616 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001617}
1618
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001619static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001620{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001621 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1623 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001624 i915_reg_t reg;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02001625 u32 val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001626
Jesse Barnes040484a2011-01-03 12:14:26 -08001627 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001628 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001629
1630 /* FDI must be feeding us bits for PCH ports */
1631 assert_fdi_tx_enabled(dev_priv, pipe);
1632 assert_fdi_rx_enabled(dev_priv, pipe);
1633
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001634 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001635 /* Workaround: Set the timing override bit before enabling the
1636 * pch transcoder. */
1637 reg = TRANS_CHICKEN2(pipe);
1638 val = I915_READ(reg);
1639 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1640 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001641 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001642
Daniel Vetterab9412b2013-05-03 11:49:46 +02001643 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001644 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001645 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001646
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001647 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001648 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001649 * Make the BPC in transcoder be consistent with
1650 * that in pipeconf reg. For HDMI we must use 8bpc
1651 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001652 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001653 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001654 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001655 val |= PIPECONF_8BPC;
1656 else
1657 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001658 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001659
1660 val &= ~TRANS_INTERLACE_MASK;
1661 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001662 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001663 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001664 val |= TRANS_LEGACY_INTERLACED_ILK;
1665 else
1666 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001667 else
1668 val |= TRANS_PROGRESSIVE;
1669
Jesse Barnes040484a2011-01-03 12:14:26 -08001670 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001671 if (intel_wait_for_register(dev_priv,
1672 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1673 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001674 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001675}
1676
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001677static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001678 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001679{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001680 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001681
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001682 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001683 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001684 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001685
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001686 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001687 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001688 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001689 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001690
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001691 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001692 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001693
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001694 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1695 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001696 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001697 else
1698 val |= TRANS_PROGRESSIVE;
1699
Daniel Vetterab9412b2013-05-03 11:49:46 +02001700 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001701 if (intel_wait_for_register(dev_priv,
1702 LPT_TRANSCONF,
1703 TRANS_STATE_ENABLE,
1704 TRANS_STATE_ENABLE,
1705 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001706 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001707}
1708
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001709static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1710 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001711{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001712 i915_reg_t reg;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02001713 u32 val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001714
1715 /* FDI relies on the transcoder */
1716 assert_fdi_tx_disabled(dev_priv, pipe);
1717 assert_fdi_rx_disabled(dev_priv, pipe);
1718
Jesse Barnes291906f2011-02-02 12:28:03 -08001719 /* Ports must be off as well */
1720 assert_pch_ports_disabled(dev_priv, pipe);
1721
Daniel Vetterab9412b2013-05-03 11:49:46 +02001722 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001723 val = I915_READ(reg);
1724 val &= ~TRANS_ENABLE;
1725 I915_WRITE(reg, val);
1726 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001727 if (intel_wait_for_register(dev_priv,
1728 reg, TRANS_STATE_ENABLE, 0,
1729 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001730 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001731
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001732 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001733 /* Workaround: Clear the timing override chicken bit again. */
1734 reg = TRANS_CHICKEN2(pipe);
1735 val = I915_READ(reg);
1736 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1737 I915_WRITE(reg, val);
1738 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001739}
1740
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001741void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001742{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001743 u32 val;
1744
Daniel Vetterab9412b2013-05-03 11:49:46 +02001745 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001746 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001747 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001748 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001749 if (intel_wait_for_register(dev_priv,
1750 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1751 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001752 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001753
1754 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001755 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001756 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001757 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001758}
1759
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001760enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001761{
1762 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1763
Ville Syrjälä65f21302016-10-14 20:02:53 +03001764 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001765 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001766 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001767 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001768}
1769
Ville Syrjälä32db0b62018-11-27 22:05:50 +02001770static u32 intel_crtc_max_vblank_count(const struct intel_crtc_state *crtc_state)
1771{
1772 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
1773
1774 /*
1775 * On i965gm the hardware frame counter reads
1776 * zero when the TV encoder is enabled :(
1777 */
1778 if (IS_I965GM(dev_priv) &&
1779 (crtc_state->output_types & BIT(INTEL_OUTPUT_TVOUT)))
1780 return 0;
1781
1782 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
1783 return 0xffffffff; /* full 32 bit counter */
1784 else if (INTEL_GEN(dev_priv) >= 3)
1785 return 0xffffff; /* only 24 bits of frame count */
1786 else
1787 return 0; /* Gen2 doesn't have a hardware frame counter */
1788}
1789
1790static void intel_crtc_vblank_on(const struct intel_crtc_state *crtc_state)
1791{
1792 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1793
1794 drm_crtc_set_max_vblank_count(&crtc->base,
1795 intel_crtc_max_vblank_count(crtc_state));
1796 drm_crtc_vblank_on(&crtc->base);
1797}
1798
Ville Syrjälä4972f702017-11-29 17:37:32 +02001799static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001800{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001801 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1802 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1803 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001804 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001805 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001806 u32 val;
1807
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001808 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1809
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001810 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001811
Jesse Barnesb24e7172011-01-04 15:09:30 -08001812 /*
1813 * A pipe without a PLL won't actually be able to drive bits from
1814 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1815 * need the check.
1816 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08001817 if (HAS_GMCH(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001818 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001819 assert_dsi_pll_enabled(dev_priv);
1820 else
1821 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001822 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001823 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001824 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001825 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001826 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001827 assert_fdi_tx_pll_enabled(dev_priv,
1828 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001829 }
1830 /* FIXME: assert CPU port conditions for SNB+ */
1831 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001832
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001833 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001834 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001835 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001836 /* we keep both pipes enabled on 830 */
1837 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001838 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001839 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001840
1841 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001842 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001843
1844 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001845 * Until the pipe starts PIPEDSL reads will return a stale value,
1846 * which causes an apparent vblank timestamp jump when PIPEDSL
1847 * resets to its proper value. That also messes up the frame count
1848 * when it's derived from the timestamps. So let's wait for the
1849 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001850 */
Ville Syrjälä32db0b62018-11-27 22:05:50 +02001851 if (intel_crtc_max_vblank_count(new_crtc_state) == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001852 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001853}
1854
Ville Syrjälä4972f702017-11-29 17:37:32 +02001855static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001856{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001857 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001858 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001859 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001860 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001861 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001862 u32 val;
1863
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001864 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1865
Jesse Barnesb24e7172011-01-04 15:09:30 -08001866 /*
1867 * Make sure planes won't keep trying to pump pixels to us,
1868 * or we might hang the display.
1869 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001870 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001871
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001872 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001873 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001874 if ((val & PIPECONF_ENABLE) == 0)
1875 return;
1876
Ville Syrjälä67adc642014-08-15 01:21:57 +03001877 /*
1878 * Double wide has implications for planes
1879 * so best keep it disabled when not needed.
1880 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001881 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001882 val &= ~PIPECONF_DOUBLE_WIDE;
1883
1884 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001885 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001886 val &= ~PIPECONF_ENABLE;
1887
1888 I915_WRITE(reg, val);
1889 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001890 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001891}
1892
Ville Syrjälä832be822016-01-12 21:08:33 +02001893static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1894{
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001895 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
Ville Syrjälä832be822016-01-12 21:08:33 +02001896}
1897
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001898static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001899intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001900{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001901 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001902 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001903
1904 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001905 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001906 return cpp;
1907 case I915_FORMAT_MOD_X_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001908 if (IS_GEN(dev_priv, 2))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001909 return 128;
1910 else
1911 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001912 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001913 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001914 return 128;
1915 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001916 case I915_FORMAT_MOD_Y_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001917 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001918 return 128;
1919 else
1920 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001921 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001922 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001923 return 128;
1924 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001925 case I915_FORMAT_MOD_Yf_TILED:
1926 switch (cpp) {
1927 case 1:
1928 return 64;
1929 case 2:
1930 case 4:
1931 return 128;
1932 case 8:
1933 case 16:
1934 return 256;
1935 default:
1936 MISSING_CASE(cpp);
1937 return cpp;
1938 }
1939 break;
1940 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001941 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001942 return cpp;
1943 }
1944}
1945
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001946static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001947intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001948{
Ben Widawsky2f075562017-03-24 14:29:48 -07001949 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001950 return 1;
1951 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001952 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001953 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001954}
1955
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001956/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001957static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001958 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001959 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001960{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001961 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1962 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001963
1964 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001965 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001966}
1967
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001968unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001969intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001970 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001971{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001972 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001973
1974 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001975}
1976
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001977unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1978{
1979 unsigned int size = 0;
1980 int i;
1981
1982 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1983 size += rot_info->plane[i].width * rot_info->plane[i].height;
1984
1985 return size;
1986}
1987
Daniel Vetter75c82a52015-10-14 16:51:04 +02001988static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001989intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1990 const struct drm_framebuffer *fb,
1991 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001992{
Chris Wilson7b92c042017-01-14 00:28:26 +00001993 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001994 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001995 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001996 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001997 }
1998}
1999
Ville Syrjäläfabac482017-03-27 21:55:43 +03002000static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
2001{
2002 if (IS_I830(dev_priv))
2003 return 16 * 1024;
2004 else if (IS_I85X(dev_priv))
2005 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03002006 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
2007 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03002008 else
2009 return 4 * 1024;
2010}
2011
Ville Syrjälä603525d2016-01-12 21:08:37 +02002012static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002013{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00002014 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002015 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02002016 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08002017 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002018 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00002019 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002020 return 4 * 1024;
2021 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03002022 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002023}
2024
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002025static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002026 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02002027{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002028 struct drm_i915_private *dev_priv = to_i915(fb->dev);
2029
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002030 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002031 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02002032 return 4096;
2033
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002034 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002035 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002036 return intel_linear_alignment(dev_priv);
2037 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002038 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02002039 return 256 * 1024;
2040 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002041 case I915_FORMAT_MOD_Y_TILED_CCS:
2042 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002043 case I915_FORMAT_MOD_Y_TILED:
2044 case I915_FORMAT_MOD_Yf_TILED:
2045 return 1 * 1024 * 1024;
2046 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002047 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002048 return 0;
2049 }
2050}
2051
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002052static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2053{
2054 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2055 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2056
Ville Syrjälä32febd92018-02-21 18:02:33 +02002057 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002058}
2059
Chris Wilson058d88c2016-08-15 10:49:06 +01002060struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002061intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002062 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002063 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002064 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002065{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002066 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002067 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002068 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson1d264d92019-01-14 14:21:19 +00002069 intel_wakeref_t wakeref;
Chris Wilson058d88c2016-08-15 10:49:06 +01002070 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002071 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002072 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002073
Matt Roperebcdd392014-07-09 16:22:11 -07002074 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2075
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002076 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002077
Chris Wilson693db182013-03-05 14:52:39 +00002078 /* Note that the w/a also requires 64 PTE of padding following the
2079 * bo. We currently fill all unused PTE with the shadow page and so
2080 * we should always have valid PTE following the scanout preventing
2081 * the VT-d warning.
2082 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002083 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002084 alignment = 256 * 1024;
2085
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002086 /*
2087 * Global gtt pte registers are special registers which actually forward
2088 * writes to a chunk of system memory. Which means that there is no risk
2089 * that the register values disappear as soon as we call
2090 * intel_runtime_pm_put(), so it is correct to wrap only the
2091 * pin/unpin/fence and not more.
2092 */
Chris Wilson1d264d92019-01-14 14:21:19 +00002093 wakeref = intel_runtime_pm_get(dev_priv);
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002094
Daniel Vetter9db529a2017-08-08 10:08:28 +02002095 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2096
Chris Wilson59354852018-02-20 13:42:06 +00002097 pinctl = 0;
2098
2099 /* Valleyview is definitely limited to scanning out the first
2100 * 512MiB. Lets presume this behaviour was inherited from the
2101 * g4x display engine and that all earlier gen are similarly
2102 * limited. Testing suggests that it is a little more
2103 * complicated than this. For example, Cherryview appears quite
2104 * happy to scanout from anywhere within its global aperture.
2105 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08002106 if (HAS_GMCH(dev_priv))
Chris Wilson59354852018-02-20 13:42:06 +00002107 pinctl |= PIN_MAPPABLE;
2108
2109 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002110 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002111 if (IS_ERR(vma))
2112 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002113
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002114 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002115 int ret;
2116
Chris Wilson49ef5292016-08-18 17:17:00 +01002117 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2118 * fence, whereas 965+ only requires a fence if using
2119 * framebuffer compression. For simplicity, we always, when
2120 * possible, install a fence as the cost is not that onerous.
2121 *
2122 * If we fail to fence the tiled scanout, then either the
2123 * modeset will reject the change (which is highly unlikely as
2124 * the affected systems, all but one, do not have unmappable
2125 * space) or we will not be able to enable full powersaving
2126 * techniques (also likely not to apply due to various limits
2127 * FBC and the like impose on the size of the buffer, which
2128 * presumably we violated anyway with this unmappable buffer).
2129 * Anyway, it is presumably better to stumble onwards with
2130 * something and try to run the system in a "less than optimal"
2131 * mode that matches the user configuration.
2132 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002133 ret = i915_vma_pin_fence(vma);
2134 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002135 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002136 vma = ERR_PTR(ret);
2137 goto err;
2138 }
2139
2140 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002141 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002142 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002143
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002144 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002145err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002146 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2147
Chris Wilson1d264d92019-01-14 14:21:19 +00002148 intel_runtime_pm_put(dev_priv, wakeref);
Chris Wilson058d88c2016-08-15 10:49:06 +01002149 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002150}
2151
Chris Wilson59354852018-02-20 13:42:06 +00002152void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002153{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002154 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002155
Chris Wilson59354852018-02-20 13:42:06 +00002156 if (flags & PLANE_HAS_FENCE)
2157 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002158 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002159 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002160}
2161
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002162static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002163 unsigned int rotation)
2164{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002165 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002166 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002167 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002168 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002169}
2170
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002171/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002172 * Convert the x/y offsets into a linear offset.
2173 * Only valid with 0/180 degree rotation, which is fine since linear
2174 * offset is only used with linear buffers on pre-hsw and tiled buffers
2175 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2176 */
2177u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002178 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002179 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002180{
Ville Syrjälä29490562016-01-20 18:02:50 +02002181 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002182 unsigned int cpp = fb->format->cpp[color_plane];
2183 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002184
2185 return y * pitch + x * cpp;
2186}
2187
2188/*
2189 * Add the x/y offsets derived from fb->offsets[] to the user
2190 * specified plane src x/y offsets. The resulting x/y offsets
2191 * specify the start of scanout from the beginning of the gtt mapping.
2192 */
2193void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002194 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002195 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002196
2197{
Ville Syrjälä29490562016-01-20 18:02:50 +02002198 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2199 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002200
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002201 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002202 *x += intel_fb->rotated[color_plane].x;
2203 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002204 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002205 *x += intel_fb->normal[color_plane].x;
2206 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002207 }
2208}
2209
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002210static u32 intel_adjust_tile_offset(int *x, int *y,
2211 unsigned int tile_width,
2212 unsigned int tile_height,
2213 unsigned int tile_size,
2214 unsigned int pitch_tiles,
2215 u32 old_offset,
2216 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002217{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002218 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002219 unsigned int tiles;
2220
2221 WARN_ON(old_offset & (tile_size - 1));
2222 WARN_ON(new_offset & (tile_size - 1));
2223 WARN_ON(new_offset > old_offset);
2224
2225 tiles = (old_offset - new_offset) / tile_size;
2226
2227 *y += tiles / pitch_tiles * tile_height;
2228 *x += tiles % pitch_tiles * tile_width;
2229
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002230 /* minimize x in case it got needlessly big */
2231 *y += *x / pitch_pixels * tile_height;
2232 *x %= pitch_pixels;
2233
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002234 return new_offset;
2235}
2236
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002237static bool is_surface_linear(u64 modifier, int color_plane)
2238{
2239 return modifier == DRM_FORMAT_MOD_LINEAR;
2240}
2241
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002242static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002243 const struct drm_framebuffer *fb,
2244 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002245 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002246 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002247 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002248{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002249 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002250 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002251
2252 WARN_ON(new_offset > old_offset);
2253
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002254 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002255 unsigned int tile_size, tile_width, tile_height;
2256 unsigned int pitch_tiles;
2257
2258 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002259 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002260
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002261 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002262 pitch_tiles = pitch / tile_height;
2263 swap(tile_width, tile_height);
2264 } else {
2265 pitch_tiles = pitch / (tile_width * cpp);
2266 }
2267
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002268 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2269 tile_size, pitch_tiles,
2270 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002271 } else {
2272 old_offset += *y * pitch + *x * cpp;
2273
2274 *y = (old_offset - new_offset) / pitch;
2275 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2276 }
2277
2278 return new_offset;
2279}
2280
2281/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002282 * Adjust the tile offset by moving the difference into
2283 * the x/y offsets.
2284 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002285static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2286 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002287 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002288 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002289{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002290 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002291 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002292 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002293 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002294}
2295
2296/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002297 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002298 * x, y. bytes per pixel is assumed to be a power-of-two.
2299 *
2300 * In the 90/270 rotated case, x and y are assumed
2301 * to be already rotated to match the rotated GTT view, and
2302 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002303 *
2304 * This function is used when computing the derived information
2305 * under intel_framebuffer, so using any of that information
2306 * here is not allowed. Anything under drm_framebuffer can be
2307 * used. This is why the user has to pass in the pitch since it
2308 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002309 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002310static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2311 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002312 const struct drm_framebuffer *fb,
2313 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002314 unsigned int pitch,
2315 unsigned int rotation,
2316 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002317{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002318 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002319 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002320
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002321 if (alignment)
2322 alignment--;
2323
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002324 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002325 unsigned int tile_size, tile_width, tile_height;
2326 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002327
Ville Syrjäläd8433102016-01-12 21:08:35 +02002328 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002329 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002330
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002331 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002332 pitch_tiles = pitch / tile_height;
2333 swap(tile_width, tile_height);
2334 } else {
2335 pitch_tiles = pitch / (tile_width * cpp);
2336 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002337
Ville Syrjäläd8433102016-01-12 21:08:35 +02002338 tile_rows = *y / tile_height;
2339 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002340
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002341 tiles = *x / tile_width;
2342 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002343
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002344 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2345 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002346
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002347 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2348 tile_size, pitch_tiles,
2349 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002350 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002351 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002352 offset_aligned = offset & ~alignment;
2353
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002354 *y = (offset & alignment) / pitch;
2355 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002356 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002357
2358 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002359}
2360
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002361static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2362 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002363 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002364{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002365 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2366 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002367 const struct drm_framebuffer *fb = state->base.fb;
2368 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002369 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002370 u32 alignment;
2371
2372 if (intel_plane->id == PLANE_CURSOR)
2373 alignment = intel_cursor_alignment(dev_priv);
2374 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002375 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002376
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002377 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002378 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002379}
2380
Ville Syrjälä303ba692017-08-24 22:10:49 +03002381/* Convert the fb->offset[] into x/y offsets */
2382static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002383 const struct drm_framebuffer *fb,
2384 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002385{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002386 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002387 unsigned int height;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002388
Ville Syrjälä303ba692017-08-24 22:10:49 +03002389 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002390 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2391 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2392 fb->offsets[color_plane], color_plane);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002393 return -EINVAL;
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002394 }
2395
2396 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2397 height = ALIGN(height, intel_tile_height(fb, color_plane));
2398
2399 /* Catch potential overflows early */
2400 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2401 fb->offsets[color_plane])) {
2402 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2403 fb->offsets[color_plane], fb->pitches[color_plane],
2404 color_plane);
2405 return -ERANGE;
2406 }
Ville Syrjälä303ba692017-08-24 22:10:49 +03002407
2408 *x = 0;
2409 *y = 0;
2410
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002411 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002412 fb, color_plane, DRM_MODE_ROTATE_0,
2413 fb->pitches[color_plane],
2414 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002415
2416 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002417}
2418
Jani Nikulaba3f4d02019-01-18 14:01:23 +02002419static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier)
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002420{
2421 switch (fb_modifier) {
2422 case I915_FORMAT_MOD_X_TILED:
2423 return I915_TILING_X;
2424 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002425 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002426 return I915_TILING_Y;
2427 default:
2428 return I915_TILING_NONE;
2429 }
2430}
2431
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002432/*
2433 * From the Sky Lake PRM:
2434 * "The Color Control Surface (CCS) contains the compression status of
2435 * the cache-line pairs. The compression state of the cache-line pair
2436 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2437 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2438 * cache-line-pairs. CCS is always Y tiled."
2439 *
2440 * Since cache line pairs refers to horizontally adjacent cache lines,
2441 * each cache line in the CCS corresponds to an area of 32x16 cache
2442 * lines on the main surface. Since each pixel is 4 bytes, this gives
2443 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2444 * main surface.
2445 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002446static const struct drm_format_info ccs_formats[] = {
2447 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2448 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2449 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2450 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2451};
2452
2453static const struct drm_format_info *
2454lookup_format_info(const struct drm_format_info formats[],
2455 int num_formats, u32 format)
2456{
2457 int i;
2458
2459 for (i = 0; i < num_formats; i++) {
2460 if (formats[i].format == format)
2461 return &formats[i];
2462 }
2463
2464 return NULL;
2465}
2466
2467static const struct drm_format_info *
2468intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2469{
2470 switch (cmd->modifier[0]) {
2471 case I915_FORMAT_MOD_Y_TILED_CCS:
2472 case I915_FORMAT_MOD_Yf_TILED_CCS:
2473 return lookup_format_info(ccs_formats,
2474 ARRAY_SIZE(ccs_formats),
2475 cmd->pixel_format);
2476 default:
2477 return NULL;
2478 }
2479}
2480
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002481bool is_ccs_modifier(u64 modifier)
2482{
2483 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2484 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2485}
2486
Ville Syrjälä6687c902015-09-15 13:16:41 +03002487static int
2488intel_fill_fb_info(struct drm_i915_private *dev_priv,
2489 struct drm_framebuffer *fb)
2490{
2491 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2492 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002493 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002494 u32 gtt_offset_rotated = 0;
2495 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002496 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002497 unsigned int tile_size = intel_tile_size(dev_priv);
2498
2499 for (i = 0; i < num_planes; i++) {
2500 unsigned int width, height;
2501 unsigned int cpp, size;
2502 u32 offset;
2503 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002504 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002505
Ville Syrjälä353c8592016-12-14 23:30:57 +02002506 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002507 width = drm_framebuffer_plane_width(fb->width, fb, i);
2508 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002509
Ville Syrjälä303ba692017-08-24 22:10:49 +03002510 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2511 if (ret) {
2512 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2513 i, fb->offsets[i]);
2514 return ret;
2515 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002516
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002517 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002518 int hsub = fb->format->hsub;
2519 int vsub = fb->format->vsub;
2520 int tile_width, tile_height;
2521 int main_x, main_y;
2522 int ccs_x, ccs_y;
2523
2524 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002525 tile_width *= hsub;
2526 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002527
Ville Syrjälä303ba692017-08-24 22:10:49 +03002528 ccs_x = (x * hsub) % tile_width;
2529 ccs_y = (y * vsub) % tile_height;
2530 main_x = intel_fb->normal[0].x % tile_width;
2531 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002532
2533 /*
2534 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2535 * x/y offsets must match between CCS and the main surface.
2536 */
2537 if (main_x != ccs_x || main_y != ccs_y) {
2538 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2539 main_x, main_y,
2540 ccs_x, ccs_y,
2541 intel_fb->normal[0].x,
2542 intel_fb->normal[0].y,
2543 x, y);
2544 return -EINVAL;
2545 }
2546 }
2547
Ville Syrjälä6687c902015-09-15 13:16:41 +03002548 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002549 * The fence (if used) is aligned to the start of the object
2550 * so having the framebuffer wrap around across the edge of the
2551 * fenced region doesn't really work. We have no API to configure
2552 * the fence start offset within the object (nor could we probably
2553 * on gen2/3). So it's just easier if we just require that the
2554 * fb layout agrees with the fence layout. We already check that the
2555 * fb stride matches the fence stride elsewhere.
2556 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002557 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002558 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002559 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2560 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002561 return -EINVAL;
2562 }
2563
2564 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002565 * First pixel of the framebuffer from
2566 * the start of the normal gtt mapping.
2567 */
2568 intel_fb->normal[i].x = x;
2569 intel_fb->normal[i].y = y;
2570
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002571 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2572 fb->pitches[i],
2573 DRM_MODE_ROTATE_0,
2574 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002575 offset /= tile_size;
2576
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002577 if (!is_surface_linear(fb->modifier, i)) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002578 unsigned int tile_width, tile_height;
2579 unsigned int pitch_tiles;
2580 struct drm_rect r;
2581
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002582 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002583
2584 rot_info->plane[i].offset = offset;
2585 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2586 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2587 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2588
2589 intel_fb->rotated[i].pitch =
2590 rot_info->plane[i].height * tile_height;
2591
2592 /* how many tiles does this plane need */
2593 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2594 /*
2595 * If the plane isn't horizontally tile aligned,
2596 * we need one more tile.
2597 */
2598 if (x != 0)
2599 size++;
2600
2601 /* rotate the x/y offsets to match the GTT view */
2602 r.x1 = x;
2603 r.y1 = y;
2604 r.x2 = x + width;
2605 r.y2 = y + height;
2606 drm_rect_rotate(&r,
2607 rot_info->plane[i].width * tile_width,
2608 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002609 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002610 x = r.x1;
2611 y = r.y1;
2612
2613 /* rotate the tile dimensions to match the GTT view */
2614 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2615 swap(tile_width, tile_height);
2616
2617 /*
2618 * We only keep the x/y offsets, so push all of the
2619 * gtt offset into the x/y offsets.
2620 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002621 intel_adjust_tile_offset(&x, &y,
2622 tile_width, tile_height,
2623 tile_size, pitch_tiles,
2624 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002625
2626 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2627
2628 /*
2629 * First pixel of the framebuffer from
2630 * the start of the rotated gtt mapping.
2631 */
2632 intel_fb->rotated[i].x = x;
2633 intel_fb->rotated[i].y = y;
2634 } else {
2635 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2636 x * cpp, tile_size);
2637 }
2638
2639 /* how many tiles in total needed in the bo */
2640 max_size = max(max_size, offset + size);
2641 }
2642
Ville Syrjälä4e050472018-09-12 21:04:43 +03002643 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2644 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2645 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002646 return -EINVAL;
2647 }
2648
2649 return 0;
2650}
2651
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002652static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002653{
2654 switch (format) {
2655 case DISPPLANE_8BPP:
2656 return DRM_FORMAT_C8;
2657 case DISPPLANE_BGRX555:
2658 return DRM_FORMAT_XRGB1555;
2659 case DISPPLANE_BGRX565:
2660 return DRM_FORMAT_RGB565;
2661 default:
2662 case DISPPLANE_BGRX888:
2663 return DRM_FORMAT_XRGB8888;
2664 case DISPPLANE_RGBX888:
2665 return DRM_FORMAT_XBGR8888;
2666 case DISPPLANE_BGRX101010:
2667 return DRM_FORMAT_XRGB2101010;
2668 case DISPPLANE_RGBX101010:
2669 return DRM_FORMAT_XBGR2101010;
2670 }
2671}
2672
Mahesh Kumarddf34312018-04-09 09:11:03 +05302673int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002674{
2675 switch (format) {
2676 case PLANE_CTL_FORMAT_RGB_565:
2677 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302678 case PLANE_CTL_FORMAT_NV12:
2679 return DRM_FORMAT_NV12;
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05302680 case PLANE_CTL_FORMAT_P010:
2681 return DRM_FORMAT_P010;
2682 case PLANE_CTL_FORMAT_P012:
2683 return DRM_FORMAT_P012;
2684 case PLANE_CTL_FORMAT_P016:
2685 return DRM_FORMAT_P016;
Swati Sharma296e9b12019-03-04 17:26:35 +05302686 case PLANE_CTL_FORMAT_Y210:
2687 return DRM_FORMAT_Y210;
2688 case PLANE_CTL_FORMAT_Y212:
2689 return DRM_FORMAT_Y212;
2690 case PLANE_CTL_FORMAT_Y216:
2691 return DRM_FORMAT_Y216;
2692 case PLANE_CTL_FORMAT_Y410:
2693 return DRM_FORMAT_Y410;
2694 case PLANE_CTL_FORMAT_Y412:
2695 return DRM_FORMAT_Y412;
2696 case PLANE_CTL_FORMAT_Y416:
2697 return DRM_FORMAT_Y416;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002698 default:
2699 case PLANE_CTL_FORMAT_XRGB_8888:
2700 if (rgb_order) {
2701 if (alpha)
2702 return DRM_FORMAT_ABGR8888;
2703 else
2704 return DRM_FORMAT_XBGR8888;
2705 } else {
2706 if (alpha)
2707 return DRM_FORMAT_ARGB8888;
2708 else
2709 return DRM_FORMAT_XRGB8888;
2710 }
2711 case PLANE_CTL_FORMAT_XRGB_2101010:
2712 if (rgb_order)
2713 return DRM_FORMAT_XBGR2101010;
2714 else
2715 return DRM_FORMAT_XRGB2101010;
2716 }
2717}
2718
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002719static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002720intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2721 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002722{
2723 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002724 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002725 struct drm_i915_gem_object *obj = NULL;
2726 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002727 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002728 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2729 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2730 PAGE_SIZE);
2731
2732 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002733
Chris Wilsonff2652e2014-03-10 08:07:02 +00002734 if (plane_config->size == 0)
2735 return false;
2736
Paulo Zanoni3badb492015-09-23 12:52:23 -03002737 /* If the FB is too big, just don't use it since fbdev is not very
2738 * important and we should probably use that space with FBC or other
2739 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002740 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002741 return false;
2742
Imre Deak914a4fd2018-10-16 19:00:11 +03002743 switch (fb->modifier) {
2744 case DRM_FORMAT_MOD_LINEAR:
2745 case I915_FORMAT_MOD_X_TILED:
2746 case I915_FORMAT_MOD_Y_TILED:
2747 break;
2748 default:
2749 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2750 fb->modifier);
2751 return false;
2752 }
2753
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002754 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002755 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002756 base_aligned,
2757 base_aligned,
2758 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002759 mutex_unlock(&dev->struct_mutex);
2760 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002761 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002762
Imre Deak914a4fd2018-10-16 19:00:11 +03002763 switch (plane_config->tiling) {
2764 case I915_TILING_NONE:
2765 break;
2766 case I915_TILING_X:
2767 case I915_TILING_Y:
2768 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2769 break;
2770 default:
2771 MISSING_CASE(plane_config->tiling);
2772 return false;
2773 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002774
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002775 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002776 mode_cmd.width = fb->width;
2777 mode_cmd.height = fb->height;
2778 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002779 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002780 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002781
Chris Wilson24dbf512017-02-15 10:59:18 +00002782 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002783 DRM_DEBUG_KMS("intel fb init failed\n");
2784 goto out_unref_obj;
2785 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002786
Jesse Barnes484b41d2014-03-07 08:57:55 -08002787
Daniel Vetterf6936e22015-03-26 12:17:05 +01002788 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002789 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002790
2791out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002792 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002793 return false;
2794}
2795
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002796static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002797intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2798 struct intel_plane_state *plane_state,
2799 bool visible)
2800{
2801 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2802
2803 plane_state->base.visible = visible;
2804
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002805 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002806 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002807 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002808 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002809}
2810
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002811static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2812{
2813 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2814 struct drm_plane *plane;
2815
2816 /*
2817 * Active_planes aliases if multiple "primary" or cursor planes
2818 * have been used on the same (or wrong) pipe. plane_mask uses
2819 * unique ids, hence we can use that to reconstruct active_planes.
2820 */
2821 crtc_state->active_planes = 0;
2822
2823 drm_for_each_plane_mask(plane, &dev_priv->drm,
2824 crtc_state->base.plane_mask)
2825 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2826}
2827
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002828static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2829 struct intel_plane *plane)
2830{
2831 struct intel_crtc_state *crtc_state =
2832 to_intel_crtc_state(crtc->base.state);
2833 struct intel_plane_state *plane_state =
2834 to_intel_plane_state(plane->base.state);
2835
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002836 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2837 plane->base.base.id, plane->base.name,
2838 crtc->base.base.id, crtc->base.name);
2839
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002840 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002841 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002842
2843 if (plane->id == PLANE_PRIMARY)
2844 intel_pre_disable_primary_noatomic(&crtc->base);
2845
2846 trace_intel_disable_plane(&plane->base, crtc);
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02002847 plane->disable_plane(plane, crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002848}
2849
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002850static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002851intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2852 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002853{
2854 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002855 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002856 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002857 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002858 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002859 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002860 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002861 struct intel_plane_state *intel_state =
2862 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002863 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002864
Damien Lespiau2d140302015-02-05 17:22:18 +00002865 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002866 return;
2867
Daniel Vetterf6936e22015-03-26 12:17:05 +01002868 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002869 fb = &plane_config->fb->base;
2870 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002871 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002872
Damien Lespiau2d140302015-02-05 17:22:18 +00002873 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002874
2875 /*
2876 * Failed to alloc the obj, check to see if we should share
2877 * an fb with another CRTC instead
2878 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002879 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002880 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002881
2882 if (c == &intel_crtc->base)
2883 continue;
2884
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002885 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002886 continue;
2887
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002888 state = to_intel_plane_state(c->primary->state);
2889 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002890 continue;
2891
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002892 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002893 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302894 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002895 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002896 }
2897 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002898
Matt Roper200757f2015-12-03 11:37:36 -08002899 /*
2900 * We've failed to reconstruct the BIOS FB. Current display state
2901 * indicates that the primary plane is visible, but has a NULL FB,
2902 * which will lead to problems later if we don't fix it up. The
2903 * simplest solution is to just disable the primary plane now and
2904 * pretend the BIOS never had it enabled.
2905 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002906 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002907
Daniel Vetter88595ac2015-03-26 12:42:24 +01002908 return;
2909
2910valid_fb:
Ville Syrjäläf43348a2018-11-20 15:54:50 +02002911 intel_state->base.rotation = plane_config->rotation;
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002912 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2913 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002914 intel_state->color_plane[0].stride =
2915 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2916
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002917 mutex_lock(&dev->struct_mutex);
2918 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002919 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002920 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002921 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002922 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002923 mutex_unlock(&dev->struct_mutex);
2924 if (IS_ERR(intel_state->vma)) {
2925 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2926 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2927
2928 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302929 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002930 return;
2931 }
2932
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002933 obj = intel_fb_obj(fb);
2934 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2935
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002936 plane_state->src_x = 0;
2937 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002938 plane_state->src_w = fb->width << 16;
2939 plane_state->src_h = fb->height << 16;
2940
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002941 plane_state->crtc_x = 0;
2942 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002943 plane_state->crtc_w = fb->width;
2944 plane_state->crtc_h = fb->height;
2945
Rob Clark1638d302016-11-05 11:08:08 -04002946 intel_state->base.src = drm_plane_state_src(plane_state);
2947 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002948
Chris Wilson3e510a82016-08-05 10:14:23 +01002949 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002950 dev_priv->preserve_bios_swizzle = true;
2951
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002952 plane_state->fb = fb;
2953 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002954
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002955 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2956 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002957}
2958
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002959static int skl_max_plane_width(const struct drm_framebuffer *fb,
2960 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002961 unsigned int rotation)
2962{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002963 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002964
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002965 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002966 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002967 case I915_FORMAT_MOD_X_TILED:
2968 switch (cpp) {
2969 case 8:
2970 return 4096;
2971 case 4:
2972 case 2:
2973 case 1:
2974 return 8192;
2975 default:
2976 MISSING_CASE(cpp);
2977 break;
2978 }
2979 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002980 case I915_FORMAT_MOD_Y_TILED_CCS:
2981 case I915_FORMAT_MOD_Yf_TILED_CCS:
2982 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002983 case I915_FORMAT_MOD_Y_TILED:
2984 case I915_FORMAT_MOD_Yf_TILED:
2985 switch (cpp) {
2986 case 8:
2987 return 2048;
2988 case 4:
2989 return 4096;
2990 case 2:
2991 case 1:
2992 return 8192;
2993 default:
2994 MISSING_CASE(cpp);
2995 break;
2996 }
2997 break;
2998 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002999 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003000 }
3001
3002 return 2048;
3003}
3004
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003005static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
3006 int main_x, int main_y, u32 main_offset)
3007{
3008 const struct drm_framebuffer *fb = plane_state->base.fb;
3009 int hsub = fb->format->hsub;
3010 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003011 int aux_x = plane_state->color_plane[1].x;
3012 int aux_y = plane_state->color_plane[1].y;
3013 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003014 u32 alignment = intel_surf_alignment(fb, 1);
3015
3016 while (aux_offset >= main_offset && aux_y <= main_y) {
3017 int x, y;
3018
3019 if (aux_x == main_x && aux_y == main_y)
3020 break;
3021
3022 if (aux_offset == 0)
3023 break;
3024
3025 x = aux_x / hsub;
3026 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003027 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
3028 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003029 aux_x = x * hsub + aux_x % hsub;
3030 aux_y = y * vsub + aux_y % vsub;
3031 }
3032
3033 if (aux_x != main_x || aux_y != main_y)
3034 return false;
3035
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003036 plane_state->color_plane[1].offset = aux_offset;
3037 plane_state->color_plane[1].x = aux_x;
3038 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003039
3040 return true;
3041}
3042
Ville Syrjälä73266592018-09-07 18:24:11 +03003043static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003044{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003045 const struct drm_framebuffer *fb = plane_state->base.fb;
3046 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02003047 int x = plane_state->base.src.x1 >> 16;
3048 int y = plane_state->base.src.y1 >> 16;
3049 int w = drm_rect_width(&plane_state->base.src) >> 16;
3050 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003051 int max_width = skl_max_plane_width(fb, 0, rotation);
3052 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003053 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003054
3055 if (w > max_width || h > max_height) {
3056 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
3057 w, h, max_width, max_height);
3058 return -EINVAL;
3059 }
3060
3061 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003062 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003063 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003064
3065 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02003066 * AUX surface offset is specified as the distance from the
3067 * main surface offset, and it must be non-negative. Make
3068 * sure that is what we will get.
3069 */
3070 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003071 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3072 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02003073
3074 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003075 * When using an X-tiled surface, the plane blows up
3076 * if the x offset + width exceed the stride.
3077 *
3078 * TODO: linear and Y-tiled seem fine, Yf untested,
3079 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003080 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003081 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003082
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003083 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003084 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003085 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003086 return -EINVAL;
3087 }
3088
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003089 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3090 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003091 }
3092 }
3093
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003094 /*
3095 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3096 * they match with the main surface x/y offsets.
3097 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003098 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003099 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3100 if (offset == 0)
3101 break;
3102
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003103 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3104 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003105 }
3106
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003107 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003108 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3109 return -EINVAL;
3110 }
3111 }
3112
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003113 plane_state->color_plane[0].offset = offset;
3114 plane_state->color_plane[0].x = x;
3115 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003116
3117 return 0;
3118}
3119
Ville Syrjälä8d970652016-01-28 16:30:28 +02003120static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3121{
3122 const struct drm_framebuffer *fb = plane_state->base.fb;
3123 unsigned int rotation = plane_state->base.rotation;
3124 int max_width = skl_max_plane_width(fb, 1, rotation);
3125 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003126 int x = plane_state->base.src.x1 >> 17;
3127 int y = plane_state->base.src.y1 >> 17;
3128 int w = drm_rect_width(&plane_state->base.src) >> 17;
3129 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003130 u32 offset;
3131
3132 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003133 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003134
3135 /* FIXME not quite sure how/if these apply to the chroma plane */
3136 if (w > max_width || h > max_height) {
3137 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3138 w, h, max_width, max_height);
3139 return -EINVAL;
3140 }
3141
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003142 plane_state->color_plane[1].offset = offset;
3143 plane_state->color_plane[1].x = x;
3144 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003145
3146 return 0;
3147}
3148
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003149static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3150{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003151 const struct drm_framebuffer *fb = plane_state->base.fb;
3152 int src_x = plane_state->base.src.x1 >> 16;
3153 int src_y = plane_state->base.src.y1 >> 16;
3154 int hsub = fb->format->hsub;
3155 int vsub = fb->format->vsub;
3156 int x = src_x / hsub;
3157 int y = src_y / vsub;
3158 u32 offset;
3159
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003160 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003161 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003162
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003163 plane_state->color_plane[1].offset = offset;
3164 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3165 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003166
3167 return 0;
3168}
3169
Ville Syrjälä73266592018-09-07 18:24:11 +03003170int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003171{
3172 const struct drm_framebuffer *fb = plane_state->base.fb;
3173 unsigned int rotation = plane_state->base.rotation;
3174 int ret;
3175
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003176 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003177 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3178 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3179
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003180 ret = intel_plane_check_stride(plane_state);
3181 if (ret)
3182 return ret;
3183
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003184 if (!plane_state->base.visible)
3185 return 0;
3186
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003187 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003188 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003189 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003190 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003191 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003192
Ville Syrjälä8d970652016-01-28 16:30:28 +02003193 /*
3194 * Handle the AUX surface first since
3195 * the main surface setup depends on it.
3196 */
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05303197 if (is_planar_yuv_format(fb->format->format)) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003198 ret = skl_check_nv12_aux_surface(plane_state);
3199 if (ret)
3200 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003201 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003202 ret = skl_check_ccs_aux_surface(plane_state);
3203 if (ret)
3204 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003205 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003206 plane_state->color_plane[1].offset = ~0xfff;
3207 plane_state->color_plane[1].x = 0;
3208 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003209 }
3210
Ville Syrjälä73266592018-09-07 18:24:11 +03003211 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003212 if (ret)
3213 return ret;
3214
3215 return 0;
3216}
3217
Ville Syrjäläddd57132018-09-07 18:24:02 +03003218unsigned int
3219i9xx_plane_max_stride(struct intel_plane *plane,
3220 u32 pixel_format, u64 modifier,
3221 unsigned int rotation)
3222{
3223 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3224
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08003225 if (!HAS_GMCH(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +03003226 return 32*1024;
3227 } else if (INTEL_GEN(dev_priv) >= 4) {
3228 if (modifier == I915_FORMAT_MOD_X_TILED)
3229 return 16*1024;
3230 else
3231 return 32*1024;
3232 } else if (INTEL_GEN(dev_priv) >= 3) {
3233 if (modifier == I915_FORMAT_MOD_X_TILED)
3234 return 8*1024;
3235 else
3236 return 16*1024;
3237 } else {
3238 if (plane->i9xx_plane == PLANE_C)
3239 return 4*1024;
3240 else
3241 return 8*1024;
3242 }
3243}
3244
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003245static u32 i9xx_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003246{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003247 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003248 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3249 u32 dspcntr = 0;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003250
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003251 dspcntr |= DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003252
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003253 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3254 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003255
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003256 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003257 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003258
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003259 return dspcntr;
3260}
3261
3262static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3263 const struct intel_plane_state *plane_state)
3264{
3265 struct drm_i915_private *dev_priv =
3266 to_i915(plane_state->base.plane->dev);
3267 const struct drm_framebuffer *fb = plane_state->base.fb;
3268 unsigned int rotation = plane_state->base.rotation;
3269 u32 dspcntr;
3270
3271 dspcntr = DISPLAY_PLANE_ENABLE;
3272
3273 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3274 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
3275 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
3276
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003277 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003278 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003279 dspcntr |= DISPPLANE_8BPP;
3280 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003281 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003282 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003283 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003284 case DRM_FORMAT_RGB565:
3285 dspcntr |= DISPPLANE_BGRX565;
3286 break;
3287 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003288 dspcntr |= DISPPLANE_BGRX888;
3289 break;
3290 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003291 dspcntr |= DISPPLANE_RGBX888;
3292 break;
3293 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003294 dspcntr |= DISPPLANE_BGRX101010;
3295 break;
3296 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003297 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003298 break;
3299 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003300 MISSING_CASE(fb->format->format);
3301 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003302 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003303
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003304 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003305 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003306 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003307
Robert Fossc2c446a2017-05-19 16:50:17 -04003308 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003309 dspcntr |= DISPPLANE_ROTATE_180;
3310
Robert Fossc2c446a2017-05-19 16:50:17 -04003311 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003312 dspcntr |= DISPPLANE_MIRROR;
3313
Ville Syrjälä7145f602017-03-23 21:27:07 +02003314 return dspcntr;
3315}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003316
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003317int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003318{
3319 struct drm_i915_private *dev_priv =
3320 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003321 const struct drm_framebuffer *fb = plane_state->base.fb;
3322 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003323 int src_x = plane_state->base.src.x1 >> 16;
3324 int src_y = plane_state->base.src.y1 >> 16;
3325 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003326 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003327
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003328 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003329 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3330
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003331 ret = intel_plane_check_stride(plane_state);
3332 if (ret)
3333 return ret;
3334
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003335 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003336
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003337 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003338 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3339 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003340 else
3341 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003342
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003343 /* HSW/BDW do this automagically in hardware */
3344 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003345 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3346 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3347
Robert Fossc2c446a2017-05-19 16:50:17 -04003348 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003349 src_x += src_w - 1;
3350 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003351 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003352 src_x += src_w - 1;
3353 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303354 }
3355
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003356 plane_state->color_plane[0].offset = offset;
3357 plane_state->color_plane[0].x = src_x;
3358 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003359
3360 return 0;
3361}
3362
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003363static int
3364i9xx_plane_check(struct intel_crtc_state *crtc_state,
3365 struct intel_plane_state *plane_state)
3366{
3367 int ret;
3368
Ville Syrjälä25721f82018-09-07 18:24:12 +03003369 ret = chv_plane_check_rotation(plane_state);
3370 if (ret)
3371 return ret;
3372
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003373 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3374 &crtc_state->base,
3375 DRM_PLANE_HELPER_NO_SCALING,
3376 DRM_PLANE_HELPER_NO_SCALING,
3377 false, true);
3378 if (ret)
3379 return ret;
3380
3381 if (!plane_state->base.visible)
3382 return 0;
3383
3384 ret = intel_plane_check_src_coordinates(plane_state);
3385 if (ret)
3386 return ret;
3387
3388 ret = i9xx_check_plane_surface(plane_state);
3389 if (ret)
3390 return ret;
3391
3392 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3393
3394 return 0;
3395}
3396
Ville Syrjäläed150302017-11-17 21:19:10 +02003397static void i9xx_update_plane(struct intel_plane *plane,
3398 const struct intel_crtc_state *crtc_state,
3399 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003400{
Ville Syrjäläed150302017-11-17 21:19:10 +02003401 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003402 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003403 u32 linear_offset;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003404 int x = plane_state->color_plane[0].x;
3405 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003406 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003407 u32 dspaddr_offset;
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003408 u32 dspcntr;
3409
3410 dspcntr = plane_state->ctl | i9xx_plane_ctl_crtc(crtc_state);
Ville Syrjälä7145f602017-03-23 21:27:07 +02003411
Ville Syrjälä29490562016-01-20 18:02:50 +02003412 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003413
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003414 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003415 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003416 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003417 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003418
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003419 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3420
Ville Syrjälä83234d12018-11-14 23:07:17 +02003421 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3422
Ville Syrjälä78587de2017-03-09 17:44:32 +02003423 if (INTEL_GEN(dev_priv) < 4) {
3424 /* pipesrc and dspsize control the size that is scaled from,
3425 * which should always be the user's requested size.
3426 */
Ville Syrjälä83234d12018-11-14 23:07:17 +02003427 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003428 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003429 ((crtc_state->pipe_src_h - 1) << 16) |
3430 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003431 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003432 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003433 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003434 ((crtc_state->pipe_src_h - 1) << 16) |
3435 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003436 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003437 }
3438
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003439 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003440 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003441 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003442 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3443 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3444 }
3445
3446 /*
3447 * The control register self-arms if the plane was previously
3448 * disabled. Try to make the plane enable atomic by writing
3449 * the control register just before the surface register.
3450 */
3451 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3452 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläed150302017-11-17 21:19:10 +02003453 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003454 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003455 dspaddr_offset);
Ville Syrjälä83234d12018-11-14 23:07:17 +02003456 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003457 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003458 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003459 dspaddr_offset);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003460
3461 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003462}
3463
Ville Syrjäläed150302017-11-17 21:19:10 +02003464static void i9xx_disable_plane(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02003465 const struct intel_crtc_state *crtc_state)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003466{
Ville Syrjäläed150302017-11-17 21:19:10 +02003467 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3468 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003469 unsigned long irqflags;
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003470 u32 dspcntr;
3471
3472 /*
3473 * DSPCNTR pipe gamma enable on g4x+ and pipe csc
3474 * enable on ilk+ affect the pipe bottom color as
3475 * well, so we must configure them even if the plane
3476 * is disabled.
3477 *
3478 * On pre-g4x there is no way to gamma correct the
3479 * pipe bottom color but we'll keep on doing this
3480 * anyway.
3481 */
3482 dspcntr = i9xx_plane_ctl_crtc(crtc_state);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003483
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003484 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3485
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003486 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
Ville Syrjäläed150302017-11-17 21:19:10 +02003487 if (INTEL_GEN(dev_priv) >= 4)
3488 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003489 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003490 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003491
3492 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003493}
3494
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003495static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3496 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003497{
Ville Syrjäläed150302017-11-17 21:19:10 +02003498 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003499 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003500 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003501 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003502 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003503 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003504
3505 /*
3506 * Not 100% correct for planes that can move between pipes,
3507 * but that's only the case for gen2-4 which don't have any
3508 * display power wells.
3509 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003510 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003511 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
3512 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003513 return false;
3514
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003515 val = I915_READ(DSPCNTR(i9xx_plane));
3516
3517 ret = val & DISPLAY_PLANE_ENABLE;
3518
3519 if (INTEL_GEN(dev_priv) >= 5)
3520 *pipe = plane->pipe;
3521 else
3522 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3523 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003524
Chris Wilson0e6e0be2019-01-14 14:21:24 +00003525 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003526
3527 return ret;
3528}
3529
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003530static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003531intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003532{
Ben Widawsky2f075562017-03-24 14:29:48 -07003533 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003534 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003535 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003536 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003537}
3538
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003539static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3540{
3541 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003542 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003543
3544 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3545 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3546 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003547}
3548
Chandra Kondurua1b22782015-04-07 15:28:45 -07003549/*
3550 * This function detaches (aka. unbinds) unused scalers in hardware
3551 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003552static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003553{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003554 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3555 const struct intel_crtc_scaler_state *scaler_state =
3556 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003557 int i;
3558
Chandra Kondurua1b22782015-04-07 15:28:45 -07003559 /* loop through and disable scalers that aren't in use */
3560 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003561 if (!scaler_state->scalers[i].in_use)
3562 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003563 }
3564}
3565
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003566static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3567 int color_plane, unsigned int rotation)
3568{
3569 /*
3570 * The stride is either expressed as a multiple of 64 bytes chunks for
3571 * linear buffers or in number of tiles for tiled buffers.
3572 */
3573 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3574 return 64;
3575 else if (drm_rotation_90_or_270(rotation))
3576 return intel_tile_height(fb, color_plane);
3577 else
3578 return intel_tile_width_bytes(fb, color_plane);
3579}
3580
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003581u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003582 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003583{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003584 const struct drm_framebuffer *fb = plane_state->base.fb;
3585 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003586 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003587
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003588 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003589 return 0;
3590
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003591 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003592}
3593
Jani Nikulaba3f4d02019-01-18 14:01:23 +02003594static u32 skl_plane_ctl_format(u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003595{
Chandra Konduru6156a452015-04-27 13:48:39 -07003596 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003597 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003598 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003599 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003600 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003601 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003602 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003603 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003604 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003605 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003606 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003607 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003608 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003609 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003610 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003611 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003612 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003613 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003614 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003615 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003616 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003617 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003618 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303619 case DRM_FORMAT_NV12:
3620 return PLANE_CTL_FORMAT_NV12;
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05303621 case DRM_FORMAT_P010:
3622 return PLANE_CTL_FORMAT_P010;
3623 case DRM_FORMAT_P012:
3624 return PLANE_CTL_FORMAT_P012;
3625 case DRM_FORMAT_P016:
3626 return PLANE_CTL_FORMAT_P016;
Swati Sharma296e9b12019-03-04 17:26:35 +05303627 case DRM_FORMAT_Y210:
3628 return PLANE_CTL_FORMAT_Y210;
3629 case DRM_FORMAT_Y212:
3630 return PLANE_CTL_FORMAT_Y212;
3631 case DRM_FORMAT_Y216:
3632 return PLANE_CTL_FORMAT_Y216;
3633 case DRM_FORMAT_Y410:
3634 return PLANE_CTL_FORMAT_Y410;
3635 case DRM_FORMAT_Y412:
3636 return PLANE_CTL_FORMAT_Y412;
3637 case DRM_FORMAT_Y416:
3638 return PLANE_CTL_FORMAT_Y416;
Chandra Konduru6156a452015-04-27 13:48:39 -07003639 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003640 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003641 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003642
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003643 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003644}
3645
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003646static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003647{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003648 if (!plane_state->base.fb->format->has_alpha)
3649 return PLANE_CTL_ALPHA_DISABLE;
3650
3651 switch (plane_state->base.pixel_blend_mode) {
3652 case DRM_MODE_BLEND_PIXEL_NONE:
3653 return PLANE_CTL_ALPHA_DISABLE;
3654 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003655 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003656 case DRM_MODE_BLEND_COVERAGE:
3657 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003658 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003659 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003660 return PLANE_CTL_ALPHA_DISABLE;
3661 }
3662}
3663
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003664static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003665{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003666 if (!plane_state->base.fb->format->has_alpha)
3667 return PLANE_COLOR_ALPHA_DISABLE;
3668
3669 switch (plane_state->base.pixel_blend_mode) {
3670 case DRM_MODE_BLEND_PIXEL_NONE:
3671 return PLANE_COLOR_ALPHA_DISABLE;
3672 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003673 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003674 case DRM_MODE_BLEND_COVERAGE:
3675 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003676 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003677 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003678 return PLANE_COLOR_ALPHA_DISABLE;
3679 }
3680}
3681
Jani Nikulaba3f4d02019-01-18 14:01:23 +02003682static u32 skl_plane_ctl_tiling(u64 fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003683{
Chandra Konduru6156a452015-04-27 13:48:39 -07003684 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003685 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003686 break;
3687 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003688 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003689 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003690 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003691 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003692 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003693 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003694 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003695 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003696 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003697 default:
3698 MISSING_CASE(fb_modifier);
3699 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003700
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003701 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003702}
3703
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003704static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003705{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003706 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003707 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003708 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303709 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003710 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303711 * while i915 HW rotation is clockwise, thats why this swapping.
3712 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003713 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303714 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003715 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003716 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003717 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303718 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003719 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003720 MISSING_CASE(rotate);
3721 }
3722
3723 return 0;
3724}
3725
3726static u32 cnl_plane_ctl_flip(unsigned int reflect)
3727{
3728 switch (reflect) {
3729 case 0:
3730 break;
3731 case DRM_MODE_REFLECT_X:
3732 return PLANE_CTL_FLIP_HORIZONTAL;
3733 case DRM_MODE_REFLECT_Y:
3734 default:
3735 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003736 }
3737
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003738 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003739}
3740
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003741u32 skl_plane_ctl_crtc(const struct intel_crtc_state *crtc_state)
3742{
3743 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3744 u32 plane_ctl = 0;
3745
3746 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
3747 return plane_ctl;
3748
3749 plane_ctl |= PLANE_CTL_PIPE_GAMMA_ENABLE;
3750 plane_ctl |= PLANE_CTL_PIPE_CSC_ENABLE;
3751
3752 return plane_ctl;
3753}
3754
Ville Syrjälä2e881262017-03-17 23:17:56 +02003755u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3756 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003757{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003758 struct drm_i915_private *dev_priv =
3759 to_i915(plane_state->base.plane->dev);
3760 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003761 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003762 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003763 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003764
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003765 plane_ctl = PLANE_CTL_ENABLE;
3766
James Ausmus4036c782017-11-13 10:11:28 -08003767 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003768 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003769 plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003770
3771 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3772 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003773
3774 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3775 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003776 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003777
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003778 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003779 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003780 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3781
3782 if (INTEL_GEN(dev_priv) >= 10)
3783 plane_ctl |= cnl_plane_ctl_flip(rotation &
3784 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003785
Ville Syrjälä2e881262017-03-17 23:17:56 +02003786 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3787 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3788 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3789 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3790
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003791 return plane_ctl;
3792}
3793
Ville Syrjälä7eb31a02019-02-05 18:08:36 +02003794u32 glk_plane_color_ctl_crtc(const struct intel_crtc_state *crtc_state)
3795{
3796 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
3797 u32 plane_color_ctl = 0;
3798
3799 if (INTEL_GEN(dev_priv) >= 11)
3800 return plane_color_ctl;
3801
3802 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3803 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3804
3805 return plane_color_ctl;
3806}
3807
James Ausmus4036c782017-11-13 10:11:28 -08003808u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3809 const struct intel_plane_state *plane_state)
3810{
Kevin Strasser42fd20e2019-03-12 17:38:31 -07003811 struct drm_i915_private *dev_priv =
3812 to_i915(plane_state->base.plane->dev);
James Ausmus4036c782017-11-13 10:11:28 -08003813 const struct drm_framebuffer *fb = plane_state->base.fb;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303814 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
James Ausmus4036c782017-11-13 10:11:28 -08003815 u32 plane_color_ctl = 0;
3816
James Ausmus4036c782017-11-13 10:11:28 -08003817 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003818 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003819
Kevin Strasser42fd20e2019-03-12 17:38:31 -07003820 if (fb->format->is_yuv && !icl_is_hdr_plane(dev_priv, plane->id)) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003821 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3822 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3823 else
3824 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003825
3826 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3827 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303828 } else if (fb->format->is_yuv) {
3829 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003830 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003831
James Ausmus4036c782017-11-13 10:11:28 -08003832 return plane_color_ctl;
3833}
3834
Maarten Lankhorst73974892016-08-05 23:28:27 +03003835static int
3836__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003837 struct drm_atomic_state *state,
3838 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003839{
3840 struct drm_crtc_state *crtc_state;
3841 struct drm_crtc *crtc;
3842 int i, ret;
3843
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003844 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003845 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003846
3847 if (!state)
3848 return 0;
3849
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003850 /*
3851 * We've duplicated the state, pointers to the old state are invalid.
3852 *
3853 * Don't attempt to use the old state until we commit the duplicated state.
3854 */
3855 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003856 /*
3857 * Force recalculation even if we restore
3858 * current state. With fast modeset this may not result
3859 * in a modeset when the state is compatible.
3860 */
3861 crtc_state->mode_changed = true;
3862 }
3863
3864 /* ignore any reset values/BIOS leftovers in the WM registers */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08003865 if (!HAS_GMCH(to_i915(dev)))
Ville Syrjälä602ae832017-03-02 19:15:02 +02003866 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003867
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003868 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003869
3870 WARN_ON(ret == -EDEADLK);
3871 return ret;
3872}
3873
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003874static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3875{
Chris Wilson55277e12019-01-03 11:21:04 +00003876 return (INTEL_INFO(dev_priv)->gpu_reset_clobbers_display &&
3877 intel_has_gpu_reset(dev_priv));
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003878}
3879
Chris Wilsonc0336662016-05-06 15:40:21 +01003880void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003881{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003882 struct drm_device *dev = &dev_priv->drm;
3883 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3884 struct drm_atomic_state *state;
3885 int ret;
3886
Daniel Vetterce87ea12017-07-19 14:54:55 +02003887 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003888 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003889 !gpu_reset_clobbers_display(dev_priv))
3890 return;
3891
Daniel Vetter9db529a2017-08-08 10:08:28 +02003892 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3893 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3894 wake_up_all(&dev_priv->gpu_error.wait_queue);
3895
3896 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3897 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3898 i915_gem_set_wedged(dev_priv);
3899 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003900
Maarten Lankhorst73974892016-08-05 23:28:27 +03003901 /*
3902 * Need mode_config.mutex so that we don't
3903 * trample ongoing ->detect() and whatnot.
3904 */
3905 mutex_lock(&dev->mode_config.mutex);
3906 drm_modeset_acquire_init(ctx, 0);
3907 while (1) {
3908 ret = drm_modeset_lock_all_ctx(dev, ctx);
3909 if (ret != -EDEADLK)
3910 break;
3911
3912 drm_modeset_backoff(ctx);
3913 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003914 /*
3915 * Disabling the crtcs gracefully seems nicer. Also the
3916 * g33 docs say we should at least disable all the planes.
3917 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003918 state = drm_atomic_helper_duplicate_state(dev, ctx);
3919 if (IS_ERR(state)) {
3920 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003921 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003922 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003923 }
3924
3925 ret = drm_atomic_helper_disable_all(dev, ctx);
3926 if (ret) {
3927 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003928 drm_atomic_state_put(state);
3929 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003930 }
3931
3932 dev_priv->modeset_restore_state = state;
3933 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003934}
3935
Chris Wilsonc0336662016-05-06 15:40:21 +01003936void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003937{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003938 struct drm_device *dev = &dev_priv->drm;
3939 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003940 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003941 int ret;
3942
Daniel Vetterce87ea12017-07-19 14:54:55 +02003943 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003944 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003945 return;
3946
Chris Wilson40da1d32018-04-05 13:37:14 +01003947 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003948 if (!state)
3949 goto unlock;
3950
Ville Syrjälä75147472014-11-24 18:28:11 +02003951 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003952 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003953 /* for testing only restore the display */
3954 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003955 if (ret)
3956 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003957 } else {
3958 /*
3959 * The display has been reset as well,
3960 * so need a full re-initialization.
3961 */
3962 intel_runtime_pm_disable_interrupts(dev_priv);
3963 intel_runtime_pm_enable_interrupts(dev_priv);
3964
Imre Deak51f59202016-09-14 13:04:13 +03003965 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003966 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003967 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003968
3969 spin_lock_irq(&dev_priv->irq_lock);
3970 if (dev_priv->display.hpd_irq_setup)
3971 dev_priv->display.hpd_irq_setup(dev_priv);
3972 spin_unlock_irq(&dev_priv->irq_lock);
3973
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003974 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003975 if (ret)
3976 DRM_ERROR("Restoring old state failed with %i\n", ret);
3977
3978 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003979 }
3980
Daniel Vetterce87ea12017-07-19 14:54:55 +02003981 drm_atomic_state_put(state);
3982unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003983 drm_modeset_drop_locks(ctx);
3984 drm_modeset_acquire_fini(ctx);
3985 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003986
3987 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003988}
3989
Ville Syrjäläd1622112019-02-04 22:21:39 +02003990static void icl_set_pipe_chicken(struct intel_crtc *crtc)
3991{
3992 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
3993 enum pipe pipe = crtc->pipe;
3994 u32 tmp;
3995
3996 tmp = I915_READ(PIPE_CHICKEN(pipe));
3997
3998 /*
3999 * Display WA #1153: icl
4000 * enable hardware to bypass the alpha math
4001 * and rounding for per-pixel values 00 and 0xff
4002 */
4003 tmp |= PER_PIXEL_ALPHA_BYPASS_EN;
4004
Ville Syrjäläbf002c12019-02-04 22:22:32 +02004005 /*
4006 * W/A for underruns with linear/X-tiled with
4007 * WM1+ disabled.
4008 */
4009 tmp |= PM_FILL_MAINTAIN_DBUF_FULLNESS;
4010
Ville Syrjäläd1622112019-02-04 22:21:39 +02004011 I915_WRITE(PIPE_CHICKEN(pipe), tmp);
4012}
4013
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004014static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
4015 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004016{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004017 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00004018 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004019
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02004020 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004021 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02004022
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004023 /*
4024 * Update pipe size and adjust fitter if needed: the reason for this is
4025 * that in compute_mode_changes we check the native mode (not the pfit
4026 * mode) to see if we can flip rather than do a full mode set. In the
4027 * fastboot case, we'll flip, but if we don't update the pipesrc and
4028 * pfit state, we'll end up with a big fb scanned out into the wrong
4029 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004030 */
4031
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004032 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004033 ((new_crtc_state->pipe_src_w - 1) << 16) |
4034 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02004035
4036 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00004037 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02004038 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02004039
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004040 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02004041 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004042 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03004043 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02004044 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02004045 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02004046 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004047 }
Matt Roperc0550302019-01-30 10:51:20 -08004048
4049 /*
4050 * We don't (yet) allow userspace to control the pipe background color,
4051 * so force it to black, but apply pipe gamma and CSC so that its
4052 * handling will match how we program our planes.
4053 */
4054 if (INTEL_GEN(dev_priv) >= 9)
4055 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
4056 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
4057 SKL_BOTTOM_COLOR_CSC_ENABLE);
Ville Syrjälä108d14b2019-02-04 22:22:14 +02004058
4059 if (INTEL_GEN(dev_priv) >= 11)
4060 icl_set_pipe_chicken(crtc);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03004061}
4062
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004063static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004064{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004065 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004066 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004067 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004068 i915_reg_t reg;
4069 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004070
4071 /* enable normal train */
4072 reg = FDI_TX_CTL(pipe);
4073 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004074 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07004075 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4076 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07004077 } else {
4078 temp &= ~FDI_LINK_TRAIN_NONE;
4079 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07004080 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004081 I915_WRITE(reg, temp);
4082
4083 reg = FDI_RX_CTL(pipe);
4084 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004085 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004086 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4087 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
4088 } else {
4089 temp &= ~FDI_LINK_TRAIN_NONE;
4090 temp |= FDI_LINK_TRAIN_NONE;
4091 }
4092 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
4093
4094 /* wait one idle pattern time */
4095 POSTING_READ(reg);
4096 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07004097
4098 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004099 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07004100 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
4101 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004102}
4103
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004104/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004105static void ironlake_fdi_link_train(struct intel_crtc *crtc,
4106 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004107{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004108 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004109 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004110 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004111 i915_reg_t reg;
4112 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004113
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03004114 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004115 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004116
Adam Jacksone1a44742010-06-25 15:32:14 -04004117 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4118 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004119 reg = FDI_RX_IMR(pipe);
4120 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004121 temp &= ~FDI_RX_SYMBOL_LOCK;
4122 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004123 I915_WRITE(reg, temp);
4124 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004125 udelay(150);
4126
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004127 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004128 reg = FDI_TX_CTL(pipe);
4129 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004130 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004131 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004132 temp &= ~FDI_LINK_TRAIN_NONE;
4133 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01004134 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004135
Chris Wilson5eddb702010-09-11 13:48:45 +01004136 reg = FDI_RX_CTL(pipe);
4137 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004138 temp &= ~FDI_LINK_TRAIN_NONE;
4139 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01004140 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4141
4142 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004143 udelay(150);
4144
Jesse Barnes5b2adf82010-10-07 16:01:15 -07004145 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01004146 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
4147 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
4148 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07004149
Chris Wilson5eddb702010-09-11 13:48:45 +01004150 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004151 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004152 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004153 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4154
4155 if ((temp & FDI_RX_BIT_LOCK)) {
4156 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01004157 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004158 break;
4159 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004160 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004161 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004162 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004163
4164 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004165 reg = FDI_TX_CTL(pipe);
4166 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004167 temp &= ~FDI_LINK_TRAIN_NONE;
4168 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004169 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004170
Chris Wilson5eddb702010-09-11 13:48:45 +01004171 reg = FDI_RX_CTL(pipe);
4172 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004173 temp &= ~FDI_LINK_TRAIN_NONE;
4174 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004175 I915_WRITE(reg, temp);
4176
4177 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004178 udelay(150);
4179
Chris Wilson5eddb702010-09-11 13:48:45 +01004180 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004181 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004182 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004183 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4184
4185 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004186 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004187 DRM_DEBUG_KMS("FDI train 2 done.\n");
4188 break;
4189 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004190 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004191 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004192 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004193
4194 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004195
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004196}
4197
Akshay Joshi0206e352011-08-16 15:34:10 -04004198static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004199 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4200 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4201 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4202 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4203};
4204
4205/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004206static void gen6_fdi_link_train(struct intel_crtc *crtc,
4207 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004208{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004209 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004210 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004211 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004212 i915_reg_t reg;
4213 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004214
Adam Jacksone1a44742010-06-25 15:32:14 -04004215 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4216 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004217 reg = FDI_RX_IMR(pipe);
4218 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004219 temp &= ~FDI_RX_SYMBOL_LOCK;
4220 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004221 I915_WRITE(reg, temp);
4222
4223 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004224 udelay(150);
4225
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004226 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004227 reg = FDI_TX_CTL(pipe);
4228 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004229 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004230 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004231 temp &= ~FDI_LINK_TRAIN_NONE;
4232 temp |= FDI_LINK_TRAIN_PATTERN_1;
4233 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4234 /* SNB-B */
4235 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004236 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004237
Daniel Vetterd74cf322012-10-26 10:58:13 +02004238 I915_WRITE(FDI_RX_MISC(pipe),
4239 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4240
Chris Wilson5eddb702010-09-11 13:48:45 +01004241 reg = FDI_RX_CTL(pipe);
4242 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004243 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004244 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4245 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4246 } else {
4247 temp &= ~FDI_LINK_TRAIN_NONE;
4248 temp |= FDI_LINK_TRAIN_PATTERN_1;
4249 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004250 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4251
4252 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004253 udelay(150);
4254
Akshay Joshi0206e352011-08-16 15:34:10 -04004255 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004256 reg = FDI_TX_CTL(pipe);
4257 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004258 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4259 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004260 I915_WRITE(reg, temp);
4261
4262 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004263 udelay(500);
4264
Sean Paulfa37d392012-03-02 12:53:39 -05004265 for (retry = 0; retry < 5; retry++) {
4266 reg = FDI_RX_IIR(pipe);
4267 temp = I915_READ(reg);
4268 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4269 if (temp & FDI_RX_BIT_LOCK) {
4270 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4271 DRM_DEBUG_KMS("FDI train 1 done.\n");
4272 break;
4273 }
4274 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004275 }
Sean Paulfa37d392012-03-02 12:53:39 -05004276 if (retry < 5)
4277 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004278 }
4279 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004280 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004281
4282 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004283 reg = FDI_TX_CTL(pipe);
4284 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004285 temp &= ~FDI_LINK_TRAIN_NONE;
4286 temp |= FDI_LINK_TRAIN_PATTERN_2;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004287 if (IS_GEN(dev_priv, 6)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004288 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4289 /* SNB-B */
4290 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4291 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004292 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004293
Chris Wilson5eddb702010-09-11 13:48:45 +01004294 reg = FDI_RX_CTL(pipe);
4295 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004296 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004297 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4298 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4299 } else {
4300 temp &= ~FDI_LINK_TRAIN_NONE;
4301 temp |= FDI_LINK_TRAIN_PATTERN_2;
4302 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004303 I915_WRITE(reg, temp);
4304
4305 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004306 udelay(150);
4307
Akshay Joshi0206e352011-08-16 15:34:10 -04004308 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004309 reg = FDI_TX_CTL(pipe);
4310 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004311 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4312 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004313 I915_WRITE(reg, temp);
4314
4315 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004316 udelay(500);
4317
Sean Paulfa37d392012-03-02 12:53:39 -05004318 for (retry = 0; retry < 5; retry++) {
4319 reg = FDI_RX_IIR(pipe);
4320 temp = I915_READ(reg);
4321 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4322 if (temp & FDI_RX_SYMBOL_LOCK) {
4323 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4324 DRM_DEBUG_KMS("FDI train 2 done.\n");
4325 break;
4326 }
4327 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004328 }
Sean Paulfa37d392012-03-02 12:53:39 -05004329 if (retry < 5)
4330 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004331 }
4332 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004333 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004334
4335 DRM_DEBUG_KMS("FDI train done.\n");
4336}
4337
Jesse Barnes357555c2011-04-28 15:09:55 -07004338/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004339static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4340 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004341{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004342 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004343 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004344 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004345 i915_reg_t reg;
4346 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004347
4348 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4349 for train result */
4350 reg = FDI_RX_IMR(pipe);
4351 temp = I915_READ(reg);
4352 temp &= ~FDI_RX_SYMBOL_LOCK;
4353 temp &= ~FDI_RX_BIT_LOCK;
4354 I915_WRITE(reg, temp);
4355
4356 POSTING_READ(reg);
4357 udelay(150);
4358
Daniel Vetter01a415f2012-10-27 15:58:40 +02004359 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4360 I915_READ(FDI_RX_IIR(pipe)));
4361
Jesse Barnes139ccd32013-08-19 11:04:55 -07004362 /* Try each vswing and preemphasis setting twice before moving on */
4363 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4364 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004365 reg = FDI_TX_CTL(pipe);
4366 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004367 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4368 temp &= ~FDI_TX_ENABLE;
4369 I915_WRITE(reg, temp);
4370
4371 reg = FDI_RX_CTL(pipe);
4372 temp = I915_READ(reg);
4373 temp &= ~FDI_LINK_TRAIN_AUTO;
4374 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4375 temp &= ~FDI_RX_ENABLE;
4376 I915_WRITE(reg, temp);
4377
4378 /* enable CPU FDI TX and PCH FDI RX */
4379 reg = FDI_TX_CTL(pipe);
4380 temp = I915_READ(reg);
4381 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004382 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004383 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004384 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004385 temp |= snb_b_fdi_train_param[j/2];
4386 temp |= FDI_COMPOSITE_SYNC;
4387 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4388
4389 I915_WRITE(FDI_RX_MISC(pipe),
4390 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4391
4392 reg = FDI_RX_CTL(pipe);
4393 temp = I915_READ(reg);
4394 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4395 temp |= FDI_COMPOSITE_SYNC;
4396 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4397
4398 POSTING_READ(reg);
4399 udelay(1); /* should be 0.5us */
4400
4401 for (i = 0; i < 4; i++) {
4402 reg = FDI_RX_IIR(pipe);
4403 temp = I915_READ(reg);
4404 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4405
4406 if (temp & FDI_RX_BIT_LOCK ||
4407 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4408 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4409 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4410 i);
4411 break;
4412 }
4413 udelay(1); /* should be 0.5us */
4414 }
4415 if (i == 4) {
4416 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4417 continue;
4418 }
4419
4420 /* Train 2 */
4421 reg = FDI_TX_CTL(pipe);
4422 temp = I915_READ(reg);
4423 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4424 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4425 I915_WRITE(reg, temp);
4426
4427 reg = FDI_RX_CTL(pipe);
4428 temp = I915_READ(reg);
4429 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4430 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004431 I915_WRITE(reg, temp);
4432
4433 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004434 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004435
Jesse Barnes139ccd32013-08-19 11:04:55 -07004436 for (i = 0; i < 4; i++) {
4437 reg = FDI_RX_IIR(pipe);
4438 temp = I915_READ(reg);
4439 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004440
Jesse Barnes139ccd32013-08-19 11:04:55 -07004441 if (temp & FDI_RX_SYMBOL_LOCK ||
4442 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4443 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4444 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4445 i);
4446 goto train_done;
4447 }
4448 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004449 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004450 if (i == 4)
4451 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004452 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004453
Jesse Barnes139ccd32013-08-19 11:04:55 -07004454train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004455 DRM_DEBUG_KMS("FDI train done.\n");
4456}
4457
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004458static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004459{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4461 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004462 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004463 i915_reg_t reg;
4464 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004465
Jesse Barnes0e23b992010-09-10 11:10:00 -07004466 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004467 reg = FDI_RX_CTL(pipe);
4468 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004469 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004470 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004471 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004472 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4473
4474 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004475 udelay(200);
4476
4477 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004478 temp = I915_READ(reg);
4479 I915_WRITE(reg, temp | FDI_PCDCLK);
4480
4481 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004482 udelay(200);
4483
Paulo Zanoni20749732012-11-23 15:30:38 -02004484 /* Enable CPU FDI TX PLL, always on for Ironlake */
4485 reg = FDI_TX_CTL(pipe);
4486 temp = I915_READ(reg);
4487 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4488 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004489
Paulo Zanoni20749732012-11-23 15:30:38 -02004490 POSTING_READ(reg);
4491 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004492 }
4493}
4494
Daniel Vetter88cefb62012-08-12 19:27:14 +02004495static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4496{
4497 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004498 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004499 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004500 i915_reg_t reg;
4501 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004502
4503 /* Switch from PCDclk to Rawclk */
4504 reg = FDI_RX_CTL(pipe);
4505 temp = I915_READ(reg);
4506 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4507
4508 /* Disable CPU FDI TX PLL */
4509 reg = FDI_TX_CTL(pipe);
4510 temp = I915_READ(reg);
4511 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4512
4513 POSTING_READ(reg);
4514 udelay(100);
4515
4516 reg = FDI_RX_CTL(pipe);
4517 temp = I915_READ(reg);
4518 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4519
4520 /* Wait for the clocks to turn off. */
4521 POSTING_READ(reg);
4522 udelay(100);
4523}
4524
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004525static void ironlake_fdi_disable(struct drm_crtc *crtc)
4526{
4527 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004528 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004529 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4530 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004531 i915_reg_t reg;
4532 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004533
4534 /* disable CPU FDI tx and PCH FDI rx */
4535 reg = FDI_TX_CTL(pipe);
4536 temp = I915_READ(reg);
4537 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4538 POSTING_READ(reg);
4539
4540 reg = FDI_RX_CTL(pipe);
4541 temp = I915_READ(reg);
4542 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004543 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004544 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4545
4546 POSTING_READ(reg);
4547 udelay(100);
4548
4549 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004550 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004551 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004552
4553 /* still set train pattern 1 */
4554 reg = FDI_TX_CTL(pipe);
4555 temp = I915_READ(reg);
4556 temp &= ~FDI_LINK_TRAIN_NONE;
4557 temp |= FDI_LINK_TRAIN_PATTERN_1;
4558 I915_WRITE(reg, temp);
4559
4560 reg = FDI_RX_CTL(pipe);
4561 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004562 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004563 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4564 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4565 } else {
4566 temp &= ~FDI_LINK_TRAIN_NONE;
4567 temp |= FDI_LINK_TRAIN_PATTERN_1;
4568 }
4569 /* BPC in FDI rx is consistent with that in PIPECONF */
4570 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004571 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004572 I915_WRITE(reg, temp);
4573
4574 POSTING_READ(reg);
4575 udelay(100);
4576}
4577
Chris Wilson49d73912016-11-29 09:50:08 +00004578bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004579{
Daniel Vetterfa058872017-07-20 19:57:52 +02004580 struct drm_crtc *crtc;
4581 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004582
Daniel Vetterfa058872017-07-20 19:57:52 +02004583 drm_for_each_crtc(crtc, &dev_priv->drm) {
4584 struct drm_crtc_commit *commit;
4585 spin_lock(&crtc->commit_lock);
4586 commit = list_first_entry_or_null(&crtc->commit_list,
4587 struct drm_crtc_commit, commit_entry);
4588 cleanup_done = commit ?
4589 try_wait_for_completion(&commit->cleanup_done) : true;
4590 spin_unlock(&crtc->commit_lock);
4591
4592 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004593 continue;
4594
Daniel Vetterfa058872017-07-20 19:57:52 +02004595 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004596
4597 return true;
4598 }
4599
4600 return false;
4601}
4602
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004603void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004604{
4605 u32 temp;
4606
4607 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4608
4609 mutex_lock(&dev_priv->sb_lock);
4610
4611 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4612 temp |= SBI_SSCCTL_DISABLE;
4613 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4614
4615 mutex_unlock(&dev_priv->sb_lock);
4616}
4617
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004618/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004619static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004620{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004621 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004622 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004623 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004624 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4625 u32 temp;
4626
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004627 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004628
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004629 /* The iCLK virtual clock root frequency is in MHz,
4630 * but the adjusted_mode->crtc_clock in in KHz. To get the
4631 * divisors, it is necessary to divide one by another, so we
4632 * convert the virtual clock precision to KHz here for higher
4633 * precision.
4634 */
4635 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004636 u32 iclk_virtual_root_freq = 172800 * 1000;
4637 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004638 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004639
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004640 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4641 clock << auxdiv);
4642 divsel = (desired_divisor / iclk_pi_range) - 2;
4643 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004644
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004645 /*
4646 * Near 20MHz is a corner case which is
4647 * out of range for the 7-bit divisor
4648 */
4649 if (divsel <= 0x7f)
4650 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004651 }
4652
4653 /* This should not happen with any sane values */
4654 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4655 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4656 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4657 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4658
4659 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 +03004660 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004661 auxdiv,
4662 divsel,
4663 phasedir,
4664 phaseinc);
4665
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004666 mutex_lock(&dev_priv->sb_lock);
4667
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004668 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004669 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004670 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4671 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4672 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4673 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4674 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4675 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004676 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004677
4678 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004679 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004680 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4681 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004682 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004683
4684 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004685 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004686 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004687 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004688
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004689 mutex_unlock(&dev_priv->sb_lock);
4690
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004691 /* Wait for initialization time */
4692 udelay(24);
4693
4694 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4695}
4696
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004697int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4698{
4699 u32 divsel, phaseinc, auxdiv;
4700 u32 iclk_virtual_root_freq = 172800 * 1000;
4701 u32 iclk_pi_range = 64;
4702 u32 desired_divisor;
4703 u32 temp;
4704
4705 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4706 return 0;
4707
4708 mutex_lock(&dev_priv->sb_lock);
4709
4710 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4711 if (temp & SBI_SSCCTL_DISABLE) {
4712 mutex_unlock(&dev_priv->sb_lock);
4713 return 0;
4714 }
4715
4716 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4717 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4718 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4719 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4720 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4721
4722 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4723 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4724 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4725
4726 mutex_unlock(&dev_priv->sb_lock);
4727
4728 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4729
4730 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4731 desired_divisor << auxdiv);
4732}
4733
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004734static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004735 enum pipe pch_transcoder)
4736{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004737 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4738 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4739 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004740
4741 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4742 I915_READ(HTOTAL(cpu_transcoder)));
4743 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4744 I915_READ(HBLANK(cpu_transcoder)));
4745 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4746 I915_READ(HSYNC(cpu_transcoder)));
4747
4748 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4749 I915_READ(VTOTAL(cpu_transcoder)));
4750 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4751 I915_READ(VBLANK(cpu_transcoder)));
4752 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4753 I915_READ(VSYNC(cpu_transcoder)));
4754 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4755 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4756}
4757
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004758static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004759{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02004760 u32 temp;
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004761
4762 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004763 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004764 return;
4765
4766 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4767 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4768
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004769 temp &= ~FDI_BC_BIFURCATION_SELECT;
4770 if (enable)
4771 temp |= FDI_BC_BIFURCATION_SELECT;
4772
4773 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004774 I915_WRITE(SOUTH_CHICKEN1, temp);
4775 POSTING_READ(SOUTH_CHICKEN1);
4776}
4777
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004778static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004779{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004780 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4781 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004782
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004783 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004784 case PIPE_A:
4785 break;
4786 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004787 if (crtc_state->fdi_lanes > 2)
4788 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004789 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004790 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004791
4792 break;
4793 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004794 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004795
4796 break;
4797 default:
4798 BUG();
4799 }
4800}
4801
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004802/*
4803 * Finds the encoder associated with the given CRTC. This can only be
4804 * used when we know that the CRTC isn't feeding multiple encoders!
4805 */
4806static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004807intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4808 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004809{
4810 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004811 const struct drm_connector_state *connector_state;
4812 const struct drm_connector *connector;
4813 struct intel_encoder *encoder = NULL;
4814 int num_encoders = 0;
4815 int i;
4816
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004817 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004818 if (connector_state->crtc != &crtc->base)
4819 continue;
4820
4821 encoder = to_intel_encoder(connector_state->best_encoder);
4822 num_encoders++;
4823 }
4824
4825 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4826 num_encoders, pipe_name(crtc->pipe));
4827
4828 return encoder;
4829}
4830
Jesse Barnesf67a5592011-01-05 10:31:48 -08004831/*
4832 * Enable PCH resources required for PCH ports:
4833 * - PCH PLLs
4834 * - FDI training & RX/TX
4835 * - update transcoder timings
4836 * - DP transcoding bits
4837 * - transcoder
4838 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004839static void ironlake_pch_enable(const struct intel_atomic_state *state,
4840 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004841{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004842 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004843 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004844 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004845 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004846 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004847
Daniel Vetterab9412b2013-05-03 11:49:46 +02004848 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004849
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004850 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004851 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004852
Daniel Vettercd986ab2012-10-26 10:58:12 +02004853 /* Write the TU size bits before fdi link training, so that error
4854 * detection works. */
4855 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4856 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4857
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004858 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004859 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004860
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004861 /* We need to program the right clock selection before writing the pixel
4862 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004863 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004864 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004865
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004866 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004867 temp |= TRANS_DPLL_ENABLE(pipe);
4868 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004869 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004870 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004871 temp |= sel;
4872 else
4873 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004874 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004875 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004876
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004877 /* XXX: pch pll's can be enabled any time before we enable the PCH
4878 * transcoder, and we actually should do this to not upset any PCH
4879 * transcoder that already use the clock when we share it.
4880 *
4881 * Note that enable_shared_dpll tries to do the right thing, but
4882 * get_shared_dpll unconditionally resets the pll - we need that to have
4883 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004884 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004885
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004886 /* set transcoder timing, panel must allow it */
4887 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004888 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004889
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004890 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004891
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004892 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004893 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004894 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004895 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004896 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004897 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004898 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004899 enum port port;
4900
Chris Wilson5eddb702010-09-11 13:48:45 +01004901 temp = I915_READ(reg);
4902 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004903 TRANS_DP_SYNC_MASK |
4904 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004905 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004906 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004907
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004908 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004909 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004910 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004911 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004912
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004913 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004914 WARN_ON(port < PORT_B || port > PORT_D);
4915 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004916
Chris Wilson5eddb702010-09-11 13:48:45 +01004917 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004918 }
4919
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004920 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004921}
4922
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004923static void lpt_pch_enable(const struct intel_atomic_state *state,
4924 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004925{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004926 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004927 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004928 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004929
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004930 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004931
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004932 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004933
Paulo Zanoni0540e482012-10-31 18:12:40 -02004934 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004935 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004936
Paulo Zanoni937bb612012-10-31 18:12:47 -02004937 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004938}
4939
Daniel Vettera1520312013-05-03 11:49:50 +02004940static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004941{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004942 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004943 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004944 u32 temp;
4945
4946 temp = I915_READ(dslreg);
4947 udelay(500);
4948 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004949 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004950 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004951 }
4952}
4953
Ville Syrjälä0a599522018-05-21 21:56:13 +03004954/*
4955 * The hardware phase 0.0 refers to the center of the pixel.
4956 * We want to start from the top/left edge which is phase
4957 * -0.5. That matches how the hardware calculates the scaling
4958 * factors (from top-left of the first pixel to bottom-right
4959 * of the last pixel, as opposed to the pixel centers).
4960 *
4961 * For 4:2:0 subsampled chroma planes we obviously have to
4962 * adjust that so that the chroma sample position lands in
4963 * the right spot.
4964 *
4965 * Note that for packed YCbCr 4:2:2 formats there is no way to
4966 * control chroma siting. The hardware simply replicates the
4967 * chroma samples for both of the luma samples, and thus we don't
4968 * actually get the expected MPEG2 chroma siting convention :(
4969 * The same behaviour is observed on pre-SKL platforms as well.
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004970 *
4971 * Theory behind the formula (note that we ignore sub-pixel
4972 * source coordinates):
4973 * s = source sample position
4974 * d = destination sample position
4975 *
4976 * Downscaling 4:1:
4977 * -0.5
4978 * | 0.0
4979 * | | 1.5 (initial phase)
4980 * | | |
4981 * v v v
4982 * | s | s | s | s |
4983 * | d |
4984 *
4985 * Upscaling 1:4:
4986 * -0.5
4987 * | -0.375 (initial phase)
4988 * | | 0.0
4989 * | | |
4990 * v v v
4991 * | s |
4992 * | d | d | d | d |
Ville Syrjälä0a599522018-05-21 21:56:13 +03004993 */
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004994u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
Ville Syrjälä0a599522018-05-21 21:56:13 +03004995{
4996 int phase = -0x8000;
4997 u16 trip = 0;
4998
4999 if (chroma_cosited)
5000 phase += (sub - 1) * 0x8000 / sub;
5001
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005002 phase += scale / (2 * sub);
5003
5004 /*
5005 * Hardware initial phase limited to [-0.5:1.5].
5006 * Since the max hardware scale factor is 3.0, we
5007 * should never actually excdeed 1.0 here.
5008 */
5009 WARN_ON(phase < -0x8000 || phase > 0x18000);
5010
Ville Syrjälä0a599522018-05-21 21:56:13 +03005011 if (phase < 0)
5012 phase = 0x10000 + phase;
5013 else
5014 trip = PS_PHASE_TRIP;
5015
5016 return ((phase >> 2) & PS_PHASE_MASK) | trip;
5017}
5018
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005019static int
5020skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03005021 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05305022 int src_w, int src_h, int dst_w, int dst_h,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005023 const struct drm_format_info *format, bool need_scaler)
Chandra Kondurua1b22782015-04-07 15:28:45 -07005024{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005025 struct intel_crtc_scaler_state *scaler_state =
5026 &crtc_state->scaler_state;
5027 struct intel_crtc *intel_crtc =
5028 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05305029 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
5030 const struct drm_display_mode *adjusted_mode =
5031 &crtc_state->base.adjusted_mode;
Chandra Konduru6156a452015-04-27 13:48:39 -07005032
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03005033 /*
5034 * Src coordinates are already rotated by 270 degrees for
5035 * the 90/270 degree plane rotation cases (to match the
5036 * GTT mapping), hence no need to account for rotation here.
5037 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005038 if (src_w != dst_w || src_h != dst_h)
5039 need_scaler = true;
Shashank Sharmae5c05932017-07-21 20:55:05 +05305040
Chandra Kondurua1b22782015-04-07 15:28:45 -07005041 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05305042 * Scaling/fitting not supported in IF-ID mode in GEN9+
5043 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
5044 * Once NV12 is enabled, handle it here while allocating scaler
5045 * for NV12.
5046 */
5047 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005048 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05305049 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
5050 return -EINVAL;
5051 }
5052
5053 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07005054 * if plane is being disabled or scaler is no more required or force detach
5055 * - free scaler binded to this plane/crtc
5056 * - in order to do this, update crtc->scaler_usage
5057 *
5058 * Here scaler state in crtc_state is set free so that
5059 * scaler can be assigned to other user. Actual register
5060 * update to free the scaler is done in plane/panel-fit programming.
5061 * For this purpose crtc/plane_state->scaler_id isn't reset here.
5062 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005063 if (force_detach || !need_scaler) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07005064 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005065 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005066 scaler_state->scalers[*scaler_id].in_use = 0;
5067
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005068 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5069 "Staged freeing scaler id %d scaler_users = 0x%x\n",
5070 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07005071 scaler_state->scaler_users);
5072 *scaler_id = -1;
5073 }
5074 return 0;
5075 }
5076
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05305077 if (format && is_planar_yuv_format(format->format) &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05305078 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05305079 DRM_DEBUG_KMS("Planar YUV: src dimensions not met\n");
Chandra Konduru77224cd2018-04-09 09:11:13 +05305080 return -EINVAL;
5081 }
5082
Chandra Kondurua1b22782015-04-07 15:28:45 -07005083 /* range checks */
5084 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07005085 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005086 (IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07005087 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
5088 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005089 (!IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07005090 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
5091 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005092 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07005093 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005094 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005095 return -EINVAL;
5096 }
5097
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005098 /* mark this plane as a scaler user in crtc_state */
5099 scaler_state->scaler_users |= (1 << scaler_user);
5100 DRM_DEBUG_KMS("scaler_user index %u.%u: "
5101 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
5102 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
5103 scaler_state->scaler_users);
5104
5105 return 0;
5106}
5107
5108/**
5109 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
5110 *
5111 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005112 *
5113 * Return
5114 * 0 - scaler_usage updated successfully
5115 * error - requested scaling cannot be supported or other error condition
5116 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005117int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005118{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03005119 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005120 bool need_scaler = false;
5121
5122 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
5123 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005124
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005125 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05305126 &state->scaler_state.scaler_id,
5127 state->pipe_src_w, state->pipe_src_h,
5128 adjusted_mode->crtc_hdisplay,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005129 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005130}
5131
5132/**
5133 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00005134 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005135 * @plane_state: atomic plane state to update
5136 *
5137 * Return
5138 * 0 - scaler_usage updated successfully
5139 * error - requested scaling cannot be supported or other error condition
5140 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02005141static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
5142 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005143{
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02005144 struct intel_plane *intel_plane =
5145 to_intel_plane(plane_state->base.plane);
Kevin Strasser42fd20e2019-03-12 17:38:31 -07005146 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005147 struct drm_framebuffer *fb = plane_state->base.fb;
5148 int ret;
Ville Syrjälä936e71e2016-07-26 19:06:59 +03005149 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005150 bool need_scaler = false;
5151
5152 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
Kevin Strasser42fd20e2019-03-12 17:38:31 -07005153 if (!icl_is_hdr_plane(dev_priv, intel_plane->id) &&
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05305154 fb && is_planar_yuv_format(fb->format->format))
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005155 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005156
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005157 ret = skl_update_scaler(crtc_state, force_detach,
5158 drm_plane_index(&intel_plane->base),
5159 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03005160 drm_rect_width(&plane_state->base.src) >> 16,
5161 drm_rect_height(&plane_state->base.src) >> 16,
5162 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05305163 drm_rect_height(&plane_state->base.dst),
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02005164 fb ? fb->format : NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005165
5166 if (ret || plane_state->scaler_id < 0)
5167 return ret;
5168
Chandra Kondurua1b22782015-04-07 15:28:45 -07005169 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02005170 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005171 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5172 intel_plane->base.base.id,
5173 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005174 return -EINVAL;
5175 }
5176
5177 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005178 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005179 case DRM_FORMAT_RGB565:
5180 case DRM_FORMAT_XBGR8888:
5181 case DRM_FORMAT_XRGB8888:
5182 case DRM_FORMAT_ABGR8888:
5183 case DRM_FORMAT_ARGB8888:
5184 case DRM_FORMAT_XRGB2101010:
5185 case DRM_FORMAT_XBGR2101010:
5186 case DRM_FORMAT_YUYV:
5187 case DRM_FORMAT_YVYU:
5188 case DRM_FORMAT_UYVY:
5189 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05305190 case DRM_FORMAT_NV12:
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +05305191 case DRM_FORMAT_P010:
5192 case DRM_FORMAT_P012:
5193 case DRM_FORMAT_P016:
Swati Sharma296e9b12019-03-04 17:26:35 +05305194 case DRM_FORMAT_Y210:
5195 case DRM_FORMAT_Y212:
5196 case DRM_FORMAT_Y216:
5197 case DRM_FORMAT_Y410:
5198 case DRM_FORMAT_Y412:
5199 case DRM_FORMAT_Y416:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005200 break;
5201 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005202 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5203 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005204 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005205 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005206 }
5207
Chandra Kondurua1b22782015-04-07 15:28:45 -07005208 return 0;
5209}
5210
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005211static void skylake_scaler_disable(struct intel_crtc *crtc)
5212{
5213 int i;
5214
5215 for (i = 0; i < crtc->num_scalers; i++)
5216 skl_detach_scaler(crtc, i);
5217}
5218
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005219static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005220{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005221 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5222 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5223 enum pipe pipe = crtc->pipe;
5224 const struct intel_crtc_scaler_state *scaler_state =
5225 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005226
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005227 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005228 u16 uv_rgb_hphase, uv_rgb_vphase;
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005229 int pfit_w, pfit_h, hscale, vscale;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005230 int id;
5231
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005232 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005233 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005234
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005235 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5236 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5237
5238 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5239 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5240
5241 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5242 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005243
Chandra Kondurua1b22782015-04-07 15:28:45 -07005244 id = scaler_state->scaler_id;
5245 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5246 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005247 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5248 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5249 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5250 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005251 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5252 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005253 }
5254}
5255
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005256static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005257{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005258 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5259 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005260 int pipe = crtc->pipe;
5261
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005262 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005263 /* Force use of hard-coded filter coefficients
5264 * as some pre-programmed values are broken,
5265 * e.g. x201.
5266 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005267 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005268 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5269 PF_PIPE_SEL_IVB(pipe));
5270 else
5271 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005272 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5273 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005274 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005275}
5276
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005277void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005278{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005279 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005280 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005281 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005282
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005283 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005284 return;
5285
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005286 /*
5287 * We can only enable IPS after we enable a plane and wait for a vblank
5288 * This function is called from post_plane_update, which is run after
5289 * a vblank wait.
5290 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005291 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005292
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005293 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005294 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005295 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5296 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005297 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005298 /* Quoting Art Runyan: "its not safe to expect any particular
5299 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005300 * mailbox." Moreover, the mailbox may return a bogus state,
5301 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005302 */
5303 } else {
5304 I915_WRITE(IPS_CTL, IPS_ENABLE);
5305 /* The bit only becomes 1 in the next vblank, so this wait here
5306 * is essentially intel_wait_for_vblank. If we don't have this
5307 * and don't wait for vblanks until the end of crtc_enable, then
5308 * the HW state readout code will complain that the expected
5309 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005310 if (intel_wait_for_register(dev_priv,
5311 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5312 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005313 DRM_ERROR("Timed out waiting for IPS enable\n");
5314 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005315}
5316
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005317void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005318{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005319 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005320 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005321 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005322
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005323 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005324 return;
5325
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005326 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005327 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005328 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005329 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005330 /*
5331 * Wait for PCODE to finish disabling IPS. The BSpec specified
5332 * 42ms timeout value leads to occasional timeouts so use 100ms
5333 * instead.
5334 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005335 if (intel_wait_for_register(dev_priv,
5336 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005337 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005338 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005339 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005340 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005341 POSTING_READ(IPS_CTL);
5342 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005343
5344 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005345 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005346}
5347
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005348static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005349{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005350 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005351 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005352
5353 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005354 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005355 mutex_unlock(&dev->struct_mutex);
5356 }
5357
5358 /* Let userspace switch the overlay on again. In most cases userspace
5359 * has to recompute where to put it anyway.
5360 */
5361}
5362
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005363/**
5364 * intel_post_enable_primary - Perform operations after enabling primary plane
5365 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005366 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005367 *
5368 * Performs potentially sleeping operations that must be done after the primary
5369 * plane is enabled, such as updating FBC and IPS. Note that this may be
5370 * called due to an explicit primary plane update, or due to an implicit
5371 * re-enable that is caused when a sprite plane is updated to no longer
5372 * completely hide the primary plane.
5373 */
5374static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005375intel_post_enable_primary(struct drm_crtc *crtc,
5376 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005377{
5378 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005379 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005380 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5381 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005382
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005383 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005384 * Gen2 reports pipe underruns whenever all planes are disabled.
5385 * So don't enable underrun reporting before at least some planes
5386 * are enabled.
5387 * FIXME: Need to fix the logic to work when we turn off all planes
5388 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005389 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005390 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005391 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5392
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005393 /* Underruns don't always raise interrupts, so check manually. */
5394 intel_check_cpu_fifo_underruns(dev_priv);
5395 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005396}
5397
Ville Syrjälä2622a082016-03-09 19:07:26 +02005398/* FIXME get rid of this and use pre_plane_update */
5399static void
5400intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5401{
5402 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005403 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005404 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5405 int pipe = intel_crtc->pipe;
5406
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005407 /*
5408 * Gen2 reports pipe underruns whenever all planes are disabled.
5409 * So disable underrun reporting before all the planes get disabled.
5410 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005411 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005412 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5413
5414 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005415
5416 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005417 * Vblank time updates from the shadow to live plane control register
5418 * are blocked if the memory self-refresh mode is active at that
5419 * moment. So to make sure the plane gets truly disabled, disable
5420 * first the self-refresh mode. The self-refresh enable bit in turn
5421 * will be checked/applied by the HW only at the next frame start
5422 * event which is after the vblank start event, so we need to have a
5423 * wait-for-vblank between disabling the plane and the pipe.
5424 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08005425 if (HAS_GMCH(dev_priv) &&
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005426 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005427 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005428}
5429
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005430static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5431 const struct intel_crtc_state *new_crtc_state)
5432{
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005433 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5435
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005436 if (!old_crtc_state->ips_enabled)
5437 return false;
5438
5439 if (needs_modeset(&new_crtc_state->base))
5440 return true;
5441
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005442 /*
5443 * Workaround : Do not read or write the pipe palette/gamma data while
5444 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5445 *
5446 * Disable IPS before we program the LUT.
5447 */
5448 if (IS_HASWELL(dev_priv) &&
5449 (new_crtc_state->base.color_mgmt_changed ||
5450 new_crtc_state->update_pipe) &&
5451 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5452 return true;
5453
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005454 return !new_crtc_state->ips_enabled;
5455}
5456
5457static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5458 const struct intel_crtc_state *new_crtc_state)
5459{
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005460 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
5461 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5462
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005463 if (!new_crtc_state->ips_enabled)
5464 return false;
5465
5466 if (needs_modeset(&new_crtc_state->base))
5467 return true;
5468
5469 /*
Ville Syrjälä051a6d82019-02-05 18:08:41 +02005470 * Workaround : Do not read or write the pipe palette/gamma data while
5471 * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled.
5472 *
5473 * Re-enable IPS after the LUT has been programmed.
5474 */
5475 if (IS_HASWELL(dev_priv) &&
5476 (new_crtc_state->base.color_mgmt_changed ||
5477 new_crtc_state->update_pipe) &&
5478 new_crtc_state->gamma_mode == GAMMA_MODE_MODE_SPLIT)
5479 return true;
5480
5481 /*
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005482 * We can't read out IPS on broadwell, assume the worst and
5483 * forcibly enable IPS on the first fastset.
5484 */
5485 if (new_crtc_state->update_pipe &&
5486 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5487 return true;
5488
5489 return !old_crtc_state->ips_enabled;
5490}
5491
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305492static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5493 const struct intel_crtc_state *crtc_state)
5494{
5495 if (!crtc_state->nv12_planes)
5496 return false;
5497
Rodrigo Vivi1347d3c2018-10-31 09:28:45 -07005498 /* WA Display #0827: Gen9:all */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005499 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305500 return true;
5501
5502 return false;
5503}
5504
Daniel Vetter5a21b662016-05-24 17:13:53 +02005505static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5506{
5507 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305508 struct drm_device *dev = crtc->base.dev;
5509 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005510 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5511 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005512 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5513 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005514 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005515 struct drm_plane_state *old_primary_state =
5516 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005517
Chris Wilson5748b6a2016-08-04 16:32:38 +01005518 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005519
Daniel Vetter5a21b662016-05-24 17:13:53 +02005520 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005521 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005522
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005523 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5524 hsw_enable_ips(pipe_config);
5525
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005526 if (old_primary_state) {
5527 struct drm_plane_state *new_primary_state =
5528 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005529
5530 intel_fbc_post_update(crtc);
5531
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005532 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005533 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005534 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005535 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005536 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305537
5538 /* Display WA 827 */
5539 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305540 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305541 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305542 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005543}
5544
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005545static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5546 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005547{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005548 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005549 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005550 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005551 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5552 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005553 struct drm_plane_state *old_primary_state =
5554 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005555 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005556 struct intel_atomic_state *old_intel_state =
5557 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005558
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005559 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5560 hsw_disable_ips(old_crtc_state);
5561
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005562 if (old_primary_state) {
5563 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005564 intel_atomic_get_new_plane_state(old_intel_state,
5565 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005566
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005567 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005568 /*
5569 * Gen2 reports pipe underruns whenever all planes are disabled.
5570 * So disable underrun reporting before all the planes get disabled.
5571 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005572 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005573 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005574 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005575 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005576
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305577 /* Display WA 827 */
5578 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305579 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305580 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b2018-05-12 03:03:13 +05305581 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305582
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005583 /*
5584 * Vblank time updates from the shadow to live plane control register
5585 * are blocked if the memory self-refresh mode is active at that
5586 * moment. So to make sure the plane gets truly disabled, disable
5587 * first the self-refresh mode. The self-refresh enable bit in turn
5588 * will be checked/applied by the HW only at the next frame start
5589 * event which is after the vblank start event, so we need to have a
5590 * wait-for-vblank between disabling the plane and the pipe.
5591 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08005592 if (HAS_GMCH(dev_priv) && old_crtc_state->base.active &&
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005593 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5594 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005595
Matt Ropered4a6a72016-02-23 17:20:13 -08005596 /*
5597 * IVB workaround: must disable low power watermarks for at least
5598 * one frame before enabling scaling. LP watermarks can be re-enabled
5599 * when scaling is disabled.
5600 *
5601 * WaCxSRDisabledForSpriteScaling:ivb
5602 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005603 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5604 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005605 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005606
5607 /*
5608 * If we're doing a modeset, we're done. No need to do any pre-vblank
5609 * watermark programming here.
5610 */
5611 if (needs_modeset(&pipe_config->base))
5612 return;
5613
5614 /*
5615 * For platforms that support atomic watermarks, program the
5616 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5617 * will be the intermediate values that are safe for both pre- and
5618 * post- vblank; when vblank happens, the 'active' values will be set
5619 * to the final 'target' values and we'll do this again to get the
5620 * optimal watermarks. For gen9+ platforms, the values we program here
5621 * will be the final target values which will get automatically latched
5622 * at vblank time; no further programming will be necessary.
5623 *
5624 * If a platform hasn't been transitioned to atomic watermarks yet,
5625 * we'll continue to update watermarks the old way, if flags tell
5626 * us to.
5627 */
5628 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005629 dev_priv->display.initial_watermarks(old_intel_state,
5630 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005631 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005632 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005633}
5634
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005635static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5636 struct intel_crtc *crtc)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005637{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005638 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5639 const struct intel_crtc_state *new_crtc_state =
5640 intel_atomic_get_new_crtc_state(state, crtc);
5641 unsigned int update_mask = new_crtc_state->update_planes;
5642 const struct intel_plane_state *old_plane_state;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005643 struct intel_plane *plane;
5644 unsigned fb_bits = 0;
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005645 int i;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005646
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005647 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005648
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005649 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5650 if (crtc->pipe != plane->pipe ||
5651 !(update_mask & BIT(plane->id)))
5652 continue;
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005653
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005654 plane->disable_plane(plane, new_crtc_state);
5655
5656 if (old_plane_state->base.visible)
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005657 fb_bits |= plane->frontbuffer_bit;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005658 }
5659
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005660 intel_frontbuffer_flip(dev_priv, fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005661}
5662
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005663static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005664 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005665 struct drm_atomic_state *old_state)
5666{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005667 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005668 struct drm_connector *conn;
5669 int i;
5670
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005671 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005672 struct intel_encoder *encoder =
5673 to_intel_encoder(conn_state->best_encoder);
5674
5675 if (conn_state->crtc != crtc)
5676 continue;
5677
5678 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005679 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005680 }
5681}
5682
5683static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005684 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005685 struct drm_atomic_state *old_state)
5686{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005687 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005688 struct drm_connector *conn;
5689 int i;
5690
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005691 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005692 struct intel_encoder *encoder =
5693 to_intel_encoder(conn_state->best_encoder);
5694
5695 if (conn_state->crtc != crtc)
5696 continue;
5697
5698 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005699 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005700 }
5701}
5702
5703static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005704 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005705 struct drm_atomic_state *old_state)
5706{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005707 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005708 struct drm_connector *conn;
5709 int i;
5710
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005711 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005712 struct intel_encoder *encoder =
5713 to_intel_encoder(conn_state->best_encoder);
5714
5715 if (conn_state->crtc != crtc)
5716 continue;
5717
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005718 if (encoder->enable)
5719 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005720 intel_opregion_notify_encoder(encoder, true);
5721 }
5722}
5723
5724static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005725 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005726 struct drm_atomic_state *old_state)
5727{
5728 struct drm_connector_state *old_conn_state;
5729 struct drm_connector *conn;
5730 int i;
5731
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005732 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005733 struct intel_encoder *encoder =
5734 to_intel_encoder(old_conn_state->best_encoder);
5735
5736 if (old_conn_state->crtc != crtc)
5737 continue;
5738
5739 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005740 if (encoder->disable)
5741 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005742 }
5743}
5744
5745static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005746 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005747 struct drm_atomic_state *old_state)
5748{
5749 struct drm_connector_state *old_conn_state;
5750 struct drm_connector *conn;
5751 int i;
5752
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005753 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005754 struct intel_encoder *encoder =
5755 to_intel_encoder(old_conn_state->best_encoder);
5756
5757 if (old_conn_state->crtc != crtc)
5758 continue;
5759
5760 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005761 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005762 }
5763}
5764
5765static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005766 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005767 struct drm_atomic_state *old_state)
5768{
5769 struct drm_connector_state *old_conn_state;
5770 struct drm_connector *conn;
5771 int i;
5772
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005773 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005774 struct intel_encoder *encoder =
5775 to_intel_encoder(old_conn_state->best_encoder);
5776
5777 if (old_conn_state->crtc != crtc)
5778 continue;
5779
5780 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005781 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005782 }
5783}
5784
Hans de Goede608ed4a2018-12-20 14:21:18 +01005785static void intel_encoders_update_pipe(struct drm_crtc *crtc,
5786 struct intel_crtc_state *crtc_state,
5787 struct drm_atomic_state *old_state)
5788{
5789 struct drm_connector_state *conn_state;
5790 struct drm_connector *conn;
5791 int i;
5792
5793 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
5794 struct intel_encoder *encoder =
5795 to_intel_encoder(conn_state->best_encoder);
5796
5797 if (conn_state->crtc != crtc)
5798 continue;
5799
5800 if (encoder->update_pipe)
5801 encoder->update_pipe(encoder, crtc_state, conn_state);
5802 }
5803}
5804
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005805static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5806 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005807{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005808 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005809 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005810 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005811 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5812 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005813 struct intel_atomic_state *old_intel_state =
5814 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005815
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005816 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005817 return;
5818
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005819 /*
5820 * Sometimes spurious CPU pipe underruns happen during FDI
5821 * training, at least with VGA+HDMI cloning. Suppress them.
5822 *
5823 * On ILK we get an occasional spurious CPU pipe underruns
5824 * between eDP port A enable and vdd enable. Also PCH port
5825 * enable seems to result in the occasional CPU pipe underrun.
5826 *
5827 * Spurious PCH underruns also occur during PCH enabling.
5828 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005829 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5830 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005831
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005832 if (pipe_config->has_pch_encoder)
5833 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005834
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005835 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005836 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005837
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005838 intel_set_pipe_timings(pipe_config);
5839 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005840
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005841 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005842 intel_cpu_transcoder_set_m_n(pipe_config,
5843 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005844 }
5845
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005846 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005847
Jesse Barnesf67a5592011-01-05 10:31:48 -08005848 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005849
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005850 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005851
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005852 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005853 /* Note: FDI PLL enabling _must_ be done before we enable the
5854 * cpu pipes, hence this is separate from all the other fdi/pch
5855 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005856 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005857 } else {
5858 assert_fdi_tx_disabled(dev_priv, pipe);
5859 assert_fdi_rx_disabled(dev_priv, pipe);
5860 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005861
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005862 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005863
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005864 /*
5865 * On ILK+ LUT must be loaded before the pipe is running but with
5866 * clocks enabled
5867 */
Matt Roper302da0c2018-12-10 13:54:15 -08005868 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02005869 intel_color_commit(pipe_config);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005870
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005871 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005872 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005873 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005874
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005875 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005876 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005877
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005878 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02005879 intel_crtc_vblank_on(pipe_config);
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005880
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005881 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005882
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005883 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005884 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005885
Ville Syrjäläea80a662018-05-24 22:04:05 +03005886 /*
5887 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5888 * And a second vblank wait is needed at least on ILK with
5889 * some interlaced HDMI modes. Let's do the double wait always
5890 * in case there are more corner cases we don't know about.
5891 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005892 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005893 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005894 intel_wait_for_vblank(dev_priv, pipe);
5895 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005896 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005897 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005898}
5899
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005900/* IPS only exists on ULT machines and is tied to pipe A. */
5901static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5902{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005903 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005904}
5905
Imre Deaked69cd42017-10-02 10:55:57 +03005906static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5907 enum pipe pipe, bool apply)
5908{
5909 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5910 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5911
5912 if (apply)
5913 val |= mask;
5914 else
5915 val &= ~mask;
5916
5917 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5918}
5919
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005920static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5921{
5922 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5923 enum pipe pipe = crtc->pipe;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02005924 u32 val;
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005925
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005926 val = MBUS_DBOX_A_CREDIT(2);
5927 val |= MBUS_DBOX_BW_CREDIT(1);
5928 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005929
5930 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5931}
5932
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005933static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5934 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005935{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005936 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005937 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005938 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005939 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005940 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005941 struct intel_atomic_state *old_intel_state =
5942 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005943 bool psl_clkgate_wa;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005944
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005945 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005946 return;
5947
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005948 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005949
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005950 if (pipe_config->shared_dpll)
5951 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005952
Paulo Zanonic8af5272018-05-02 14:58:51 -07005953 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5954
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005955 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005956 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005957
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005958 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005959 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005960
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005961 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005962
Jani Nikula4d1de972016-03-18 17:05:42 +02005963 if (cpu_transcoder != TRANSCODER_EDP &&
5964 !transcoder_is_dsi(cpu_transcoder)) {
5965 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005966 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005967 }
5968
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005969 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005970 intel_cpu_transcoder_set_m_n(pipe_config,
5971 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005972 }
5973
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005974 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005975 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005976
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005977 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005978
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005979 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005980
Imre Deaked69cd42017-10-02 10:55:57 +03005981 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5982 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005983 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005984 if (psl_clkgate_wa)
5985 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5986
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005987 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005988 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005989 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005990 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005991
5992 /*
5993 * On ILK+ LUT must be loaded before the pipe is running but with
5994 * clocks enabled
5995 */
Matt Roper302da0c2018-12-10 13:54:15 -08005996 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02005997 intel_color_commit(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005998
Ville Syrjäläd1622112019-02-04 22:21:39 +02005999 if (INTEL_GEN(dev_priv) >= 11)
6000 icl_set_pipe_chicken(intel_crtc);
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05306001
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02006002 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006003 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02006004 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006005
Imre Deak1d5bf5d2016-02-29 22:10:33 +02006006 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02006007 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02006008
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02006009 if (INTEL_GEN(dev_priv) >= 11)
6010 icl_pipe_mbus_enable(intel_crtc);
6011
Jani Nikula4d1de972016-03-18 17:05:42 +02006012 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006013 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02006014 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006015
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006016 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03006017 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006018
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006019 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02006020 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10006021
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006022 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02006023 intel_crtc_vblank_on(pipe_config);
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006024
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006025 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006026
Imre Deaked69cd42017-10-02 10:55:57 +03006027 if (psl_clkgate_wa) {
6028 intel_wait_for_vblank(dev_priv, pipe);
6029 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
6030 }
6031
Paulo Zanonie4916942013-09-20 16:21:19 -03006032 /* If we change the relative order between pipe/planes enabling, we need
6033 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02006034 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01006035 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006036 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
6037 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02006038 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006039}
6040
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006041static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02006042{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006043 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6044 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6045 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02006046
6047 /* To avoid upsetting the power well on haswell only disable the pfit if
6048 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006049 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02006050 I915_WRITE(PF_CTL(pipe), 0);
6051 I915_WRITE(PF_WIN_POS(pipe), 0);
6052 I915_WRITE(PF_WIN_SZ(pipe), 0);
6053 }
6054}
6055
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006056static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
6057 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07006058{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006059 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07006060 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006061 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006062 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6063 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07006064
Ville Syrjäläb2c05932016-04-01 21:53:17 +03006065 /*
6066 * Sometimes spurious CPU pipe underruns happen when the
6067 * pipe is already disabled, but FDI RX/TX is still enabled.
6068 * Happens at least with VGA+HDMI cloning. Suppress them.
6069 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03006070 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
6071 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02006072
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006073 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02006074
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006075 drm_crtc_vblank_off(crtc);
6076 assert_vblank_disabled(crtc);
6077
Ville Syrjälä4972f702017-11-29 17:37:32 +02006078 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006079
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006080 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006081
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006082 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03006083 ironlake_fdi_disable(crtc);
6084
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006085 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006086
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006087 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02006088 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006089
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01006090 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02006091 i915_reg_t reg;
6092 u32 temp;
6093
Daniel Vetterd925c592013-06-05 13:34:04 +02006094 /* disable TRANS_DP_CTL */
6095 reg = TRANS_DP_CTL(pipe);
6096 temp = I915_READ(reg);
6097 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
6098 TRANS_DP_PORT_SEL_MASK);
6099 temp |= TRANS_DP_PORT_SEL_NONE;
6100 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006101
Daniel Vetterd925c592013-06-05 13:34:04 +02006102 /* disable DPLL_SEL */
6103 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02006104 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02006105 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08006106 }
Daniel Vetterd925c592013-06-05 13:34:04 +02006107
Daniel Vetterd925c592013-06-05 13:34:04 +02006108 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006109 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02006110
Ville Syrjäläb2c05932016-04-01 21:53:17 +03006111 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02006112 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07006113}
6114
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006115static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
6116 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006117{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006118 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006119 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006120 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03006121 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006122
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006123 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006124
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006125 drm_crtc_vblank_off(crtc);
6126 assert_vblank_disabled(crtc);
6127
Jani Nikula4d1de972016-03-18 17:05:42 +02006128 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006129 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02006130 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006131
Imre Deak24a28172018-06-13 20:07:06 +03006132 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
6133 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03006134
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006135 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07006136 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006137
Manasi Navarea6006222018-11-28 12:26:23 -08006138 intel_dsc_disable(old_crtc_state);
6139
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006140 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02006141 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08006142 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006143 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006144
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006145 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07006146
Imre Deakbdaa29b2018-11-01 16:04:24 +02006147 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02006148}
6149
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006150static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07006151{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006152 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6153 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006154
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006155 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07006156 return;
6157
Daniel Vetterc0b03412013-05-28 12:05:54 +02006158 /*
6159 * The panel fitter should only be adjusted whilst the pipe is disabled,
6160 * according to register description and PRM.
6161 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07006162 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
6163 assert_pipe_disabled(dev_priv, crtc->pipe);
6164
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006165 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
6166 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02006167
6168 /* Border color in case we don't scale up to the full screen. Black by
6169 * default, change to something else for debugging. */
6170 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006171}
6172
Mahesh Kumar176597a2018-10-04 14:20:43 +05306173bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
6174{
6175 if (port == PORT_NONE)
6176 return false;
6177
6178 if (IS_ICELAKE(dev_priv))
6179 return port <= PORT_B;
6180
6181 return false;
6182}
6183
Paulo Zanoniac213c12018-05-21 17:25:37 -07006184bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
6185{
6186 if (IS_ICELAKE(dev_priv))
6187 return port >= PORT_C && port <= PORT_F;
6188
6189 return false;
6190}
6191
6192enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
6193{
6194 if (!intel_port_is_tc(dev_priv, port))
6195 return PORT_TC_NONE;
6196
6197 return port - PORT_C;
6198}
6199
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006200enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10006201{
6202 switch (port) {
6203 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006204 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006205 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006206 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006207 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006208 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006209 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006210 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08006211 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01006212 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08006213 case PORT_F:
6214 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006215 default:
Imre Deakb9fec162015-11-18 15:57:25 +02006216 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10006217 return POWER_DOMAIN_PORT_OTHER;
6218 }
6219}
6220
Imre Deak337837a2018-11-01 16:04:23 +02006221enum intel_display_power_domain
6222intel_aux_power_domain(struct intel_digital_port *dig_port)
6223{
6224 switch (dig_port->aux_ch) {
6225 case AUX_CH_A:
6226 return POWER_DOMAIN_AUX_A;
6227 case AUX_CH_B:
6228 return POWER_DOMAIN_AUX_B;
6229 case AUX_CH_C:
6230 return POWER_DOMAIN_AUX_C;
6231 case AUX_CH_D:
6232 return POWER_DOMAIN_AUX_D;
6233 case AUX_CH_E:
6234 return POWER_DOMAIN_AUX_E;
6235 case AUX_CH_F:
6236 return POWER_DOMAIN_AUX_F;
6237 default:
6238 MISSING_CASE(dig_port->aux_ch);
6239 return POWER_DOMAIN_AUX_A;
6240 }
6241}
6242
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006243static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6244 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02006245{
6246 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006247 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006248 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02006249 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6250 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006251 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006252 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02006253
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006254 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006255 return 0;
6256
Imre Deak17bd6e62018-01-09 14:20:40 +02006257 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6258 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006259 if (crtc_state->pch_pfit.enabled ||
6260 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006261 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02006262
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006263 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6264 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6265
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006266 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006267 }
Imre Deak319be8a2014-03-04 19:22:57 +02006268
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006269 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02006270 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006271
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006272 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006273 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006274
Imre Deak77d22dc2014-03-05 16:20:52 +02006275 return mask;
6276}
6277
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006278static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006279modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6280 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006281{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006282 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006283 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6284 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006285 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006286
6287 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006288 intel_crtc->enabled_power_domains = new_domains =
6289 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006290
Daniel Vetter5a21b662016-05-24 17:13:53 +02006291 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006292
6293 for_each_power_domain(domain, domains)
6294 intel_display_power_get(dev_priv, domain);
6295
Daniel Vetter5a21b662016-05-24 17:13:53 +02006296 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006297}
6298
6299static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006300 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006301{
6302 enum intel_display_power_domain domain;
6303
6304 for_each_power_domain(domain, domains)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00006305 intel_display_power_put_unchecked(dev_priv, domain);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006306}
6307
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006308static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6309 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006310{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006311 struct intel_atomic_state *old_intel_state =
6312 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006313 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006314 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006315 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006316 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006317 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006318
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006319 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006320 return;
6321
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006322 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006323 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006324
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006325 intel_set_pipe_timings(pipe_config);
6326 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006327
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006328 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006329 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6330 I915_WRITE(CHV_CANVAS(pipe), 0);
6331 }
6332
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006333 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006334
Jesse Barnes89b667f2013-04-18 14:51:36 -07006335 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006336
Daniel Vettera72e4c92014-09-30 10:56:47 +02006337 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006338
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006339 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006340
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006341 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006342 chv_prepare_pll(intel_crtc, pipe_config);
6343 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006344 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006345 vlv_prepare_pll(intel_crtc, pipe_config);
6346 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006347 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006348
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006349 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006350
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006351 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006352
Matt Roper302da0c2018-12-10 13:54:15 -08006353 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02006354 intel_color_commit(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006355
Ville Syrjäläff32c542017-03-02 19:14:57 +02006356 dev_priv->display.initial_watermarks(old_intel_state,
6357 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006358 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006359
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006360 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02006361 intel_crtc_vblank_on(pipe_config);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006362
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006363 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006364}
6365
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006366static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006367{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006368 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6369 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006370
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006371 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6372 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006373}
6374
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006375static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6376 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006377{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006378 struct intel_atomic_state *old_intel_state =
6379 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006380 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006381 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006382 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006383 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006384 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006385
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006386 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006387 return;
6388
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006389 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006390
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006391 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006392 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006393
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006394 intel_set_pipe_timings(pipe_config);
6395 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006396
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006397 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006398
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006399 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006400
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006401 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006402 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006403
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006404 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006405
Ville Syrjälä939994d2017-09-13 17:08:56 +03006406 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006407
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006408 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006409
Matt Roper302da0c2018-12-10 13:54:15 -08006410 intel_color_load_luts(pipe_config);
Ville Syrjälä4d8ed542019-02-05 18:08:40 +02006411 intel_color_commit(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006412
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006413 if (dev_priv->display.initial_watermarks != NULL)
6414 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006415 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006416 else
6417 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006418 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006419
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006420 assert_vblank_disabled(crtc);
Ville Syrjälä32db0b62018-11-27 22:05:50 +02006421 intel_crtc_vblank_on(pipe_config);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006422
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006423 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006424}
6425
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006426static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006427{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006428 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6429 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006430
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006431 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006432 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006433
6434 assert_pipe_disabled(dev_priv, crtc->pipe);
6435
Chris Wilson43031782018-09-13 14:16:26 +01006436 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6437 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006438 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006439}
6440
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006441static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6442 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006443{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006444 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006445 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006446 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006447 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6448 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006449
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006450 /*
6451 * On gen2 planes are double buffered but the pipe isn't, so we must
6452 * wait for planes to fully turn off before disabling the pipe.
6453 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006454 if (IS_GEN(dev_priv, 2))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006455 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006456
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006457 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006458
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006459 drm_crtc_vblank_off(crtc);
6460 assert_vblank_disabled(crtc);
6461
Ville Syrjälä4972f702017-11-29 17:37:32 +02006462 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006463
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006464 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006465
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006466 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006467
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006468 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006469 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006470 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006471 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006472 vlv_disable_pll(dev_priv, pipe);
6473 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006474 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006475 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006476
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006477 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006478
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006479 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006480 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006481
6482 if (!dev_priv->display.initial_watermarks)
6483 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006484
6485 /* clock the pipe down to 640x480@60 to potentially save power */
6486 if (IS_I830(dev_priv))
6487 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006488}
6489
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006490static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6491 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006492{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006493 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006494 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006495 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006496 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006497 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006498 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006499 struct drm_atomic_state *state;
6500 struct intel_crtc_state *crtc_state;
6501 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006502
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006503 if (!intel_crtc->active)
6504 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006505
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006506 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6507 const struct intel_plane_state *plane_state =
6508 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006509
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006510 if (plane_state->base.visible)
6511 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006512 }
6513
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006514 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006515 if (!state) {
6516 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6517 crtc->base.id, crtc->name);
6518 return;
6519 }
6520
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006521 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006522
6523 /* Everything's already locked, -EDEADLK can't happen. */
6524 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6525 ret = drm_atomic_add_affected_connectors(state, crtc);
6526
6527 WARN_ON(IS_ERR(crtc_state) || ret);
6528
6529 dev_priv->display.crtc_disable(crtc_state, state);
6530
Chris Wilson08536952016-10-14 13:18:18 +01006531 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006532
Ville Syrjälä78108b72016-05-27 20:59:19 +03006533 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6534 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006535
6536 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6537 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006538 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006539 crtc->enabled = false;
6540 crtc->state->connector_mask = 0;
6541 crtc->state->encoder_mask = 0;
6542
6543 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6544 encoder->base.crtc = NULL;
6545
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006546 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006547 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006548 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006549
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006550 domains = intel_crtc->enabled_power_domains;
6551 for_each_power_domain(domain, domains)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00006552 intel_display_power_put_unchecked(dev_priv, domain);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006553 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006554
6555 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006556 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006557 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006558}
6559
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006560/*
6561 * turn all crtc's off, but do not adjust state
6562 * This has to be paired with a call to intel_modeset_setup_hw_state.
6563 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006564int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006565{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006566 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006567 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006568 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006569
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006570 state = drm_atomic_helper_suspend(dev);
6571 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006572 if (ret)
6573 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006574 else
6575 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006576 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006577}
6578
Chris Wilsonea5b2132010-08-04 13:50:23 +01006579void intel_encoder_destroy(struct drm_encoder *encoder)
6580{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006581 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006582
Chris Wilsonea5b2132010-08-04 13:50:23 +01006583 drm_encoder_cleanup(encoder);
6584 kfree(intel_encoder);
6585}
6586
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006587/* Cross check the actual hw state with our own modeset state tracking (and it's
6588 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006589static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6590 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006591{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006592 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006593
6594 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6595 connector->base.base.id,
6596 connector->base.name);
6597
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006598 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006599 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006600
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006601 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006602 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006603
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006604 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006605 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006606
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006607 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006608 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006609
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006610 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006611 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006612
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006613 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006614 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006615
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006616 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006617 "attached encoder crtc differs from connector crtc\n");
6618 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006619 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006620 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006621 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006622 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006623 }
6624}
6625
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006626static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006627{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006628 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6629 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006630
6631 return 0;
6632}
6633
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006634static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006635 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006636{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006637 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006638 struct drm_atomic_state *state = pipe_config->base.state;
6639 struct intel_crtc *other_crtc;
6640 struct intel_crtc_state *other_crtc_state;
6641
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006642 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6643 pipe_name(pipe), pipe_config->fdi_lanes);
6644 if (pipe_config->fdi_lanes > 4) {
6645 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6646 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006647 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006648 }
6649
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006650 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006651 if (pipe_config->fdi_lanes > 2) {
6652 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6653 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006654 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006655 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006656 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006657 }
6658 }
6659
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006660 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006661 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006662
6663 /* Ivybridge 3 pipe is really complicated */
6664 switch (pipe) {
6665 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006666 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006667 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006668 if (pipe_config->fdi_lanes <= 2)
6669 return 0;
6670
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006671 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006672 other_crtc_state =
6673 intel_atomic_get_crtc_state(state, other_crtc);
6674 if (IS_ERR(other_crtc_state))
6675 return PTR_ERR(other_crtc_state);
6676
6677 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006678 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6679 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006680 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006681 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006682 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006683 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006684 if (pipe_config->fdi_lanes > 2) {
6685 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6686 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006687 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006688 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006689
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006690 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006691 other_crtc_state =
6692 intel_atomic_get_crtc_state(state, other_crtc);
6693 if (IS_ERR(other_crtc_state))
6694 return PTR_ERR(other_crtc_state);
6695
6696 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006697 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006698 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006699 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006700 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006701 default:
6702 BUG();
6703 }
6704}
6705
Daniel Vettere29c22c2013-02-21 00:00:16 +01006706#define RETRY 1
6707static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006708 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006709{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006710 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006711 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006712 int lane, link_bw, fdi_dotclock, ret;
6713 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006714
Daniel Vettere29c22c2013-02-21 00:00:16 +01006715retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006716 /* FDI is a binary signal running at ~2.7GHz, encoding
6717 * each output octet as 10 bits. The actual frequency
6718 * is stored as a divider into a 100MHz clock, and the
6719 * mode pixel clock is stored in units of 1KHz.
6720 * Hence the bw of each lane in terms of the mode signal
6721 * is:
6722 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006723 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006724
Damien Lespiau241bfc32013-09-25 16:45:37 +01006725 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006726
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006727 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006728 pipe_config->pipe_bpp);
6729
6730 pipe_config->fdi_lanes = lane;
6731
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006732 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006733 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006734
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006735 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +02006736 if (ret == -EDEADLK)
6737 return ret;
6738
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006739 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006740 pipe_config->pipe_bpp -= 2*3;
6741 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6742 pipe_config->pipe_bpp);
6743 needs_recompute = true;
6744 pipe_config->bw_constrained = true;
6745
6746 goto retry;
6747 }
6748
6749 if (needs_recompute)
6750 return RETRY;
6751
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006752 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006753}
6754
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006755bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006756{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006757 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6758 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6759
6760 /* IPS only exists on ULT machines and is tied to pipe A. */
6761 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006762 return false;
6763
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006764 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006765 return false;
6766
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006767 if (crtc_state->pipe_bpp > 24)
6768 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006769
6770 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006771 * We compare against max which means we must take
6772 * the increased cdclk requirement into account when
6773 * calculating the new cdclk.
6774 *
6775 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006776 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006777 if (IS_BROADWELL(dev_priv) &&
6778 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6779 return false;
6780
6781 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006782}
6783
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006784static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006785{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006786 struct drm_i915_private *dev_priv =
6787 to_i915(crtc_state->base.crtc->dev);
6788 struct intel_atomic_state *intel_state =
6789 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006790
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006791 if (!hsw_crtc_state_ips_capable(crtc_state))
6792 return false;
6793
6794 if (crtc_state->ips_force_disable)
6795 return false;
6796
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006797 /* IPS should be fine as long as at least one plane is enabled. */
6798 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006799 return false;
6800
6801 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6802 if (IS_BROADWELL(dev_priv) &&
6803 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6804 return false;
6805
6806 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006807}
6808
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006809static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6810{
6811 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6812
6813 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006814 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006815 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6816}
6817
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006818static u32 ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
Ville Syrjäläceb99322017-01-20 20:22:05 +02006819{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006820 u32 pixel_rate;
Ville Syrjäläceb99322017-01-20 20:22:05 +02006821
6822 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6823
6824 /*
6825 * We only use IF-ID interlacing. If we ever use
6826 * PF-ID we'll need to adjust the pixel_rate here.
6827 */
6828
6829 if (pipe_config->pch_pfit.enabled) {
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006830 u64 pipe_w, pipe_h, pfit_w, pfit_h;
6831 u32 pfit_size = pipe_config->pch_pfit.size;
Ville Syrjäläceb99322017-01-20 20:22:05 +02006832
6833 pipe_w = pipe_config->pipe_src_w;
6834 pipe_h = pipe_config->pipe_src_h;
6835
6836 pfit_w = (pfit_size >> 16) & 0xFFFF;
6837 pfit_h = pfit_size & 0xFFFF;
6838 if (pipe_w < pfit_w)
6839 pipe_w = pfit_w;
6840 if (pipe_h < pfit_h)
6841 pipe_h = pfit_h;
6842
6843 if (WARN_ON(!pfit_w || !pfit_h))
6844 return pixel_rate;
6845
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006846 pixel_rate = div_u64((u64)pixel_rate * pipe_w * pipe_h,
Ville Syrjäläceb99322017-01-20 20:22:05 +02006847 pfit_w * pfit_h);
6848 }
6849
6850 return pixel_rate;
6851}
6852
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006853static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6854{
6855 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6856
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08006857 if (HAS_GMCH(dev_priv))
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006858 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6859 crtc_state->pixel_rate =
6860 crtc_state->base.adjusted_mode.crtc_clock;
6861 else
6862 crtc_state->pixel_rate =
6863 ilk_pipe_pixel_rate(crtc_state);
6864}
6865
Daniel Vettera43f6e02013-06-07 23:10:32 +02006866static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006867 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006868{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006869 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006870 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006871 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006872 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006873
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006874 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006875 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006876
6877 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006878 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006879 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006880 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006881 if (intel_crtc_supports_double_wide(crtc) &&
6882 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006883 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006884 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006885 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006886 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006887
Ville Syrjäläf3261152016-05-24 21:34:18 +03006888 if (adjusted_mode->crtc_clock > clock_limit) {
6889 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6890 adjusted_mode->crtc_clock, clock_limit,
6891 yesno(pipe_config->double_wide));
6892 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006893 }
Chris Wilson89749352010-09-12 18:25:19 +01006894
Shashank Sharma8c79f842018-10-12 11:53:09 +05306895 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6896 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6897 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306898 /*
6899 * There is only one pipe CSC unit per pipe, and we need that
6900 * for output conversion from RGB->YCBCR. So if CTM is already
6901 * applied we can't support YCBCR420 output.
6902 */
6903 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6904 return -EINVAL;
6905 }
6906
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006907 /*
6908 * Pipe horizontal size must be even in:
6909 * - DVO ganged mode
6910 * - LVDS dual channel mode
6911 * - Double wide pipe
6912 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006913 if (pipe_config->pipe_src_w & 1) {
6914 if (pipe_config->double_wide) {
6915 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6916 return -EINVAL;
6917 }
6918
6919 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6920 intel_is_dual_link_lvds(dev)) {
6921 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6922 return -EINVAL;
6923 }
6924 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006925
Damien Lespiau8693a822013-05-03 18:48:11 +01006926 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6927 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006928 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006929 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006930 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006931 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006932
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006933 intel_crtc_compute_pixel_rate(pipe_config);
6934
Daniel Vetter877d48d2013-04-19 11:24:43 +02006935 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006936 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006937
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006938 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006939}
6940
Zhenyu Wang2c072452009-06-05 15:38:42 +08006941static void
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006942intel_reduce_m_n_ratio(u32 *num, u32 *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006943{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006944 while (*num > DATA_LINK_M_N_MASK ||
6945 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006946 *num >>= 1;
6947 *den >>= 1;
6948 }
6949}
6950
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006951static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006952 u32 *ret_m, u32 *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006953 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006954{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006955 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006956 * Several DP dongles in particular seem to be fussy about
6957 * too large link M/N values. Give N value as 0x8000 that
6958 * should be acceptable by specific devices. 0x8000 is the
6959 * specified fixed N value for asynchronous clock mode,
6960 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006961 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006962 if (constant_n)
6963 *ret_n = 0x8000;
6964 else
6965 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006966
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006967 *ret_m = div_u64((u64)m * *ret_n, n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006968 intel_reduce_m_n_ratio(ret_m, ret_n);
6969}
6970
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006971void
Manasi Navarea4a15772018-11-28 13:36:21 -08006972intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006973 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006974 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006975 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006976{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006977 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006978
6979 compute_m_n(bits_per_pixel * pixel_clock,
6980 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006981 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006982 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006983
6984 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006985 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006986 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006987}
6988
Chris Wilsona7615032011-01-12 17:04:08 +00006989static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6990{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006991 if (i915_modparams.panel_use_ssc >= 0)
6992 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006993 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006994 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006995}
6996
Jani Nikulaba3f4d02019-01-18 14:01:23 +02006997static u32 pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006998{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006999 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02007000}
Daniel Vetterf47709a2013-03-28 10:42:02 +01007001
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007002static u32 i9xx_dpll_compute_fp(struct dpll *dpll)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02007003{
7004 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08007005}
7006
Daniel Vetterf47709a2013-03-28 10:42:02 +01007007static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007008 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007009 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08007010{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007011 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08007012 u32 fp, fp2 = 0;
7013
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007014 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007015 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08007016 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02007017 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08007018 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007019 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08007020 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02007021 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08007022 }
7023
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007024 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08007025
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007026 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07007027 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007028 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08007029 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007030 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08007031 }
7032}
7033
Chon Ming Lee5e69f972013-09-05 20:41:49 +08007034static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
7035 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07007036{
7037 u32 reg_val;
7038
7039 /*
7040 * PLLB opamp always calibrates to max value of 0x3f, force enable it
7041 * and set it to a reasonable value instead.
7042 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007043 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007044 reg_val &= 0xffffff00;
7045 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007046 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007047
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007048 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03007049 reg_val &= 0x00ffffff;
7050 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007051 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007052
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007053 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007054 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007055 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007056
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007057 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007058 reg_val &= 0x00ffffff;
7059 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007060 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007061}
7062
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007063static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7064 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02007065{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007066 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7067 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7068 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02007069
Daniel Vettere3b95f12013-05-03 11:49:49 +02007070 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7071 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
7072 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
7073 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02007074}
7075
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007076static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
7077 enum transcoder transcoder)
7078{
7079 if (IS_HASWELL(dev_priv))
7080 return transcoder == TRANSCODER_EDP;
7081
7082 /*
7083 * Strictly speaking some registers are available before
7084 * gen7, but we only support DRRS on gen7+
7085 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08007086 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007087}
7088
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007089static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
7090 const struct intel_link_m_n *m_n,
7091 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02007092{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007093 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007094 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007095 enum pipe pipe = crtc->pipe;
7096 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02007097
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007098 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02007099 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
7100 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
7101 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
7102 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007103 /*
7104 * M2_N2 registers are set only if DRRS is supported
7105 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07007106 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02007107 if (m2_n2 && crtc_state->has_drrs &&
7108 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07007109 I915_WRITE(PIPE_DATA_M2(transcoder),
7110 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
7111 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
7112 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
7113 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
7114 }
Daniel Vetterb5518422013-05-03 11:49:48 +02007115 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02007116 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
7117 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
7118 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
7119 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02007120 }
7121}
7122
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007123void 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 +02007124{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007125 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307126
7127 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007128 dp_m_n = &crtc_state->dp_m_n;
7129 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307130 } else if (m_n == M2_N2) {
7131
7132 /*
7133 * M2_N2 registers are not supported. Hence m2_n2 divider value
7134 * needs to be programmed into M1_N1.
7135 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007136 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05307137 } else {
7138 DRM_ERROR("Unsupported divider value\n");
7139 return;
7140 }
7141
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007142 if (crtc_state->has_pch_encoder)
7143 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02007144 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02007145 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02007146}
7147
Daniel Vetter251ac862015-06-18 10:30:24 +02007148static void vlv_compute_dpll(struct intel_crtc *crtc,
7149 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007150{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007151 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007152 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007153 if (crtc->pipe != PIPE_A)
7154 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007155
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007156 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03007157 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007158 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
7159 DPLL_EXT_BUFFER_ENABLE_VLV;
7160
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007161 pipe_config->dpll_hw_state.dpll_md =
7162 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
7163}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007164
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007165static void chv_compute_dpll(struct intel_crtc *crtc,
7166 struct intel_crtc_state *pipe_config)
7167{
7168 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007169 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007170 if (crtc->pipe != PIPE_A)
7171 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
7172
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007173 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03007174 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007175 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
7176
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02007177 pipe_config->dpll_hw_state.dpll_md =
7178 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007179}
7180
Ville Syrjäläd288f652014-10-28 13:20:22 +02007181static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007182 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007183{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007184 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007185 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007186 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007187 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007188 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007189 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007190
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007191 /* Enable Refclk */
7192 I915_WRITE(DPLL(pipe),
7193 pipe_config->dpll_hw_state.dpll &
7194 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
7195
7196 /* No need to actually set up the DPLL with DSI */
7197 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7198 return;
7199
Ville Syrjäläa5805162015-05-26 20:42:30 +03007200 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01007201
Ville Syrjäläd288f652014-10-28 13:20:22 +02007202 bestn = pipe_config->dpll.n;
7203 bestm1 = pipe_config->dpll.m1;
7204 bestm2 = pipe_config->dpll.m2;
7205 bestp1 = pipe_config->dpll.p1;
7206 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007207
Jesse Barnes89b667f2013-04-18 14:51:36 -07007208 /* See eDP HDMI DPIO driver vbios notes doc */
7209
7210 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007211 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08007212 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007213
7214 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007215 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007216
7217 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007218 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007219 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007220 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007221
7222 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007223 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007224
7225 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007226 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7227 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7228 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007229 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07007230
7231 /*
7232 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7233 * but we don't support that).
7234 * Note: don't use the DAC post divider as it seems unstable.
7235 */
7236 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007237 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007238
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007239 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007240 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007241
Jesse Barnes89b667f2013-04-18 14:51:36 -07007242 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02007243 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007244 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7245 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007246 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03007247 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007248 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007249 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007250 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007251
Ville Syrjälä37a56502016-06-22 21:57:04 +03007252 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07007253 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007254 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007255 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007256 0x0df40000);
7257 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007258 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007259 0x0df70000);
7260 } else { /* HDMI or VGA */
7261 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007262 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007263 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007264 0x0df70000);
7265 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007266 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007267 0x0df40000);
7268 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007269
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007270 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007271 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007272 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07007273 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007274 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007275
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007276 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03007277 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007278}
7279
Ville Syrjäläd288f652014-10-28 13:20:22 +02007280static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007281 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03007282{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007283 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007284 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007285 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007286 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307287 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007288 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307289 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307290 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007291
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007292 /* Enable Refclk and SSC */
7293 I915_WRITE(DPLL(pipe),
7294 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7295
7296 /* No need to actually set up the DPLL with DSI */
7297 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7298 return;
7299
Ville Syrjäläd288f652014-10-28 13:20:22 +02007300 bestn = pipe_config->dpll.n;
7301 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7302 bestm1 = pipe_config->dpll.m1;
7303 bestm2 = pipe_config->dpll.m2 >> 22;
7304 bestp1 = pipe_config->dpll.p1;
7305 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307306 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307307 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307308 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007309
Ville Syrjäläa5805162015-05-26 20:42:30 +03007310 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007311
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007312 /* p1 and p2 divider */
7313 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7314 5 << DPIO_CHV_S1_DIV_SHIFT |
7315 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7316 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7317 1 << DPIO_CHV_K_DIV_SHIFT);
7318
7319 /* Feedback post-divider - m2 */
7320 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7321
7322 /* Feedback refclk divider - n and m1 */
7323 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7324 DPIO_CHV_M1_DIV_BY_2 |
7325 1 << DPIO_CHV_N_DIV_SHIFT);
7326
7327 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007328 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007329
7330 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307331 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7332 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7333 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7334 if (bestm2_frac)
7335 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7336 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007337
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307338 /* Program digital lock detect threshold */
7339 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7340 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7341 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7342 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7343 if (!bestm2_frac)
7344 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7345 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7346
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007347 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307348 if (vco == 5400000) {
7349 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7350 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7351 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7352 tribuf_calcntr = 0x9;
7353 } else if (vco <= 6200000) {
7354 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7355 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7356 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7357 tribuf_calcntr = 0x9;
7358 } else if (vco <= 6480000) {
7359 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7360 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7361 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7362 tribuf_calcntr = 0x8;
7363 } else {
7364 /* Not supported. Apply the same limits as in the max case */
7365 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7366 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7367 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7368 tribuf_calcntr = 0;
7369 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007370 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7371
Ville Syrjälä968040b2015-03-11 22:52:08 +02007372 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307373 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7374 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7375 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7376
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007377 /* AFC Recal */
7378 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7379 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7380 DPIO_AFC_RECAL);
7381
Ville Syrjäläa5805162015-05-26 20:42:30 +03007382 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007383}
7384
Ville Syrjäläd288f652014-10-28 13:20:22 +02007385/**
7386 * vlv_force_pll_on - forcibly enable just the PLL
7387 * @dev_priv: i915 private structure
7388 * @pipe: pipe PLL to enable
7389 * @dpll: PLL configuration
7390 *
7391 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7392 * in cases where we need the PLL enabled even when @pipe is not going to
7393 * be enabled.
7394 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007395int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007396 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007397{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007398 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007399 struct intel_crtc_state *pipe_config;
7400
7401 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7402 if (!pipe_config)
7403 return -ENOMEM;
7404
7405 pipe_config->base.crtc = &crtc->base;
7406 pipe_config->pixel_multiplier = 1;
7407 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007408
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007409 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007410 chv_compute_dpll(crtc, pipe_config);
7411 chv_prepare_pll(crtc, pipe_config);
7412 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007413 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007414 vlv_compute_dpll(crtc, pipe_config);
7415 vlv_prepare_pll(crtc, pipe_config);
7416 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007417 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007418
7419 kfree(pipe_config);
7420
7421 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007422}
7423
7424/**
7425 * vlv_force_pll_off - forcibly disable just the PLL
7426 * @dev_priv: i915 private structure
7427 * @pipe: pipe PLL to disable
7428 *
7429 * Disable the PLL for @pipe. To be used in cases where we need
7430 * the PLL enabled even when @pipe is not going to be enabled.
7431 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007432void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007433{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007434 if (IS_CHERRYVIEW(dev_priv))
7435 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007436 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007437 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007438}
7439
Daniel Vetter251ac862015-06-18 10:30:24 +02007440static void i9xx_compute_dpll(struct intel_crtc *crtc,
7441 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007442 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007443{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007444 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007445 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007446 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007447
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007448 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307449
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007450 dpll = DPLL_VGA_MODE_DIS;
7451
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007452 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007453 dpll |= DPLLB_MODE_LVDS;
7454 else
7455 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007456
Jani Nikula73f67aa2016-12-07 22:48:09 +02007457 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7458 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007459 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007460 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007461 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007462
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007463 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7464 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007465 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007466
Ville Syrjälä37a56502016-06-22 21:57:04 +03007467 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007468 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007469
7470 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007471 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007472 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7473 else {
7474 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007475 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007476 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7477 }
7478 switch (clock->p2) {
7479 case 5:
7480 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7481 break;
7482 case 7:
7483 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7484 break;
7485 case 10:
7486 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7487 break;
7488 case 14:
7489 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7490 break;
7491 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007492 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007493 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7494
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007495 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007496 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007497 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007498 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007499 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7500 else
7501 dpll |= PLL_REF_INPUT_DREFCLK;
7502
7503 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007504 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007505
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007506 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007507 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007508 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007509 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007510 }
7511}
7512
Daniel Vetter251ac862015-06-18 10:30:24 +02007513static void i8xx_compute_dpll(struct intel_crtc *crtc,
7514 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007515 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007516{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007517 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007518 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007519 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007520 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007521
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007522 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307523
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007524 dpll = DPLL_VGA_MODE_DIS;
7525
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007526 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007527 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7528 } else {
7529 if (clock->p1 == 2)
7530 dpll |= PLL_P1_DIVIDE_BY_TWO;
7531 else
7532 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7533 if (clock->p2 == 4)
7534 dpll |= PLL_P2_DIVIDE_BY_4;
7535 }
7536
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007537 if (!IS_I830(dev_priv) &&
7538 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007539 dpll |= DPLL_DVO_2X_MODE;
7540
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007541 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007542 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007543 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7544 else
7545 dpll |= PLL_REF_INPUT_DREFCLK;
7546
7547 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007548 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007549}
7550
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007551static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007552{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007553 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7554 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7555 enum pipe pipe = crtc->pipe;
7556 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7557 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007558 u32 crtc_vtotal, crtc_vblank_end;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007559 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007560
7561 /* We need to be careful not to changed the adjusted mode, for otherwise
7562 * the hw state checker will get angry at the mismatch. */
7563 crtc_vtotal = adjusted_mode->crtc_vtotal;
7564 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007565
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007566 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007567 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007568 crtc_vtotal -= 1;
7569 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007570
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007571 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007572 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7573 else
7574 vsyncshift = adjusted_mode->crtc_hsync_start -
7575 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007576 if (vsyncshift < 0)
7577 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007578 }
7579
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007580 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007581 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007582
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007583 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007584 (adjusted_mode->crtc_hdisplay - 1) |
7585 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007586 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007587 (adjusted_mode->crtc_hblank_start - 1) |
7588 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007589 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007590 (adjusted_mode->crtc_hsync_start - 1) |
7591 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7592
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007593 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007594 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007595 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007596 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007597 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007598 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007599 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007600 (adjusted_mode->crtc_vsync_start - 1) |
7601 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7602
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007603 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7604 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7605 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7606 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007607 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007608 (pipe == PIPE_B || pipe == PIPE_C))
7609 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7610
Jani Nikulabc58be62016-03-18 17:05:39 +02007611}
7612
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007613static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007614{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007615 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7616 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7617 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007618
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007619 /* pipesrc controls the size that is scaled from, which should
7620 * always be the user's requested size.
7621 */
7622 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007623 ((crtc_state->pipe_src_w - 1) << 16) |
7624 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007625}
7626
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007627static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007628 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007629{
7630 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007631 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007632 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007633 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007634
7635 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007636 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7637 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007638 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007639 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7640 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007641 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007642 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7643 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007644
7645 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007646 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7647 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007648 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007649 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7650 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007651 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007652 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7653 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007654
7655 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007656 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7657 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7658 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007659 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007660}
7661
7662static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7663 struct intel_crtc_state *pipe_config)
7664{
7665 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007666 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007667 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007668
7669 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007670 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7671 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7672
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007673 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7674 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007675}
7676
Daniel Vetterf6a83282014-02-11 15:28:57 -08007677void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007678 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007679{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007680 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7681 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7682 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7683 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007684
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007685 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7686 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7687 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7688 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007689
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007690 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007691 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007692
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007693 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007694
7695 mode->hsync = drm_mode_hsync(mode);
7696 mode->vrefresh = drm_mode_vrefresh(mode);
7697 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007698}
7699
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007700static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007701{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007702 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7703 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007704 u32 pipeconf;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007705
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007706 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007707
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007708 /* we keep both pipes enabled on 830 */
7709 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007710 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007711
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007712 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007713 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007714
Daniel Vetterff9ce462013-04-24 14:57:17 +02007715 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007716 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7717 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007718 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007719 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007720 pipeconf |= PIPECONF_DITHER_EN |
7721 PIPECONF_DITHER_TYPE_SP;
7722
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007723 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007724 case 18:
7725 pipeconf |= PIPECONF_6BPC;
7726 break;
7727 case 24:
7728 pipeconf |= PIPECONF_8BPC;
7729 break;
7730 case 30:
7731 pipeconf |= PIPECONF_10BPC;
7732 break;
7733 default:
7734 /* Case prevented by intel_choose_pipe_bpp_dither. */
7735 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007736 }
7737 }
7738
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007739 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007740 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007741 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007742 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7743 else
7744 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7745 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007746 pipeconf |= PIPECONF_PROGRESSIVE;
7747
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007748 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007749 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007750 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007751
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007752 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7753 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007754}
7755
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007756static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7757 struct intel_crtc_state *crtc_state)
7758{
7759 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007760 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007761 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007762 int refclk = 48000;
7763
7764 memset(&crtc_state->dpll_hw_state, 0,
7765 sizeof(crtc_state->dpll_hw_state));
7766
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007767 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007768 if (intel_panel_use_ssc(dev_priv)) {
7769 refclk = dev_priv->vbt.lvds_ssc_freq;
7770 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7771 }
7772
7773 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007774 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007775 limit = &intel_limits_i8xx_dvo;
7776 } else {
7777 limit = &intel_limits_i8xx_dac;
7778 }
7779
7780 if (!crtc_state->clock_set &&
7781 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7782 refclk, NULL, &crtc_state->dpll)) {
7783 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7784 return -EINVAL;
7785 }
7786
7787 i8xx_compute_dpll(crtc, crtc_state, NULL);
7788
7789 return 0;
7790}
7791
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007792static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7793 struct intel_crtc_state *crtc_state)
7794{
7795 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007796 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007797 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007798 int refclk = 96000;
7799
7800 memset(&crtc_state->dpll_hw_state, 0,
7801 sizeof(crtc_state->dpll_hw_state));
7802
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007803 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007804 if (intel_panel_use_ssc(dev_priv)) {
7805 refclk = dev_priv->vbt.lvds_ssc_freq;
7806 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7807 }
7808
7809 if (intel_is_dual_link_lvds(dev))
7810 limit = &intel_limits_g4x_dual_channel_lvds;
7811 else
7812 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007813 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7814 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007815 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007816 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007817 limit = &intel_limits_g4x_sdvo;
7818 } else {
7819 /* The option is for other outputs */
7820 limit = &intel_limits_i9xx_sdvo;
7821 }
7822
7823 if (!crtc_state->clock_set &&
7824 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7825 refclk, NULL, &crtc_state->dpll)) {
7826 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7827 return -EINVAL;
7828 }
7829
7830 i9xx_compute_dpll(crtc, crtc_state, NULL);
7831
7832 return 0;
7833}
7834
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007835static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7836 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007837{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007838 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007839 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007840 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007841 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007842
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007843 memset(&crtc_state->dpll_hw_state, 0,
7844 sizeof(crtc_state->dpll_hw_state));
7845
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007846 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007847 if (intel_panel_use_ssc(dev_priv)) {
7848 refclk = dev_priv->vbt.lvds_ssc_freq;
7849 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7850 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007851
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007852 limit = &intel_limits_pineview_lvds;
7853 } else {
7854 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007855 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007856
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007857 if (!crtc_state->clock_set &&
7858 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7859 refclk, NULL, &crtc_state->dpll)) {
7860 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7861 return -EINVAL;
7862 }
7863
7864 i9xx_compute_dpll(crtc, crtc_state, NULL);
7865
7866 return 0;
7867}
7868
7869static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7870 struct intel_crtc_state *crtc_state)
7871{
7872 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007873 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007874 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007875 int refclk = 96000;
7876
7877 memset(&crtc_state->dpll_hw_state, 0,
7878 sizeof(crtc_state->dpll_hw_state));
7879
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007880 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007881 if (intel_panel_use_ssc(dev_priv)) {
7882 refclk = dev_priv->vbt.lvds_ssc_freq;
7883 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007884 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007885
7886 limit = &intel_limits_i9xx_lvds;
7887 } else {
7888 limit = &intel_limits_i9xx_sdvo;
7889 }
7890
7891 if (!crtc_state->clock_set &&
7892 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7893 refclk, NULL, &crtc_state->dpll)) {
7894 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7895 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007896 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007897
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007898 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007899
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007900 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007901}
7902
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007903static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7904 struct intel_crtc_state *crtc_state)
7905{
7906 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007907 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007908
7909 memset(&crtc_state->dpll_hw_state, 0,
7910 sizeof(crtc_state->dpll_hw_state));
7911
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007912 if (!crtc_state->clock_set &&
7913 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7914 refclk, NULL, &crtc_state->dpll)) {
7915 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7916 return -EINVAL;
7917 }
7918
7919 chv_compute_dpll(crtc, crtc_state);
7920
7921 return 0;
7922}
7923
7924static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7925 struct intel_crtc_state *crtc_state)
7926{
7927 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007928 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007929
7930 memset(&crtc_state->dpll_hw_state, 0,
7931 sizeof(crtc_state->dpll_hw_state));
7932
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007933 if (!crtc_state->clock_set &&
7934 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7935 refclk, NULL, &crtc_state->dpll)) {
7936 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7937 return -EINVAL;
7938 }
7939
7940 vlv_compute_dpll(crtc, crtc_state);
7941
7942 return 0;
7943}
7944
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007945static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007946 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007947{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007948 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02007949 u32 tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007950
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007951 if (INTEL_GEN(dev_priv) <= 3 &&
7952 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007953 return;
7954
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007955 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007956 if (!(tmp & PFIT_ENABLE))
7957 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007958
Daniel Vetter06922822013-07-11 13:35:40 +02007959 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007960 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007961 if (crtc->pipe != PIPE_B)
7962 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007963 } else {
7964 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7965 return;
7966 }
7967
Daniel Vetter06922822013-07-11 13:35:40 +02007968 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007969 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007970}
7971
Jesse Barnesacbec812013-09-20 11:29:32 -07007972static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007973 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007974{
7975 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007976 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007977 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007978 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007979 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007980 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007981
Ville Syrjäläb5219732016-03-15 16:40:01 +02007982 /* In case of DSI, DPLL will not be used */
7983 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307984 return;
7985
Ville Syrjäläa5805162015-05-26 20:42:30 +03007986 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007987 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007988 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007989
7990 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7991 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7992 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7993 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7994 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7995
Imre Deakdccbea32015-06-22 23:35:51 +03007996 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007997}
7998
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007999static void
8000i9xx_get_initial_plane_config(struct intel_crtc *crtc,
8001 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008002{
8003 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008004 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008005 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8006 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008007 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008008 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008009 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00008010 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00008011 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00008012 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008013
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008014 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00008015 return;
8016
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008017 WARN_ON(pipe != crtc->pipe);
8018
Damien Lespiaud9806c92015-01-21 14:07:19 +00008019 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00008020 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008021 DRM_DEBUG_KMS("failed to alloc fb\n");
8022 return;
8023 }
8024
Damien Lespiau1b842c82015-01-21 13:50:54 +00008025 fb = &intel_fb->base;
8026
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02008027 fb->dev = dev;
8028
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02008029 val = I915_READ(DSPCNTR(i9xx_plane));
8030
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008031 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00008032 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00008033 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02008034 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00008035 }
Ville Syrjäläf43348a2018-11-20 15:54:50 +02008036
8037 if (val & DISPPLANE_ROTATE_180)
8038 plane_config->rotation = DRM_MODE_ROTATE_180;
Daniel Vetter18c52472015-02-10 17:16:09 +00008039 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008040
Ville Syrjäläf43348a2018-11-20 15:54:50 +02008041 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
8042 val & DISPPLANE_MIRROR)
8043 plane_config->rotation |= DRM_MODE_REFLECT_X;
8044
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008045 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00008046 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02008047 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008048
Ville Syrjälä81894b22017-11-17 21:19:13 +02008049 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
8050 offset = I915_READ(DSPOFFSET(i9xx_plane));
8051 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
8052 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00008053 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008054 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008055 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008056 offset = I915_READ(DSPLINOFF(i9xx_plane));
8057 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008058 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008059 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008060 }
8061 plane_config->base = base;
8062
8063 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00008064 fb->width = ((val >> 16) & 0xfff) + 1;
8065 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008066
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008067 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00008068 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008069
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008070 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008071
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008072 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008073
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008074 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8075 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02008076 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00008077 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008078
Damien Lespiau2d140302015-02-05 17:22:18 +00008079 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08008080}
8081
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008082static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008083 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008084{
8085 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008086 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008087 int pipe = pipe_config->cpu_transcoder;
8088 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008089 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03008090 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008091 int refclk = 100000;
8092
Ville Syrjäläb5219732016-03-15 16:40:01 +02008093 /* In case of DSI, DPLL will not be used */
8094 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
8095 return;
8096
Ville Syrjäläa5805162015-05-26 20:42:30 +03008097 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008098 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
8099 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
8100 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
8101 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03008102 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03008103 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008104
8105 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03008106 clock.m2 = (pll_dw0 & 0xff) << 22;
8107 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
8108 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008109 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
8110 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
8111 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
8112
Imre Deakdccbea32015-06-22 23:35:51 +03008113 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008114}
8115
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308116static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
8117 struct intel_crtc_state *pipe_config)
8118{
8119 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8120 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
8121
Shashank Sharma668b6c12018-10-12 11:53:14 +05308122 pipe_config->lspcon_downsampling = false;
8123
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308124 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
8125 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
8126
8127 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
8128 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
8129 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
8130
8131 if (ycbcr420_enabled) {
8132 /* We support 4:2:0 in full blend mode only */
8133 if (!blend)
8134 output = INTEL_OUTPUT_FORMAT_INVALID;
8135 else if (!(IS_GEMINILAKE(dev_priv) ||
8136 INTEL_GEN(dev_priv) >= 10))
8137 output = INTEL_OUTPUT_FORMAT_INVALID;
8138 else
8139 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308140 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05308141 /*
8142 * Currently there is no interface defined to
8143 * check user preference between RGB/YCBCR444
8144 * or YCBCR420. So the only possible case for
8145 * YCBCR444 usage is driving YCBCR420 output
8146 * with LSPCON, when pipe is configured for
8147 * YCBCR444 output and LSPCON takes care of
8148 * downsampling it.
8149 */
8150 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308151 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308152 }
8153 }
8154 }
8155
8156 pipe_config->output_format = output;
8157}
8158
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008159static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008160 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008161{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008162 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02008163 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008164 intel_wakeref_t wakeref;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008165 u32 tmp;
Imre Deak17290502016-02-12 18:55:11 +02008166 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008167
Imre Deak17290502016-02-12 18:55:11 +02008168 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008169 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
8170 if (!wakeref)
Imre Deakb5482bd2014-03-05 16:20:55 +02008171 return false;
8172
Shashank Sharmad9facae2018-10-12 11:53:07 +05308173 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02008174 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02008175 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02008176
Imre Deak17290502016-02-12 18:55:11 +02008177 ret = false;
8178
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008179 tmp = I915_READ(PIPECONF(crtc->pipe));
8180 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02008181 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008182
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01008183 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
8184 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03008185 switch (tmp & PIPECONF_BPC_MASK) {
8186 case PIPECONF_6BPC:
8187 pipe_config->pipe_bpp = 18;
8188 break;
8189 case PIPECONF_8BPC:
8190 pipe_config->pipe_bpp = 24;
8191 break;
8192 case PIPECONF_10BPC:
8193 pipe_config->pipe_bpp = 30;
8194 break;
8195 default:
8196 break;
8197 }
8198 }
8199
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008200 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08008201 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02008202 pipe_config->limited_color_range = true;
8203
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008204 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03008205 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
8206
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008207 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02008208 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02008209
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008210 i9xx_get_pfit_config(crtc, pipe_config);
8211
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008212 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02008213 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008214 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02008215 tmp = dev_priv->chv_dpll_md[crtc->pipe];
8216 else
8217 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02008218 pipe_config->pixel_multiplier =
8219 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8220 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008221 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008222 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02008223 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02008224 tmp = I915_READ(DPLL(crtc->pipe));
8225 pipe_config->pixel_multiplier =
8226 ((tmp & SDVO_MULTIPLIER_MASK)
8227 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8228 } else {
8229 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8230 * port and will be fixed up in the encoder->get_config
8231 * function. */
8232 pipe_config->pixel_multiplier = 1;
8233 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008234 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008235 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008236 /*
8237 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8238 * on 830. Filter it out here so that we don't
8239 * report errors due to that.
8240 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008241 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008242 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8243
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008244 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8245 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03008246 } else {
8247 /* Mask out read-only status bits. */
8248 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8249 DPLL_PORTC_READY_MASK |
8250 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008251 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02008252
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008253 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008254 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01008255 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07008256 vlv_crtc_clock_get(crtc, pipe_config);
8257 else
8258 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03008259
Ville Syrjälä0f646142015-08-26 19:39:18 +03008260 /*
8261 * Normally the dotclock is filled in by the encoder .get_config()
8262 * but in case the pipe is enabled w/o any ports we need a sane
8263 * default.
8264 */
8265 pipe_config->base.adjusted_mode.crtc_clock =
8266 pipe_config->port_clock / pipe_config->pixel_multiplier;
8267
Imre Deak17290502016-02-12 18:55:11 +02008268 ret = true;
8269
8270out:
Chris Wilson0e6e0be2019-01-14 14:21:24 +00008271 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak17290502016-02-12 18:55:11 +02008272
8273 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008274}
8275
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008276static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07008277{
Jesse Barnes13d83a62011-08-03 12:59:20 -07008278 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04008279 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008280 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008281 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008282 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008283 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07008284 bool has_ck505 = false;
8285 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04008286 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008287
8288 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008289 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07008290 switch (encoder->type) {
8291 case INTEL_OUTPUT_LVDS:
8292 has_panel = true;
8293 has_lvds = true;
8294 break;
8295 case INTEL_OUTPUT_EDP:
8296 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02008297 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07008298 has_cpu_edp = true;
8299 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008300 default:
8301 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008302 }
8303 }
8304
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008305 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008306 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008307 can_ssc = has_ck505;
8308 } else {
8309 has_ck505 = false;
8310 can_ssc = true;
8311 }
8312
Lyude1c1a24d2016-06-14 11:04:09 -04008313 /* Check if any DPLLs are using the SSC source */
8314 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8315 u32 temp = I915_READ(PCH_DPLL(i));
8316
8317 if (!(temp & DPLL_VCO_ENABLE))
8318 continue;
8319
8320 if ((temp & PLL_REF_INPUT_MASK) ==
8321 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8322 using_ssc_source = true;
8323 break;
8324 }
8325 }
8326
8327 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8328 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008329
8330 /* Ironlake: try to setup display ref clock before DPLL
8331 * enabling. This is only under driver's control after
8332 * PCH B stepping, previous chipset stepping should be
8333 * ignoring this setting.
8334 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008335 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008336
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008337 /* As we must carefully and slowly disable/enable each source in turn,
8338 * compute the final state we want first and check if we need to
8339 * make any changes at all.
8340 */
8341 final = val;
8342 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008343 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008344 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008345 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008346 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8347
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008348 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008349 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008350 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008351
Keith Packard199e5d72011-09-22 12:01:57 -07008352 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008353 final |= DREF_SSC_SOURCE_ENABLE;
8354
8355 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8356 final |= DREF_SSC1_ENABLE;
8357
8358 if (has_cpu_edp) {
8359 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8360 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8361 else
8362 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8363 } else
8364 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008365 } else if (using_ssc_source) {
8366 final |= DREF_SSC_SOURCE_ENABLE;
8367 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008368 }
8369
8370 if (final == val)
8371 return;
8372
8373 /* Always enable nonspread source */
8374 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8375
8376 if (has_ck505)
8377 val |= DREF_NONSPREAD_CK505_ENABLE;
8378 else
8379 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8380
8381 if (has_panel) {
8382 val &= ~DREF_SSC_SOURCE_MASK;
8383 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008384
Keith Packard199e5d72011-09-22 12:01:57 -07008385 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008386 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008387 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008388 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008389 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008390 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008391
8392 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008393 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008394 POSTING_READ(PCH_DREF_CONTROL);
8395 udelay(200);
8396
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008397 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008398
8399 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008400 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008401 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008402 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008403 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008404 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008405 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008406 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008407 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008408
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008409 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008410 POSTING_READ(PCH_DREF_CONTROL);
8411 udelay(200);
8412 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008413 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008414
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008415 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008416
8417 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008418 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008419
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008420 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008421 POSTING_READ(PCH_DREF_CONTROL);
8422 udelay(200);
8423
Lyude1c1a24d2016-06-14 11:04:09 -04008424 if (!using_ssc_source) {
8425 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008426
Lyude1c1a24d2016-06-14 11:04:09 -04008427 /* Turn off the SSC source */
8428 val &= ~DREF_SSC_SOURCE_MASK;
8429 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008430
Lyude1c1a24d2016-06-14 11:04:09 -04008431 /* Turn off SSC1 */
8432 val &= ~DREF_SSC1_ENABLE;
8433
8434 I915_WRITE(PCH_DREF_CONTROL, val);
8435 POSTING_READ(PCH_DREF_CONTROL);
8436 udelay(200);
8437 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008438 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008439
8440 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008441}
8442
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008443static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008444{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008445 u32 tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008446
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008447 tmp = I915_READ(SOUTH_CHICKEN2);
8448 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8449 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008450
Imre Deakcf3598c2016-06-28 13:37:31 +03008451 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8452 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008453 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008454
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008455 tmp = I915_READ(SOUTH_CHICKEN2);
8456 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8457 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008458
Imre Deakcf3598c2016-06-28 13:37:31 +03008459 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8460 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008461 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008462}
8463
8464/* WaMPhyProgramming:hsw */
8465static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8466{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008467 u32 tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008468
8469 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8470 tmp &= ~(0xFF << 24);
8471 tmp |= (0x12 << 24);
8472 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8473
Paulo Zanonidde86e22012-12-01 12:04:25 -02008474 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8475 tmp |= (1 << 11);
8476 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8477
8478 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8479 tmp |= (1 << 11);
8480 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8481
Paulo Zanonidde86e22012-12-01 12:04:25 -02008482 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8483 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8484 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8485
8486 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8487 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8488 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8489
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008490 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8491 tmp &= ~(7 << 13);
8492 tmp |= (5 << 13);
8493 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008494
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008495 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8496 tmp &= ~(7 << 13);
8497 tmp |= (5 << 13);
8498 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008499
8500 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8501 tmp &= ~0xFF;
8502 tmp |= 0x1C;
8503 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8504
8505 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8506 tmp &= ~0xFF;
8507 tmp |= 0x1C;
8508 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8509
8510 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8511 tmp &= ~(0xFF << 16);
8512 tmp |= (0x1C << 16);
8513 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8514
8515 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8516 tmp &= ~(0xFF << 16);
8517 tmp |= (0x1C << 16);
8518 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8519
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008520 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8521 tmp |= (1 << 27);
8522 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008523
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008524 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8525 tmp |= (1 << 27);
8526 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008527
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008528 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8529 tmp &= ~(0xF << 28);
8530 tmp |= (4 << 28);
8531 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008532
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008533 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8534 tmp &= ~(0xF << 28);
8535 tmp |= (4 << 28);
8536 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008537}
8538
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008539/* Implements 3 different sequences from BSpec chapter "Display iCLK
8540 * Programming" based on the parameters passed:
8541 * - Sequence to enable CLKOUT_DP
8542 * - Sequence to enable CLKOUT_DP without spread
8543 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8544 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008545static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8546 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008547{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008548 u32 reg, tmp;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008549
8550 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8551 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008552 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8553 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008554 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008555
Ville Syrjäläa5805162015-05-26 20:42:30 +03008556 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008557
8558 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8559 tmp &= ~SBI_SSCCTL_DISABLE;
8560 tmp |= SBI_SSCCTL_PATHALT;
8561 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8562
8563 udelay(24);
8564
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008565 if (with_spread) {
8566 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8567 tmp &= ~SBI_SSCCTL_PATHALT;
8568 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008569
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008570 if (with_fdi) {
8571 lpt_reset_fdi_mphy(dev_priv);
8572 lpt_program_fdi_mphy(dev_priv);
8573 }
8574 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008575
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008576 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008577 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8578 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8579 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008580
Ville Syrjäläa5805162015-05-26 20:42:30 +03008581 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008582}
8583
Paulo Zanoni47701c32013-07-23 11:19:25 -03008584/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008585static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008586{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008587 u32 reg, tmp;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008588
Ville Syrjäläa5805162015-05-26 20:42:30 +03008589 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008590
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008591 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008592 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8593 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8594 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8595
8596 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8597 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8598 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8599 tmp |= SBI_SSCCTL_PATHALT;
8600 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8601 udelay(32);
8602 }
8603 tmp |= SBI_SSCCTL_DISABLE;
8604 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8605 }
8606
Ville Syrjäläa5805162015-05-26 20:42:30 +03008607 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008608}
8609
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008610#define BEND_IDX(steps) ((50 + (steps)) / 5)
8611
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008612static const u16 sscdivintphase[] = {
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008613 [BEND_IDX( 50)] = 0x3B23,
8614 [BEND_IDX( 45)] = 0x3B23,
8615 [BEND_IDX( 40)] = 0x3C23,
8616 [BEND_IDX( 35)] = 0x3C23,
8617 [BEND_IDX( 30)] = 0x3D23,
8618 [BEND_IDX( 25)] = 0x3D23,
8619 [BEND_IDX( 20)] = 0x3E23,
8620 [BEND_IDX( 15)] = 0x3E23,
8621 [BEND_IDX( 10)] = 0x3F23,
8622 [BEND_IDX( 5)] = 0x3F23,
8623 [BEND_IDX( 0)] = 0x0025,
8624 [BEND_IDX( -5)] = 0x0025,
8625 [BEND_IDX(-10)] = 0x0125,
8626 [BEND_IDX(-15)] = 0x0125,
8627 [BEND_IDX(-20)] = 0x0225,
8628 [BEND_IDX(-25)] = 0x0225,
8629 [BEND_IDX(-30)] = 0x0325,
8630 [BEND_IDX(-35)] = 0x0325,
8631 [BEND_IDX(-40)] = 0x0425,
8632 [BEND_IDX(-45)] = 0x0425,
8633 [BEND_IDX(-50)] = 0x0525,
8634};
8635
8636/*
8637 * Bend CLKOUT_DP
8638 * steps -50 to 50 inclusive, in steps of 5
8639 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8640 * change in clock period = -(steps / 10) * 5.787 ps
8641 */
8642static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8643{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008644 u32 tmp;
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008645 int idx = BEND_IDX(steps);
8646
8647 if (WARN_ON(steps % 5 != 0))
8648 return;
8649
8650 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8651 return;
8652
8653 mutex_lock(&dev_priv->sb_lock);
8654
8655 if (steps % 10 != 0)
8656 tmp = 0xAAAAAAAB;
8657 else
8658 tmp = 0x00000000;
8659 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8660
8661 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8662 tmp &= 0xffff0000;
8663 tmp |= sscdivintphase[idx];
8664 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8665
8666 mutex_unlock(&dev_priv->sb_lock);
8667}
8668
8669#undef BEND_IDX
8670
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008671static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008672{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008673 struct intel_encoder *encoder;
8674 bool has_vga = false;
8675
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008676 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008677 switch (encoder->type) {
8678 case INTEL_OUTPUT_ANALOG:
8679 has_vga = true;
8680 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008681 default:
8682 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008683 }
8684 }
8685
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008686 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008687 lpt_bend_clkout_dp(dev_priv, 0);
8688 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008689 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008690 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008691 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008692}
8693
Paulo Zanonidde86e22012-12-01 12:04:25 -02008694/*
8695 * Initialize reference clocks when the driver loads
8696 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008697void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008698{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008699 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008700 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008701 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008702 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008703}
8704
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008705static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008706{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008707 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8708 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8709 enum pipe pipe = crtc->pipe;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02008710 u32 val;
Paulo Zanonic8203562012-09-12 10:06:29 -03008711
Daniel Vetter78114072013-06-13 00:54:57 +02008712 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008713
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008714 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008715 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008716 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008717 break;
8718 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008719 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008720 break;
8721 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008722 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008723 break;
8724 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008725 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008726 break;
8727 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008728 /* Case prevented by intel_choose_pipe_bpp_dither. */
8729 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008730 }
8731
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008732 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008733 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8734
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008735 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008736 val |= PIPECONF_INTERLACED_ILK;
8737 else
8738 val |= PIPECONF_PROGRESSIVE;
8739
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008740 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008741 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008742
Paulo Zanonic8203562012-09-12 10:06:29 -03008743 I915_WRITE(PIPECONF(pipe), val);
8744 POSTING_READ(PIPECONF(pipe));
8745}
8746
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008747static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008748{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008749 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8750 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8751 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008752 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008753
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008754 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008755 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8756
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008757 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008758 val |= PIPECONF_INTERLACED_ILK;
8759 else
8760 val |= PIPECONF_PROGRESSIVE;
8761
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008762 I915_WRITE(PIPECONF(cpu_transcoder), val);
8763 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008764}
8765
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008766static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008767{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008768 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8769 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008770
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008771 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008772 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008773
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008774 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008775 case 18:
8776 val |= PIPEMISC_DITHER_6_BPC;
8777 break;
8778 case 24:
8779 val |= PIPEMISC_DITHER_8_BPC;
8780 break;
8781 case 30:
8782 val |= PIPEMISC_DITHER_10_BPC;
8783 break;
8784 case 36:
8785 val |= PIPEMISC_DITHER_12_BPC;
8786 break;
8787 default:
8788 /* Case prevented by pipe_config_set_bpp. */
8789 BUG();
8790 }
8791
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008792 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008793 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8794
Shashank Sharma8c79f842018-10-12 11:53:09 +05308795 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8796 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308797 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308798
8799 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308800 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308801 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308802
Jani Nikula391bf042016-03-18 17:05:40 +02008803 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008804 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008805}
8806
Paulo Zanonid4b19312012-11-29 11:29:32 -02008807int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8808{
8809 /*
8810 * Account for spread spectrum to avoid
8811 * oversubscribing the link. Max center spread
8812 * is 2.5%; use 5% for safety's sake.
8813 */
8814 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008815 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008816}
8817
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008818static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008819{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008820 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008821}
8822
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008823static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8824 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008825 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008826{
8827 struct drm_crtc *crtc = &intel_crtc->base;
8828 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008829 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008830 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008831 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008832
Chris Wilsonc1858122010-12-03 21:35:48 +00008833 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008834 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008835 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008836 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008837 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008838 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008839 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008840 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008841 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008842
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008843 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008844
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008845 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8846 fp |= FP_CB_TUNE;
8847
8848 if (reduced_clock) {
8849 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8850
8851 if (reduced_clock->m < factor * reduced_clock->n)
8852 fp2 |= FP_CB_TUNE;
8853 } else {
8854 fp2 = fp;
8855 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008856
Chris Wilson5eddb702010-09-11 13:48:45 +01008857 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008858
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008859 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008860 dpll |= DPLLB_MODE_LVDS;
8861 else
8862 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008863
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008864 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008865 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008866
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008867 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8868 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008869 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008870
Ville Syrjälä37a56502016-06-22 21:57:04 +03008871 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008872 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008873
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008874 /*
8875 * The high speed IO clock is only really required for
8876 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8877 * possible to share the DPLL between CRT and HDMI. Enabling
8878 * the clock needlessly does no real harm, except use up a
8879 * bit of power potentially.
8880 *
8881 * We'll limit this to IVB with 3 pipes, since it has only two
8882 * DPLLs and so DPLL sharing is the only way to get three pipes
8883 * driving PCH ports at the same time. On SNB we could do this,
8884 * and potentially avoid enabling the second DPLL, but it's not
8885 * clear if it''s a win or loss power wise. No point in doing
8886 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8887 */
8888 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8889 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8890 dpll |= DPLL_SDVO_HIGH_SPEED;
8891
Eric Anholta07d6782011-03-30 13:01:08 -07008892 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008893 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008894 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008895 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008896
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008897 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008898 case 5:
8899 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8900 break;
8901 case 7:
8902 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8903 break;
8904 case 10:
8905 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8906 break;
8907 case 14:
8908 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8909 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008910 }
8911
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008912 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8913 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008914 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008915 else
8916 dpll |= PLL_REF_INPUT_DREFCLK;
8917
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008918 dpll |= DPLL_VCO_ENABLE;
8919
8920 crtc_state->dpll_hw_state.dpll = dpll;
8921 crtc_state->dpll_hw_state.fp0 = fp;
8922 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008923}
8924
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008925static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8926 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008927{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008928 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008929 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008930 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008931 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008932
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008933 memset(&crtc_state->dpll_hw_state, 0,
8934 sizeof(crtc_state->dpll_hw_state));
8935
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008936 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8937 if (!crtc_state->has_pch_encoder)
8938 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008939
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008940 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008941 if (intel_panel_use_ssc(dev_priv)) {
8942 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8943 dev_priv->vbt.lvds_ssc_freq);
8944 refclk = dev_priv->vbt.lvds_ssc_freq;
8945 }
8946
8947 if (intel_is_dual_link_lvds(dev)) {
8948 if (refclk == 100000)
8949 limit = &intel_limits_ironlake_dual_lvds_100m;
8950 else
8951 limit = &intel_limits_ironlake_dual_lvds;
8952 } else {
8953 if (refclk == 100000)
8954 limit = &intel_limits_ironlake_single_lvds_100m;
8955 else
8956 limit = &intel_limits_ironlake_single_lvds;
8957 }
8958 } else {
8959 limit = &intel_limits_ironlake_dac;
8960 }
8961
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008962 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008963 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8964 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008965 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8966 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008967 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008968
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008969 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008970
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008971 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008972 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8973 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008974 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008975 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008976
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008977 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008978}
8979
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008980static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8981 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008982{
8983 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008984 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008985 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008986
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008987 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8988 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8989 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8990 & ~TU_SIZE_MASK;
8991 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8992 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8993 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8994}
8995
8996static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8997 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008998 struct intel_link_m_n *m_n,
8999 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009000{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009002 enum pipe pipe = crtc->pipe;
9003
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009004 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009005 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
9006 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
9007 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
9008 & ~TU_SIZE_MASK;
9009 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
9010 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
9011 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02009012
9013 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07009014 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
9015 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
9016 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
9017 & ~TU_SIZE_MASK;
9018 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
9019 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
9020 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9021 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009022 } else {
9023 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
9024 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
9025 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
9026 & ~TU_SIZE_MASK;
9027 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
9028 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
9029 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
9030 }
9031}
9032
9033void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009034 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009035{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02009036 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009037 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
9038 else
9039 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07009040 &pipe_config->dp_m_n,
9041 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009042}
9043
Daniel Vetter72419202013-04-04 13:28:53 +02009044static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009045 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02009046{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03009047 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07009048 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02009049}
9050
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009051static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009052 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009053{
9054 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009055 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07009056 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009057 u32 ps_ctrl = 0;
Chandra Kondurua1b22782015-04-07 15:28:45 -07009058 int id = -1;
9059 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009060
Chandra Kondurua1b22782015-04-07 15:28:45 -07009061 /* find scaler attached to this pipe */
9062 for (i = 0; i < crtc->num_scalers; i++) {
9063 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
9064 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
9065 id = i;
9066 pipe_config->pch_pfit.enabled = true;
9067 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
9068 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
Maarten Lankhorst0cdc1d02019-01-08 17:08:41 +01009069 scaler_state->scalers[i].in_use = true;
Chandra Kondurua1b22782015-04-07 15:28:45 -07009070 break;
9071 }
9072 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009073
Chandra Kondurua1b22782015-04-07 15:28:45 -07009074 scaler_state->scaler_id = id;
9075 if (id >= 0) {
9076 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
9077 } else {
9078 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009079 }
9080}
9081
Damien Lespiau5724dbd2015-01-20 12:51:52 +00009082static void
9083skylake_get_initial_plane_config(struct intel_crtc *crtc,
9084 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009085{
9086 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009087 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009088 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
9089 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009090 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08009091 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009092 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00009093 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009094 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00009095 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009096
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009097 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02009098 return;
9099
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009100 WARN_ON(pipe != crtc->pipe);
9101
Damien Lespiaud9806c92015-01-21 14:07:19 +00009102 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00009103 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009104 DRM_DEBUG_KMS("failed to alloc fb\n");
9105 return;
9106 }
9107
Damien Lespiau1b842c82015-01-21 13:50:54 +00009108 fb = &intel_fb->base;
9109
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02009110 fb->dev = dev;
9111
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009112 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00009113
James Ausmusb5972772018-01-30 11:49:16 -02009114 if (INTEL_GEN(dev_priv) >= 11)
9115 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
9116 else
9117 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08009118
9119 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009120 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08009121 alpha &= PLANE_COLOR_ALPHA_MASK;
9122 } else {
9123 alpha = val & PLANE_CTL_ALPHA_MASK;
9124 }
9125
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009126 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08009127 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02009128 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009129
Damien Lespiau40f46282015-02-27 11:15:21 +00009130 tiling = val & PLANE_CTL_TILED_MASK;
9131 switch (tiling) {
9132 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07009133 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00009134 break;
9135 case PLANE_CTL_TILED_X:
9136 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02009137 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009138 break;
9139 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03009140 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07009141 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07009142 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
9143 else
9144 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009145 break;
9146 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07009147 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07009148 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
9149 else
9150 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00009151 break;
9152 default:
9153 MISSING_CASE(tiling);
9154 goto error;
9155 }
9156
Ville Syrjäläf43348a2018-11-20 15:54:50 +02009157 /*
9158 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
9159 * while i915 HW rotation is clockwise, thats why this swapping.
9160 */
9161 switch (val & PLANE_CTL_ROTATE_MASK) {
9162 case PLANE_CTL_ROTATE_0:
9163 plane_config->rotation = DRM_MODE_ROTATE_0;
9164 break;
9165 case PLANE_CTL_ROTATE_90:
9166 plane_config->rotation = DRM_MODE_ROTATE_270;
9167 break;
9168 case PLANE_CTL_ROTATE_180:
9169 plane_config->rotation = DRM_MODE_ROTATE_180;
9170 break;
9171 case PLANE_CTL_ROTATE_270:
9172 plane_config->rotation = DRM_MODE_ROTATE_90;
9173 break;
9174 }
9175
9176 if (INTEL_GEN(dev_priv) >= 10 &&
9177 val & PLANE_CTL_FLIP_HORIZONTAL)
9178 plane_config->rotation |= DRM_MODE_REFLECT_X;
9179
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009180 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009181 plane_config->base = base;
9182
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009183 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009184
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009185 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009186 fb->height = ((val >> 16) & 0xfff) + 1;
9187 fb->width = ((val >> 0) & 0x1fff) + 1;
9188
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009189 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03009190 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009191 fb->pitches[0] = (val & 0x3ff) * stride_mult;
9192
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02009193 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009194
Daniel Vetterf37b5c22015-02-10 23:12:27 +01009195 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009196
Ville Syrjälä282e83e2017-11-17 21:19:12 +02009197 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
9198 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02009199 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009200 plane_config->size);
9201
Damien Lespiau2d140302015-02-05 17:22:18 +00009202 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009203 return;
9204
9205error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01009206 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00009207}
9208
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009209static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009210 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009211{
9212 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009213 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009214 u32 tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009215
9216 tmp = I915_READ(PF_CTL(crtc->pipe));
9217
9218 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01009219 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009220 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9221 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009222
9223 /* We currently do not free assignements of panel fitters on
9224 * ivb/hsw (since we don't use the higher upscaling modes which
9225 * differentiates them) so just WARN about this case for now. */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08009226 if (IS_GEN(dev_priv, 7)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009227 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9228 PF_PIPE_SEL_IVB(crtc->pipe));
9229 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009230 }
Jesse Barnes79e53942008-11-07 14:24:08 -08009231}
9232
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009233static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009234 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009235{
9236 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009237 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02009238 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009239 intel_wakeref_t wakeref;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009240 u32 tmp;
Imre Deak17290502016-02-12 18:55:11 +02009241 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009242
Imre Deak17290502016-02-12 18:55:11 +02009243 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009244 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
9245 if (!wakeref)
Paulo Zanoni930e8c92014-07-04 13:38:34 -03009246 return false;
9247
Shashank Sharmad9facae2018-10-12 11:53:07 +05309248 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02009249 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009250 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02009251
Imre Deak17290502016-02-12 18:55:11 +02009252 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009253 tmp = I915_READ(PIPECONF(crtc->pipe));
9254 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02009255 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009256
Ville Syrjälä42571ae2013-09-06 23:29:00 +03009257 switch (tmp & PIPECONF_BPC_MASK) {
9258 case PIPECONF_6BPC:
9259 pipe_config->pipe_bpp = 18;
9260 break;
9261 case PIPECONF_8BPC:
9262 pipe_config->pipe_bpp = 24;
9263 break;
9264 case PIPECONF_10BPC:
9265 pipe_config->pipe_bpp = 30;
9266 break;
9267 case PIPECONF_12BPC:
9268 pipe_config->pipe_bpp = 36;
9269 break;
9270 default:
9271 break;
9272 }
9273
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02009274 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9275 pipe_config->limited_color_range = true;
9276
Daniel Vetterab9412b2013-05-03 11:49:46 +02009277 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02009278 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009279 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009280
Daniel Vetter88adfff2013-03-28 10:42:01 +01009281 pipe_config->has_pch_encoder = true;
9282
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009283 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9284 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9285 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02009286
9287 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009288
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03009289 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03009290 /*
9291 * The pipe->pch transcoder and pch transcoder->pll
9292 * mapping is fixed.
9293 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009294 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009295 } else {
9296 tmp = I915_READ(PCH_DPLL_SEL);
9297 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009298 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009299 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009300 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009301 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02009302
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009303 pipe_config->shared_dpll =
9304 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9305 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009306
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009307 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9308 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02009309
9310 tmp = pipe_config->dpll_hw_state.dpll;
9311 pipe_config->pixel_multiplier =
9312 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9313 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03009314
9315 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009316 } else {
9317 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009318 }
9319
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009320 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02009321 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009322
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009323 ironlake_get_pfit_config(crtc, pipe_config);
9324
Imre Deak17290502016-02-12 18:55:11 +02009325 ret = true;
9326
9327out:
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009328 intel_display_power_put(dev_priv, power_domain, wakeref);
Imre Deak17290502016-02-12 18:55:11 +02009329
9330 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009331}
9332
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009333static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9334{
Chris Wilson91c8a322016-07-05 10:40:23 +01009335 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009336 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009337
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009338 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009339 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009340 pipe_name(crtc->pipe));
9341
Imre Deak75e39682018-08-06 12:58:39 +03009342 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009343 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009344 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009345 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9346 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009347 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009348 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009349 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009350 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009351 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009352 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009353 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009354 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009355 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009356 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009357 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009358
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009359 /*
9360 * In theory we can still leave IRQs enabled, as long as only the HPD
9361 * interrupts remain enabled. We used to check for that, but since it's
9362 * gen-specific and since we only disable LCPLL after we fully disable
9363 * the interrupts, the check below should be enough.
9364 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009365 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009366}
9367
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009368static u32 hsw_read_dcomp(struct drm_i915_private *dev_priv)
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009369{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009370 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009371 return I915_READ(D_COMP_HSW);
9372 else
9373 return I915_READ(D_COMP_BDW);
9374}
9375
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009376static void hsw_write_dcomp(struct drm_i915_private *dev_priv, u32 val)
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009377{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009378 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009379 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009380 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9381 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009382 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009383 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009384 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009385 I915_WRITE(D_COMP_BDW, val);
9386 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009387 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009388}
9389
9390/*
9391 * This function implements pieces of two sequences from BSpec:
9392 * - Sequence for display software to disable LCPLL
9393 * - Sequence for display software to allow package C8+
9394 * The steps implemented here are just the steps that actually touch the LCPLL
9395 * register. Callers should take care of disabling all the display engine
9396 * functions, doing the mode unset, fixing interrupts, etc.
9397 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009398static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9399 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009400{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009401 u32 val;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009402
9403 assert_can_disable_lcpll(dev_priv);
9404
9405 val = I915_READ(LCPLL_CTL);
9406
9407 if (switch_to_fclk) {
9408 val |= LCPLL_CD_SOURCE_FCLK;
9409 I915_WRITE(LCPLL_CTL, val);
9410
Imre Deakf53dd632016-06-28 13:37:32 +03009411 if (wait_for_us(I915_READ(LCPLL_CTL) &
9412 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009413 DRM_ERROR("Switching to FCLK failed\n");
9414
9415 val = I915_READ(LCPLL_CTL);
9416 }
9417
9418 val |= LCPLL_PLL_DISABLE;
9419 I915_WRITE(LCPLL_CTL, val);
9420 POSTING_READ(LCPLL_CTL);
9421
Chris Wilson24d84412016-06-30 15:33:07 +01009422 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009423 DRM_ERROR("LCPLL still locked\n");
9424
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009425 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009426 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009427 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009428 ndelay(100);
9429
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009430 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9431 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009432 DRM_ERROR("D_COMP RCOMP still in progress\n");
9433
9434 if (allow_power_down) {
9435 val = I915_READ(LCPLL_CTL);
9436 val |= LCPLL_POWER_DOWN_ALLOW;
9437 I915_WRITE(LCPLL_CTL, val);
9438 POSTING_READ(LCPLL_CTL);
9439 }
9440}
9441
9442/*
9443 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9444 * source.
9445 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009446static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009447{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009448 u32 val;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009449
9450 val = I915_READ(LCPLL_CTL);
9451
9452 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9453 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9454 return;
9455
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009456 /*
9457 * Make sure we're not on PC8 state before disabling PC8, otherwise
9458 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009459 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009460 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009461
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009462 if (val & LCPLL_POWER_DOWN_ALLOW) {
9463 val &= ~LCPLL_POWER_DOWN_ALLOW;
9464 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009465 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009466 }
9467
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009468 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009469 val |= D_COMP_COMP_FORCE;
9470 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009471 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009472
9473 val = I915_READ(LCPLL_CTL);
9474 val &= ~LCPLL_PLL_DISABLE;
9475 I915_WRITE(LCPLL_CTL, val);
9476
Chris Wilson93220c02016-06-30 15:33:08 +01009477 if (intel_wait_for_register(dev_priv,
9478 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9479 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009480 DRM_ERROR("LCPLL not locked yet\n");
9481
9482 if (val & LCPLL_CD_SOURCE_FCLK) {
9483 val = I915_READ(LCPLL_CTL);
9484 val &= ~LCPLL_CD_SOURCE_FCLK;
9485 I915_WRITE(LCPLL_CTL, val);
9486
Imre Deakf53dd632016-06-28 13:37:32 +03009487 if (wait_for_us((I915_READ(LCPLL_CTL) &
9488 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009489 DRM_ERROR("Switching back to LCPLL failed\n");
9490 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009491
Mika Kuoppala59bad942015-01-16 11:34:40 +02009492 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009493
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009494 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009495 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009496}
9497
Paulo Zanoni765dab672014-03-07 20:08:18 -03009498/*
9499 * Package states C8 and deeper are really deep PC states that can only be
9500 * reached when all the devices on the system allow it, so even if the graphics
9501 * device allows PC8+, it doesn't mean the system will actually get to these
9502 * states. Our driver only allows PC8+ when going into runtime PM.
9503 *
9504 * The requirements for PC8+ are that all the outputs are disabled, the power
9505 * well is disabled and most interrupts are disabled, and these are also
9506 * requirements for runtime PM. When these conditions are met, we manually do
9507 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9508 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9509 * hang the machine.
9510 *
9511 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9512 * the state of some registers, so when we come back from PC8+ we need to
9513 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9514 * need to take care of the registers kept by RC6. Notice that this happens even
9515 * if we don't put the device in PCI D3 state (which is what currently happens
9516 * because of the runtime PM support).
9517 *
9518 * For more, read "Display Sequences for Package C8" on the hardware
9519 * documentation.
9520 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009521void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009522{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009523 u32 val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03009524
Paulo Zanonic67a4702013-08-19 13:18:09 -03009525 DRM_DEBUG_KMS("Enabling package C8+\n");
9526
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009527 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009528 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9529 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9530 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9531 }
9532
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009533 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009534 hsw_disable_lcpll(dev_priv, true, true);
9535}
9536
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009537void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009538{
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009539 u32 val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03009540
Paulo Zanonic67a4702013-08-19 13:18:09 -03009541 DRM_DEBUG_KMS("Disabling package C8+\n");
9542
9543 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009544 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009545
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009546 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009547 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9548 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9549 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9550 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009551}
9552
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009553static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9554 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009555{
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009556 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009557 struct intel_atomic_state *state =
9558 to_intel_atomic_state(crtc_state->base.state);
9559
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009560 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9561 IS_ICELAKE(dev_priv)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009562 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009563 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009564
9565 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009566 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9567 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009568 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009569 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009570 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009571
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009572 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009573}
9574
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009575static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9576 enum port port,
9577 struct intel_crtc_state *pipe_config)
9578{
9579 enum intel_dpll_id id;
9580 u32 temp;
9581
9582 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009583 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009584
9585 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9586 return;
9587
9588 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9589}
9590
Paulo Zanoni970888e2018-05-21 17:25:44 -07009591static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9592 enum port port,
9593 struct intel_crtc_state *pipe_config)
9594{
9595 enum intel_dpll_id id;
9596 u32 temp;
9597
9598 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309599 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009600 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9601 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9602 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9603
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309604 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009605 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309606 } else if (intel_port_is_tc(dev_priv, port)) {
Lucas De Marchi584fca12019-01-25 14:24:41 -08009607 id = icl_tc_port_to_pll_id(intel_port_to_tc(dev_priv, port));
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309608 } else {
9609 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009610 return;
9611 }
9612
9613 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9614}
9615
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309616static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9617 enum port port,
9618 struct intel_crtc_state *pipe_config)
9619{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009620 enum intel_dpll_id id;
9621
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309622 switch (port) {
9623 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009624 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309625 break;
9626 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009627 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309628 break;
9629 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009630 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309631 break;
9632 default:
9633 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009634 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309635 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009636
9637 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309638}
9639
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009640static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9641 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009642 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009643{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009644 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009645 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009646
9647 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009648 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009649
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009650 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009651 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009652
9653 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009654}
9655
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009656static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9657 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009658 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009659{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009660 enum intel_dpll_id id;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009661 u32 ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009662
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009663 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009664 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009665 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009666 break;
9667 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009668 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009669 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009670 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009671 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009672 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009673 case PORT_CLK_SEL_LCPLL_810:
9674 id = DPLL_ID_LCPLL_810;
9675 break;
9676 case PORT_CLK_SEL_LCPLL_1350:
9677 id = DPLL_ID_LCPLL_1350;
9678 break;
9679 case PORT_CLK_SEL_LCPLL_2700:
9680 id = DPLL_ID_LCPLL_2700;
9681 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009682 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009683 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009684 /* fall through */
9685 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009686 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009687 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009688
9689 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009690}
9691
Jani Nikulacf304292016-03-18 17:05:41 +02009692static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9693 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009694 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009695{
9696 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009697 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009698 enum intel_display_power_domain power_domain;
Jani Nikula07169312018-12-04 12:19:26 +02009699 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9700 unsigned long enabled_panel_transcoders = 0;
9701 enum transcoder panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009702 u32 tmp;
9703
Jani Nikula07169312018-12-04 12:19:26 +02009704 if (IS_ICELAKE(dev_priv))
9705 panel_transcoder_mask |=
9706 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
Jani Nikulacf304292016-03-18 17:05:41 +02009707
Imre Deakd9a7bc62016-05-12 16:18:50 +03009708 /*
9709 * The pipe->transcoder mapping is fixed with the exception of the eDP
Jani Nikula07169312018-12-04 12:19:26 +02009710 * and DSI transcoders handled below.
Imre Deakd9a7bc62016-05-12 16:18:50 +03009711 */
Jani Nikulacf304292016-03-18 17:05:41 +02009712 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9713
9714 /*
9715 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9716 * consistency and less surprising code; it's in always on power).
9717 */
Chris Wilson1b4bd5c2019-01-16 15:54:21 +00009718 for_each_set_bit(panel_transcoder,
9719 &panel_transcoder_mask,
9720 ARRAY_SIZE(INTEL_INFO(dev_priv)->trans_offsets)) {
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009721 enum pipe trans_pipe;
Jani Nikula07169312018-12-04 12:19:26 +02009722
9723 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9724 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9725 continue;
9726
9727 /*
9728 * Log all enabled ones, only use the first one.
9729 *
9730 * FIXME: This won't work for two separate DSI displays.
9731 */
9732 enabled_panel_transcoders |= BIT(panel_transcoder);
9733 if (enabled_panel_transcoders != BIT(panel_transcoder))
9734 continue;
9735
Jani Nikulacf304292016-03-18 17:05:41 +02009736 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9737 default:
Jani Nikula07169312018-12-04 12:19:26 +02009738 WARN(1, "unknown pipe linked to transcoder %s\n",
9739 transcoder_name(panel_transcoder));
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009740 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009741 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9742 case TRANS_DDI_EDP_INPUT_A_ON:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009743 trans_pipe = PIPE_A;
Jani Nikulacf304292016-03-18 17:05:41 +02009744 break;
9745 case TRANS_DDI_EDP_INPUT_B_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009746 trans_pipe = PIPE_B;
Jani Nikulacf304292016-03-18 17:05:41 +02009747 break;
9748 case TRANS_DDI_EDP_INPUT_C_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009749 trans_pipe = PIPE_C;
Jani Nikulacf304292016-03-18 17:05:41 +02009750 break;
9751 }
9752
Jani Nikula07169312018-12-04 12:19:26 +02009753 if (trans_pipe == crtc->pipe)
9754 pipe_config->cpu_transcoder = panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009755 }
9756
Jani Nikula07169312018-12-04 12:19:26 +02009757 /*
9758 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9759 */
9760 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9761 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9762
Jani Nikulacf304292016-03-18 17:05:41 +02009763 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9764 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9765 return false;
Chris Wilson04161d62019-01-14 14:21:27 +00009766
9767 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009768 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009769
9770 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9771
9772 return tmp & PIPECONF_ENABLE;
9773}
9774
Jani Nikula4d1de972016-03-18 17:05:42 +02009775static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9776 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009777 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009778{
9779 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009780 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009781 enum intel_display_power_domain power_domain;
9782 enum port port;
9783 enum transcoder cpu_transcoder;
9784 u32 tmp;
9785
Jani Nikula4d1de972016-03-18 17:05:42 +02009786 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9787 if (port == PORT_A)
9788 cpu_transcoder = TRANSCODER_DSI_A;
9789 else
9790 cpu_transcoder = TRANSCODER_DSI_C;
9791
9792 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9793 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9794 continue;
Chris Wilson04161d62019-01-14 14:21:27 +00009795
9796 WARN_ON(*power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009797 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009798
Imre Deakdb18b6a2016-03-24 12:41:40 +02009799 /*
9800 * The PLL needs to be enabled with a valid divider
9801 * configuration, otherwise accessing DSI registers will hang
9802 * the machine. See BSpec North Display Engine
9803 * registers/MIPI[BXT]. We can break out here early, since we
9804 * need the same DSI PLL to be enabled for both DSI ports.
9805 */
Jani Nikulae5186342018-07-05 16:25:08 +03009806 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009807 break;
9808
Jani Nikula4d1de972016-03-18 17:05:42 +02009809 /* XXX: this works for video mode only */
9810 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9811 if (!(tmp & DPI_ENABLE))
9812 continue;
9813
9814 tmp = I915_READ(MIPI_CTRL(port));
9815 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9816 continue;
9817
9818 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009819 break;
9820 }
9821
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009822 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009823}
9824
Daniel Vetter26804af2014-06-25 22:01:55 +03009825static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009826 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009827{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009828 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009829 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009830 enum port port;
Jani Nikulaba3f4d02019-01-18 14:01:23 +02009831 u32 tmp;
Daniel Vetter26804af2014-06-25 22:01:55 +03009832
9833 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9834
9835 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9836
Paulo Zanoni970888e2018-05-21 17:25:44 -07009837 if (IS_ICELAKE(dev_priv))
9838 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9839 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009840 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9841 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009842 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009843 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309844 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009845 else
9846 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009847
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009848 pll = pipe_config->shared_dpll;
9849 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009850 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9851 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009852 }
9853
Daniel Vetter26804af2014-06-25 22:01:55 +03009854 /*
9855 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9856 * DDI E. So just check whether this pipe is wired to DDI E and whether
9857 * the PCH transcoder is on.
9858 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009859 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009860 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009861 pipe_config->has_pch_encoder = true;
9862
9863 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9864 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9865 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9866
9867 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9868 }
9869}
9870
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009871static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009872 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009873{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009874 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009875 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009876 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009877 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009878
Imre Deake79dfb52017-07-20 01:50:57 +03009879 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009880
Imre Deak17290502016-02-12 18:55:11 +02009881 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9882 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009883 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009884 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009885
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009886 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009887
Jani Nikulacf304292016-03-18 17:05:41 +02009888 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009889
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009890 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009891 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9892 WARN_ON(active);
9893 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009894 }
9895
Jani Nikulacf304292016-03-18 17:05:41 +02009896 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009897 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009898
Madhav Chauhan2eae5d62018-11-29 16:12:28 +02009899 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9900 IS_ICELAKE(dev_priv)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009901 haswell_get_ddi_port_state(crtc, pipe_config);
9902 intel_get_pipe_timings(crtc, pipe_config);
9903 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009904
Jani Nikulabc58be62016-03-18 17:05:39 +02009905 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309906 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009907
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009908 pipe_config->gamma_mode =
9909 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9910
Imre Deak17290502016-02-12 18:55:11 +02009911 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9912 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Chris Wilson04161d62019-01-14 14:21:27 +00009913 WARN_ON(power_domain_mask & BIT_ULL(power_domain));
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009914 power_domain_mask |= BIT_ULL(power_domain);
Chris Wilson04161d62019-01-14 14:21:27 +00009915
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009916 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009917 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009918 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009919 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009920 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009921
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009922 if (hsw_crtc_supports_ips(crtc)) {
9923 if (IS_HASWELL(dev_priv))
9924 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9925 else {
9926 /*
9927 * We cannot readout IPS state on broadwell, set to
9928 * true so we can set it to a defined state on first
9929 * commit.
9930 */
9931 pipe_config->ips_enabled = true;
9932 }
9933 }
9934
Jani Nikula4d1de972016-03-18 17:05:42 +02009935 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9936 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009937 pipe_config->pixel_multiplier =
9938 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9939 } else {
9940 pipe_config->pixel_multiplier = 1;
9941 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009942
Imre Deak17290502016-02-12 18:55:11 +02009943out:
9944 for_each_power_domain(power_domain, power_domain_mask)
Chris Wilson0e6e0be2019-01-14 14:21:24 +00009945 intel_display_power_put_unchecked(dev_priv, power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009946
Jani Nikulacf304292016-03-18 17:05:41 +02009947 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009948}
9949
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009950static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009951{
9952 struct drm_i915_private *dev_priv =
9953 to_i915(plane_state->base.plane->dev);
9954 const struct drm_framebuffer *fb = plane_state->base.fb;
9955 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9956 u32 base;
9957
José Roberto de Souzad53db442018-11-30 15:20:48 -08009958 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009959 base = obj->phys_handle->busaddr;
9960 else
9961 base = intel_plane_ggtt_offset(plane_state);
9962
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009963 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009964
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009965 /* ILK+ do this automagically */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -08009966 if (HAS_GMCH(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009967 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009968 base += (plane_state->base.crtc_h *
9969 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9970
9971 return base;
9972}
9973
Ville Syrjäläed270222017-03-27 21:55:36 +03009974static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9975{
9976 int x = plane_state->base.crtc_x;
9977 int y = plane_state->base.crtc_y;
9978 u32 pos = 0;
9979
9980 if (x < 0) {
9981 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9982 x = -x;
9983 }
9984 pos |= x << CURSOR_X_SHIFT;
9985
9986 if (y < 0) {
9987 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9988 y = -y;
9989 }
9990 pos |= y << CURSOR_Y_SHIFT;
9991
9992 return pos;
9993}
9994
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009995static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9996{
9997 const struct drm_mode_config *config =
9998 &plane_state->base.plane->dev->mode_config;
9999 int width = plane_state->base.crtc_w;
10000 int height = plane_state->base.crtc_h;
10001
10002 return width > 0 && width <= config->cursor_width &&
10003 height > 0 && height <= config->cursor_height;
10004}
10005
Ville Syrjäläfce8d232018-09-07 18:24:13 +030010006static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010007{
10008 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010009 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +030010010 int src_x, src_y;
10011 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +030010012 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +030010013
10014 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
10015 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
10016
Ville Syrjäläfc3fed52018-09-18 17:02:43 +030010017 ret = intel_plane_check_stride(plane_state);
10018 if (ret)
10019 return ret;
10020
Ville Syrjäläfce8d232018-09-07 18:24:13 +030010021 src_x = plane_state->base.src_x >> 16;
10022 src_y = plane_state->base.src_y >> 16;
10023
10024 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
10025 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
10026 plane_state, 0);
10027
10028 if (src_x != 0 || src_y != 0) {
10029 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
10030 return -EINVAL;
10031 }
10032
10033 plane_state->color_plane[0].offset = offset;
10034
10035 return 0;
10036}
10037
10038static int intel_check_cursor(struct intel_crtc_state *crtc_state,
10039 struct intel_plane_state *plane_state)
10040{
10041 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010042 int ret;
10043
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030010044 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
10045 DRM_DEBUG_KMS("cursor cannot be tiled\n");
10046 return -EINVAL;
10047 }
10048
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +020010049 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
10050 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +020010051 DRM_PLANE_HELPER_NO_SCALING,
10052 DRM_PLANE_HELPER_NO_SCALING,
10053 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010054 if (ret)
10055 return ret;
10056
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030010057 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010058 return 0;
10059
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030010060 ret = intel_plane_check_src_coordinates(plane_state);
10061 if (ret)
10062 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010063
Ville Syrjäläfce8d232018-09-07 18:24:13 +030010064 ret = intel_cursor_check_surface(plane_state);
10065 if (ret)
10066 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +030010067
Ville Syrjälä659056f2017-03-27 21:55:39 +030010068 return 0;
10069}
10070
Ville Syrjäläddd57132018-09-07 18:24:02 +030010071static unsigned int
10072i845_cursor_max_stride(struct intel_plane *plane,
10073 u32 pixel_format, u64 modifier,
10074 unsigned int rotation)
10075{
10076 return 2048;
10077}
10078
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010079static u32 i845_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10080{
10081 return CURSOR_GAMMA_ENABLE;
10082}
10083
Ville Syrjälä292889e2017-03-17 23:18:01 +020010084static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
10085 const struct intel_plane_state *plane_state)
10086{
Ville Syrjälä292889e2017-03-17 23:18:01 +020010087 return CURSOR_ENABLE |
Ville Syrjälä292889e2017-03-17 23:18:01 +020010088 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010089 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +020010090}
10091
Ville Syrjälä659056f2017-03-27 21:55:39 +030010092static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
10093{
Ville Syrjälä659056f2017-03-27 21:55:39 +030010094 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010095
10096 /*
10097 * 845g/865g are only limited by the width of their cursors,
10098 * the height is arbitrary up to the precision of the register.
10099 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010100 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010101}
10102
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010103static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010104 struct intel_plane_state *plane_state)
10105{
10106 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010107 int ret;
10108
10109 ret = intel_check_cursor(crtc_state, plane_state);
10110 if (ret)
10111 return ret;
10112
10113 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010114 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010115 return 0;
10116
10117 /* Check for which cursor types we support */
10118 if (!i845_cursor_size_ok(plane_state)) {
10119 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10120 plane_state->base.crtc_w,
10121 plane_state->base.crtc_h);
10122 return -EINVAL;
10123 }
10124
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010125 WARN_ON(plane_state->base.visible &&
10126 plane_state->color_plane[0].stride != fb->pitches[0]);
10127
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010128 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +010010129 case 256:
10130 case 512:
10131 case 1024:
10132 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +030010133 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010134 default:
10135 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
10136 fb->pitches[0]);
10137 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +010010138 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +010010139
Ville Syrjälä659056f2017-03-27 21:55:39 +030010140 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
10141
10142 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010143}
10144
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010145static void i845_update_cursor(struct intel_plane *plane,
10146 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +010010147 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);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010150 u32 cntl = 0, base = 0, pos = 0, size = 0;
10151 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +010010152
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010153 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +010010154 unsigned int width = plane_state->base.crtc_w;
10155 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010156
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010157 cntl = plane_state->ctl |
10158 i845_cursor_ctl_crtc(crtc_state);
10159
Ville Syrjälädc41c152014-08-13 11:57:05 +030010160 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010161
10162 base = intel_cursor_base(plane_state);
10163 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +030010164 }
Chris Wilson560b85b2010-08-07 11:01:38 +010010165
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010166 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10167
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010168 /* On these chipsets we can only modify the base/size/stride
10169 * whilst the cursor is disabled.
10170 */
10171 if (plane->cursor.base != base ||
10172 plane->cursor.size != size ||
10173 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010174 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010175 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010176 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010177 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +020010178 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010179
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010180 plane->cursor.base = base;
10181 plane->cursor.size = size;
10182 plane->cursor.cntl = cntl;
10183 } else {
10184 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +030010185 }
10186
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010187 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
10188}
10189
10190static void i845_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010191 const struct intel_crtc_state *crtc_state)
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010192{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010193 i845_update_cursor(plane, crtc_state, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +010010194}
10195
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010196static bool i845_cursor_get_hw_state(struct intel_plane *plane,
10197 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010198{
10199 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10200 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010201 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010202 bool ret;
10203
10204 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010205 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10206 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010207 return false;
10208
10209 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
10210
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010211 *pipe = PIPE_A;
10212
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010213 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010214
10215 return ret;
10216}
10217
Ville Syrjäläddd57132018-09-07 18:24:02 +030010218static unsigned int
10219i9xx_cursor_max_stride(struct intel_plane *plane,
10220 u32 pixel_format, u64 modifier,
10221 unsigned int rotation)
10222{
10223 return plane->base.dev->mode_config.cursor_width * 4;
10224}
10225
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010226static u32 i9xx_cursor_ctl_crtc(const struct intel_crtc_state *crtc_state)
10227{
10228 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10229 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10230 u32 cntl = 0;
10231
10232 if (INTEL_GEN(dev_priv) >= 11)
10233 return cntl;
10234
10235 cntl |= MCURSOR_GAMMA_ENABLE;
10236
10237 if (HAS_DDI(dev_priv))
10238 cntl |= MCURSOR_PIPE_CSC_ENABLE;
10239
10240 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10241 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
10242
10243 return cntl;
10244}
10245
Ville Syrjälä292889e2017-03-17 23:18:01 +020010246static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
10247 const struct intel_plane_state *plane_state)
10248{
10249 struct drm_i915_private *dev_priv =
10250 to_i915(plane_state->base.plane->dev);
José Roberto de Souzac894d632018-05-18 13:15:47 -070010251 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010252
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010253 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjäläe876b782018-01-30 22:38:05 +020010254 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10255
Ville Syrjälä292889e2017-03-17 23:18:01 +020010256 switch (plane_state->base.crtc_w) {
10257 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010258 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010259 break;
10260 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010261 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010262 break;
10263 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010264 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010265 break;
10266 default:
10267 MISSING_CASE(plane_state->base.crtc_w);
10268 return 0;
10269 }
10270
Robert Fossc2c446a2017-05-19 16:50:17 -040010271 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010272 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010273
10274 return cntl;
10275}
10276
Ville Syrjälä659056f2017-03-27 21:55:39 +030010277static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +010010278{
Ville Syrjälä024faac2017-03-27 21:55:42 +030010279 struct drm_i915_private *dev_priv =
10280 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010281 int width = plane_state->base.crtc_w;
10282 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +010010283
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010284 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +030010285 return false;
10286
Ville Syrjälä024faac2017-03-27 21:55:42 +030010287 /* Cursor width is limited to a few power-of-two sizes */
10288 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +030010289 case 256:
10290 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +030010291 case 64:
10292 break;
10293 default:
10294 return false;
10295 }
10296
Ville Syrjälädc41c152014-08-13 11:57:05 +030010297 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +030010298 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10299 * height from 8 lines up to the cursor width, when the
10300 * cursor is not rotated. Everything else requires square
10301 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +030010302 */
Ville Syrjälä024faac2017-03-27 21:55:42 +030010303 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +100010304 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010305 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010306 return false;
10307 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010308 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010309 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010310 }
10311
10312 return true;
10313}
10314
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010315static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010316 struct intel_plane_state *plane_state)
10317{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010318 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010319 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10320 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010321 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010322 int ret;
10323
10324 ret = intel_check_cursor(crtc_state, plane_state);
10325 if (ret)
10326 return ret;
10327
10328 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010329 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010330 return 0;
10331
10332 /* Check for which cursor types we support */
10333 if (!i9xx_cursor_size_ok(plane_state)) {
10334 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10335 plane_state->base.crtc_w,
10336 plane_state->base.crtc_h);
10337 return -EINVAL;
10338 }
10339
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010340 WARN_ON(plane_state->base.visible &&
10341 plane_state->color_plane[0].stride != fb->pitches[0]);
10342
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010343 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10344 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10345 fb->pitches[0], plane_state->base.crtc_w);
10346 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010347 }
10348
10349 /*
10350 * There's something wrong with the cursor on CHV pipe C.
10351 * If it straddles the left edge of the screen then
10352 * moving it away from the edge or disabling it often
10353 * results in a pipe underrun, and often that can lead to
10354 * dead pipe (constant underrun reported, and it scans
10355 * out just a solid color). To recover from that, the
10356 * display power well must be turned off and on again.
10357 * Refuse the put the cursor into that compromised position.
10358 */
10359 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10360 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10361 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10362 return -EINVAL;
10363 }
10364
10365 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10366
10367 return 0;
10368}
10369
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010370static void i9xx_update_cursor(struct intel_plane *plane,
10371 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010372 const struct intel_plane_state *plane_state)
10373{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010374 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10375 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +030010376 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010377 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010378
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010379 if (plane_state && plane_state->base.visible) {
Ville Syrjälä7eb31a02019-02-05 18:08:36 +020010380 cntl = plane_state->ctl |
10381 i9xx_cursor_ctl_crtc(crtc_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +030010382
Ville Syrjälä024faac2017-03-27 21:55:42 +030010383 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10384 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10385
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010386 base = intel_cursor_base(plane_state);
10387 pos = intel_cursor_position(plane_state);
10388 }
10389
10390 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10391
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010392 /*
10393 * On some platforms writing CURCNTR first will also
10394 * cause CURPOS to be armed by the CURBASE write.
10395 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä83234d12018-11-14 23:07:17 +020010396 * arm itself. Thus we always update CURCNTR before
10397 * CURPOS.
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010398 *
10399 * On other platforms CURPOS always requires the
10400 * CURBASE write to arm the update. Additonally
10401 * a write to any of the cursor register will cancel
10402 * an already armed cursor update. Thus leaving out
10403 * the CURBASE write after CURPOS could lead to a
10404 * cursor that doesn't appear to move, or even change
10405 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010406 *
Ville Syrjälä83234d12018-11-14 23:07:17 +020010407 * The other registers are armed by by the CURBASE write
10408 * except when the plane is getting enabled at which time
10409 * the CURCNTR write arms the update.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010410 */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020010411
10412 if (INTEL_GEN(dev_priv) >= 9)
10413 skl_write_cursor_wm(plane, crtc_state);
10414
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010415 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010416 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010417 plane->cursor.cntl != cntl) {
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010418 if (HAS_CUR_FBC(dev_priv))
10419 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
Ville Syrjälä83234d12018-11-14 23:07:17 +020010420 I915_WRITE_FW(CURCNTR(pipe), cntl);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010421 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010422 I915_WRITE_FW(CURBASE(pipe), base);
10423
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010424 plane->cursor.base = base;
10425 plane->cursor.size = fbc_ctl;
10426 plane->cursor.cntl = cntl;
10427 } else {
10428 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010429 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010430 }
10431
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010432 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010433}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010434
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010435static void i9xx_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010436 const struct intel_crtc_state *crtc_state)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010437{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010438 i9xx_update_cursor(plane, crtc_state, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010439}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010440
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010441static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10442 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010443{
10444 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10445 enum intel_display_power_domain power_domain;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010446 intel_wakeref_t wakeref;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010447 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010448 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010449
10450 /*
10451 * Not 100% correct for planes that can move between pipes,
10452 * but that's only the case for gen2-3 which don't have any
10453 * display power wells.
10454 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010455 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010456 wakeref = intel_display_power_get_if_enabled(dev_priv, power_domain);
10457 if (!wakeref)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010458 return false;
10459
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010460 val = I915_READ(CURCNTR(plane->pipe));
10461
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010462 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010463
10464 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10465 *pipe = plane->pipe;
10466 else
10467 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10468 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010469
Chris Wilson0e6e0be2019-01-14 14:21:24 +000010470 intel_display_power_put(dev_priv, power_domain, wakeref);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010471
10472 return ret;
10473}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010474
Jesse Barnes79e53942008-11-07 14:24:08 -080010475/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010476static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010477 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10478 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10479};
10480
Daniel Vettera8bb6812014-02-10 18:00:39 +010010481struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010482intel_framebuffer_create(struct drm_i915_gem_object *obj,
10483 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010484{
10485 struct intel_framebuffer *intel_fb;
10486 int ret;
10487
10488 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010489 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010490 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010491
Chris Wilson24dbf512017-02-15 10:59:18 +000010492 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010493 if (ret)
10494 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010495
10496 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010497
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010498err:
10499 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010500 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010501}
10502
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010503static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10504 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010505{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010506 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010507 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010508 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010509
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010510 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010511 if (ret)
10512 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010513
10514 for_each_new_plane_in_state(state, plane, plane_state, i) {
10515 if (plane_state->crtc != crtc)
10516 continue;
10517
10518 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10519 if (ret)
10520 return ret;
10521
10522 drm_atomic_set_fb_for_plane(plane_state, NULL);
10523 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010524
10525 return 0;
10526}
10527
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010528int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010529 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010530 struct intel_load_detect_pipe *old,
10531 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010532{
10533 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010534 struct intel_encoder *intel_encoder =
10535 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010536 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010537 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010538 struct drm_crtc *crtc = NULL;
10539 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010540 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010541 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010542 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010543 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010544 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010545 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010546
Chris Wilsond2dff872011-04-19 08:36:26 +010010547 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010548 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010549 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010550
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010551 old->restore_state = NULL;
10552
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010553 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010554
Jesse Barnes79e53942008-11-07 14:24:08 -080010555 /*
10556 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010557 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010558 * - if the connector already has an assigned crtc, use it (but make
10559 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010560 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010561 * - try to find the first unused crtc that can drive this connector,
10562 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010563 */
10564
10565 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010566 if (connector->state->crtc) {
10567 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010568
Rob Clark51fd3712013-11-19 12:10:12 -050010569 ret = drm_modeset_lock(&crtc->mutex, ctx);
10570 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010571 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010572
10573 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010574 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010575 }
10576
10577 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010578 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010579 i++;
10580 if (!(encoder->possible_crtcs & (1 << i)))
10581 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010582
10583 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10584 if (ret)
10585 goto fail;
10586
10587 if (possible_crtc->state->enable) {
10588 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010589 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010590 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010591
10592 crtc = possible_crtc;
10593 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010594 }
10595
10596 /*
10597 * If we didn't find an unused CRTC, don't use any.
10598 */
10599 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010600 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010601 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010602 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010603 }
10604
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010605found:
10606 intel_crtc = to_intel_crtc(crtc);
10607
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010608 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010609 restore_state = drm_atomic_state_alloc(dev);
10610 if (!state || !restore_state) {
10611 ret = -ENOMEM;
10612 goto fail;
10613 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010614
10615 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010616 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010617
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010618 connector_state = drm_atomic_get_connector_state(state, connector);
10619 if (IS_ERR(connector_state)) {
10620 ret = PTR_ERR(connector_state);
10621 goto fail;
10622 }
10623
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010624 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10625 if (ret)
10626 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010627
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010628 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10629 if (IS_ERR(crtc_state)) {
10630 ret = PTR_ERR(crtc_state);
10631 goto fail;
10632 }
10633
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010634 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010635
Chris Wilson64927112011-04-20 07:25:26 +010010636 if (!mode)
10637 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010638
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010639 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010640 if (ret)
10641 goto fail;
10642
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010643 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010644 if (ret)
10645 goto fail;
10646
10647 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10648 if (!ret)
10649 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010650 if (!ret)
10651 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010652 if (ret) {
10653 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10654 goto fail;
10655 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010656
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010657 ret = drm_atomic_commit(state);
10658 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010659 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010660 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010661 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010662
10663 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010664 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010665
Jesse Barnes79e53942008-11-07 14:24:08 -080010666 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010667 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010668 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010669
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010670fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010671 if (state) {
10672 drm_atomic_state_put(state);
10673 state = NULL;
10674 }
10675 if (restore_state) {
10676 drm_atomic_state_put(restore_state);
10677 restore_state = NULL;
10678 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010679
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010680 if (ret == -EDEADLK)
10681 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010682
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010683 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010684}
10685
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010686void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010687 struct intel_load_detect_pipe *old,
10688 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010689{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010690 struct intel_encoder *intel_encoder =
10691 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010692 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010693 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010694 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010695
Chris Wilsond2dff872011-04-19 08:36:26 +010010696 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010697 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010698 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010699
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010700 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010701 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010702
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010703 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010704 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010705 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010706 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010707}
10708
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010709static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010710 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010711{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010712 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010713 u32 dpll = pipe_config->dpll_hw_state.dpll;
10714
10715 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010716 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010717 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010718 return 120000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010719 else if (!IS_GEN(dev_priv, 2))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010720 return 96000;
10721 else
10722 return 48000;
10723}
10724
Jesse Barnes79e53942008-11-07 14:24:08 -080010725/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010726static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010727 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010728{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010729 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010730 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010731 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010732 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010733 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010734 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010735 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010736 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010737
10738 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010739 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010740 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010741 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010742
10743 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010744 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010745 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10746 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010747 } else {
10748 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10749 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10750 }
10751
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010752 if (!IS_GEN(dev_priv, 2)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010753 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010754 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10755 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010756 else
10757 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010758 DPLL_FPA01_P1_POST_DIV_SHIFT);
10759
10760 switch (dpll & DPLL_MODE_MASK) {
10761 case DPLLB_MODE_DAC_SERIAL:
10762 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10763 5 : 10;
10764 break;
10765 case DPLLB_MODE_LVDS:
10766 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10767 7 : 14;
10768 break;
10769 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010770 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010771 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010772 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010773 }
10774
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010775 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010776 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010777 else
Imre Deakdccbea32015-06-22 23:35:51 +030010778 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010779 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010780 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010781 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010782
10783 if (is_lvds) {
10784 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10785 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010786
10787 if (lvds & LVDS_CLKB_POWER_UP)
10788 clock.p2 = 7;
10789 else
10790 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010791 } else {
10792 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10793 clock.p1 = 2;
10794 else {
10795 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10796 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10797 }
10798 if (dpll & PLL_P2_DIVIDE_BY_4)
10799 clock.p2 = 4;
10800 else
10801 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010802 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010803
Imre Deakdccbea32015-06-22 23:35:51 +030010804 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010805 }
10806
Ville Syrjälä18442d02013-09-13 16:00:08 +030010807 /*
10808 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010809 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010810 * encoder's get_config() function.
10811 */
Imre Deakdccbea32015-06-22 23:35:51 +030010812 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010813}
10814
Ville Syrjälä6878da02013-09-13 15:59:11 +030010815int intel_dotclock_calculate(int link_freq,
10816 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010817{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010818 /*
10819 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010820 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010821 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010822 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010823 *
10824 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010825 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010826 */
10827
Ville Syrjälä6878da02013-09-13 15:59:11 +030010828 if (!m_n->link_n)
10829 return 0;
10830
Chris Wilson31236982017-09-13 11:51:53 +010010831 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 +030010832}
10833
Ville Syrjälä18442d02013-09-13 16:00:08 +030010834static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010835 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010836{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010837 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010838
10839 /* read out port_clock from the DPLL */
10840 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010841
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010842 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010843 * In case there is an active pipe without active ports,
10844 * we may need some idea for the dotclock anyway.
10845 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010846 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010847 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010848 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010849 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010850}
10851
Ville Syrjäläde330812017-10-09 19:19:50 +030010852/* Returns the currently programmed mode of the given encoder. */
10853struct drm_display_mode *
10854intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010855{
Ville Syrjäläde330812017-10-09 19:19:50 +030010856 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10857 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010858 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010859 struct intel_crtc *crtc;
10860 enum pipe pipe;
10861
10862 if (!encoder->get_hw_state(encoder, &pipe))
10863 return NULL;
10864
10865 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010866
10867 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10868 if (!mode)
10869 return NULL;
10870
Ville Syrjäläde330812017-10-09 19:19:50 +030010871 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10872 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010873 kfree(mode);
10874 return NULL;
10875 }
10876
Ville Syrjäläde330812017-10-09 19:19:50 +030010877 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010878
Ville Syrjäläde330812017-10-09 19:19:50 +030010879 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10880 kfree(crtc_state);
10881 kfree(mode);
10882 return NULL;
10883 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010884
Ville Syrjäläde330812017-10-09 19:19:50 +030010885 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010886
Ville Syrjäläde330812017-10-09 19:19:50 +030010887 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010888
Ville Syrjäläde330812017-10-09 19:19:50 +030010889 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010890
Jesse Barnes79e53942008-11-07 14:24:08 -080010891 return mode;
10892}
10893
10894static void intel_crtc_destroy(struct drm_crtc *crtc)
10895{
10896 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10897
10898 drm_crtc_cleanup(crtc);
10899 kfree(intel_crtc);
10900}
10901
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010902/**
10903 * intel_wm_need_update - Check whether watermarks need updating
Chris Wilson6bf19812018-12-31 14:35:05 +000010904 * @cur: current plane state
10905 * @new: new plane state
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010906 *
10907 * Check current plane state versus the new one to determine whether
10908 * watermarks need to be recalculated.
10909 *
10910 * Returns true or false.
10911 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010912static bool intel_wm_need_update(struct intel_plane_state *cur,
10913 struct intel_plane_state *new)
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010914{
Matt Roperd21fbe82015-09-24 15:53:12 -070010915 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010916 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010917 return true;
10918
10919 if (!cur->base.fb || !new->base.fb)
10920 return false;
10921
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010922 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010923 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010924 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10925 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10926 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10927 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010928 return true;
10929
10930 return false;
10931}
10932
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010933static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010934{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010935 int src_w = drm_rect_width(&state->base.src) >> 16;
10936 int src_h = drm_rect_height(&state->base.src) >> 16;
10937 int dst_w = drm_rect_width(&state->base.dst);
10938 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010939
10940 return (src_w != dst_w || src_h != dst_h);
10941}
10942
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010943int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10944 struct drm_crtc_state *crtc_state,
10945 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010946 struct drm_plane_state *plane_state)
10947{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010948 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010949 struct drm_crtc *crtc = crtc_state->crtc;
10950 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010951 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010952 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010953 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010954 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010955 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010956 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010957 bool turn_off, turn_on, visible, was_visible;
10958 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010959 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010960
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010961 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010962 ret = skl_update_scaler_plane(
10963 to_intel_crtc_state(crtc_state),
10964 to_intel_plane_state(plane_state));
10965 if (ret)
10966 return ret;
10967 }
10968
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010969 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010970 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010971
10972 if (!was_crtc_enabled && WARN_ON(was_visible))
10973 was_visible = false;
10974
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010975 /*
10976 * Visibility is calculated as if the crtc was on, but
10977 * after scaler setup everything depends on it being off
10978 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010979 *
10980 * FIXME this is wrong for watermarks. Watermarks should also
10981 * be computed as if the pipe would be active. Perhaps move
10982 * per-plane wm computation to the .check_plane() hook, and
10983 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010984 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010985 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010986 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010987 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10988 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010989
10990 if (!was_visible && !visible)
10991 return 0;
10992
Maarten Lankhorste8861672016-02-24 11:24:26 +010010993 if (fb != old_plane_state->base.fb)
10994 pipe_config->fb_changed = true;
10995
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010996 turn_off = was_visible && (!visible || mode_changed);
10997 turn_on = visible && (!was_visible || mode_changed);
10998
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010999 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020011000 intel_crtc->base.base.id, intel_crtc->base.name,
11001 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030011002 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011003
Ville Syrjälä72660ce2016-05-27 20:59:20 +030011004 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 +020011005 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030011006 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011007 turn_off, turn_on, mode_changed);
11008
Ville Syrjäläcaed3612016-03-09 19:07:25 +020011009 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011010 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020011011 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020011012
11013 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020011014 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020011015 pipe_config->disable_cxsr = true;
11016 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011017 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020011018 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010011019
Ville Syrjälä852eb002015-06-24 22:00:07 +030011020 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020011021 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010011022 pipe_config->disable_cxsr = true;
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011023 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
11024 to_intel_plane_state(plane_state))) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011025 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020011026 /* FIXME bollocks */
11027 pipe_config->update_wm_pre = true;
11028 pipe_config->update_wm_post = true;
11029 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030011030 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011031
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070011032 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020011033 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030011034
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011035 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030011036 * ILK/SNB DVSACNTR/Sprite Enable
11037 * IVB SPR_CTL/Sprite Enable
11038 * "When in Self Refresh Big FIFO mode, a write to enable the
11039 * plane will be internally buffered and delayed while Big FIFO
11040 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011041 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030011042 * Which means that enabling the sprite can take an extra frame
11043 * when we start in big FIFO mode (LP1+). Thus we need to drop
11044 * down to LP0 and wait for vblank in order to make sure the
11045 * sprite gets enabled on the next vblank after the register write.
11046 * Doing otherwise would risk enabling the sprite one frame after
11047 * we've already signalled flip completion. We can resume LP1+
11048 * once the sprite has been enabled.
11049 *
11050 *
11051 * WaCxSRDisabledForSpriteScaling:ivb
11052 * IVB SPR_SCALE/Scaling Enable
11053 * "Low Power watermarks must be disabled for at least one
11054 * frame before enabling sprite scaling, and kept disabled
11055 * until sprite scaling is disabled."
11056 *
11057 * ILK/SNB DVSASCALE/Scaling Enable
11058 * "When in Self Refresh Big FIFO mode, scaling enable will be
11059 * masked off while Big FIFO mode is exiting."
11060 *
11061 * Despite the w/a only being listed for IVB we assume that
11062 * the ILK/SNB note has similar ramifications, hence we apply
11063 * the w/a on all three platforms.
Juha-Pekka Heikkilad8af3272018-12-20 13:26:08 +020011064 *
11065 * With experimental results seems this is needed also for primary
11066 * plane, not only sprite plane.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011067 */
Juha-Pekka Heikkilad8af3272018-12-20 13:26:08 +020011068 if (plane->id != PLANE_CURSOR &&
Lucas De Marchif3ce44a2018-12-12 10:10:44 -080011069 (IS_GEN_RANGE(dev_priv, 5, 6) ||
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030011070 IS_IVYBRIDGE(dev_priv)) &&
11071 (turn_on || (!needs_scaling(old_plane_state) &&
11072 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010011073 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011074
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020011075 return 0;
11076}
11077
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011078static bool encoders_cloneable(const struct intel_encoder *a,
11079 const struct intel_encoder *b)
11080{
11081 /* masks could be asymmetric, so check both ways */
11082 return a == b || (a->cloneable & (1 << b->type) &&
11083 b->cloneable & (1 << a->type));
11084}
11085
11086static bool check_single_encoder_cloning(struct drm_atomic_state *state,
11087 struct intel_crtc *crtc,
11088 struct intel_encoder *encoder)
11089{
11090 struct intel_encoder *source_encoder;
11091 struct drm_connector *connector;
11092 struct drm_connector_state *connector_state;
11093 int i;
11094
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011095 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011096 if (connector_state->crtc != &crtc->base)
11097 continue;
11098
11099 source_encoder =
11100 to_intel_encoder(connector_state->best_encoder);
11101 if (!encoders_cloneable(encoder, source_encoder))
11102 return false;
11103 }
11104
11105 return true;
11106}
11107
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011108static int icl_add_linked_planes(struct intel_atomic_state *state)
11109{
11110 struct intel_plane *plane, *linked;
11111 struct intel_plane_state *plane_state, *linked_plane_state;
11112 int i;
11113
11114 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11115 linked = plane_state->linked_plane;
11116
11117 if (!linked)
11118 continue;
11119
11120 linked_plane_state = intel_atomic_get_plane_state(state, linked);
11121 if (IS_ERR(linked_plane_state))
11122 return PTR_ERR(linked_plane_state);
11123
11124 WARN_ON(linked_plane_state->linked_plane != plane);
11125 WARN_ON(linked_plane_state->slave == plane_state->slave);
11126 }
11127
11128 return 0;
11129}
11130
11131static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
11132{
11133 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
11134 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
11135 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
11136 struct intel_plane *plane, *linked;
11137 struct intel_plane_state *plane_state;
11138 int i;
11139
11140 if (INTEL_GEN(dev_priv) < 11)
11141 return 0;
11142
11143 /*
11144 * Destroy all old plane links and make the slave plane invisible
11145 * in the crtc_state->active_planes mask.
11146 */
11147 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11148 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
11149 continue;
11150
11151 plane_state->linked_plane = NULL;
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011152 if (plane_state->slave && !plane_state->base.visible) {
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011153 crtc_state->active_planes &= ~BIT(plane->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011154 crtc_state->update_planes |= BIT(plane->id);
11155 }
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011156
11157 plane_state->slave = false;
11158 }
11159
11160 if (!crtc_state->nv12_planes)
11161 return 0;
11162
11163 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
11164 struct intel_plane_state *linked_state = NULL;
11165
11166 if (plane->pipe != crtc->pipe ||
11167 !(crtc_state->nv12_planes & BIT(plane->id)))
11168 continue;
11169
11170 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
11171 if (!icl_is_nv12_y_plane(linked->id))
11172 continue;
11173
11174 if (crtc_state->active_planes & BIT(linked->id))
11175 continue;
11176
11177 linked_state = intel_atomic_get_plane_state(state, linked);
11178 if (IS_ERR(linked_state))
11179 return PTR_ERR(linked_state);
11180
11181 break;
11182 }
11183
11184 if (!linked_state) {
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +053011185 DRM_DEBUG_KMS("Need %d free Y planes for planar YUV\n",
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011186 hweight8(crtc_state->nv12_planes));
11187
11188 return -EINVAL;
11189 }
11190
11191 plane_state->linked_plane = linked;
11192
11193 linked_state->slave = true;
11194 linked_state->linked_plane = plane;
11195 crtc_state->active_planes |= BIT(linked->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020011196 crtc_state->update_planes |= BIT(linked->id);
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011197 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
11198 }
11199
11200 return 0;
11201}
11202
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011203static int intel_crtc_atomic_check(struct drm_crtc *crtc,
11204 struct drm_crtc_state *crtc_state)
11205{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011206 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011207 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020011208 struct intel_crtc_state *pipe_config =
11209 to_intel_crtc_state(crtc_state);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020011210 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011211 bool mode_changed = needs_modeset(crtc_state);
11212
Ville Syrjälä440e84a2019-02-06 20:54:33 +020011213 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv) &&
11214 mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020011215 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020011216
Maarten Lankhorstad421372015-06-15 12:33:42 +020011217 if (mode_changed && crtc_state->enable &&
11218 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011219 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020011220 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
11221 pipe_config);
11222 if (ret)
11223 return ret;
11224 }
11225
Ville Syrjälä051a6d82019-02-05 18:08:41 +020011226 if (mode_changed || crtc_state->color_mgmt_changed) {
Matt Roper302da0c2018-12-10 13:54:15 -080011227 ret = intel_color_check(pipe_config);
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000011228 if (ret)
11229 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010011230
11231 /*
11232 * Changing color management on Intel hardware is
11233 * handled as part of planes update.
11234 */
11235 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000011236 }
11237
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011238 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070011239 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010011240 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011241 if (ret) {
11242 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070011243 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080011244 }
11245 }
11246
Ville Syrjäläf255c622018-11-08 17:10:13 +020011247 if (dev_priv->display.compute_intermediate_wm) {
Matt Ropered4a6a72016-02-23 17:20:13 -080011248 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
11249 return 0;
11250
11251 /*
11252 * Calculate 'intermediate' watermarks that satisfy both the
11253 * old state and the new state. We can program these
11254 * immediately.
11255 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011256 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011257 if (ret) {
11258 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11259 return ret;
11260 }
Matt Roper86c8bbb2015-09-24 15:53:16 -070011261 }
11262
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011263 if (INTEL_GEN(dev_priv) >= 9) {
Hans de Goede2c5c4152018-12-17 15:19:03 +010011264 if (mode_changed || pipe_config->update_pipe)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011265 ret = skl_update_scaler_crtc(pipe_config);
11266
11267 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011268 ret = icl_check_nv12_planes(pipe_config);
11269 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053011270 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11271 pipe_config);
11272 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020011273 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011274 pipe_config);
11275 }
11276
Maarten Lankhorst24f28452017-11-22 19:39:01 +010011277 if (HAS_IPS(dev_priv))
11278 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11279
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011280 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011281}
11282
Jani Nikula65b38e02015-04-13 11:26:56 +030011283static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011284 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010011285};
11286
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011287static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11288{
11289 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011290 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011291
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011292 drm_connector_list_iter_begin(dev, &conn_iter);
11293 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020011294 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011295 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020011296
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011297 if (connector->base.encoder) {
11298 connector->base.state->best_encoder =
11299 connector->base.encoder;
11300 connector->base.state->crtc =
11301 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020011302
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011303 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011304 } else {
11305 connector->base.state->best_encoder = NULL;
11306 connector->base.state->crtc = NULL;
11307 }
11308 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011309 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011310}
11311
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011312static int
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011313compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11314 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011315{
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011316 struct drm_connector *connector = conn_state->connector;
11317 const struct drm_display_info *info = &connector->display_info;
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011318 int bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011319
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011320 switch (conn_state->max_bpc) {
11321 case 6 ... 7:
11322 bpp = 6 * 3;
11323 break;
11324 case 8 ... 9:
11325 bpp = 8 * 3;
11326 break;
11327 case 10 ... 11:
11328 bpp = 10 * 3;
11329 break;
11330 case 12:
11331 bpp = 12 * 3;
11332 break;
11333 default:
11334 return -EINVAL;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011335 }
11336
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011337 if (bpp < pipe_config->pipe_bpp) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011338 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11339 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11340 connector->base.id, connector->name,
11341 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011342 pipe_config->pipe_bpp);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011343
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011344 pipe_config->pipe_bpp = bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011345 }
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011346
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011347 return 0;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011348}
11349
11350static int
11351compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011352 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011353{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011354 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011355 struct drm_atomic_state *state = pipe_config->base.state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011356 struct drm_connector *connector;
11357 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011358 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011359
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011360 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11361 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011362 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011363 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011364 bpp = 12*3;
11365 else
11366 bpp = 8*3;
11367
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011368 pipe_config->pipe_bpp = bpp;
11369
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011370 /* Clamp display bpp to connector max bpp */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011371 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011372 int ret;
11373
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011374 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011375 continue;
11376
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011377 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11378 if (ret)
11379 return ret;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011380 }
11381
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011382 return 0;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011383}
11384
Daniel Vetter644db712013-09-19 14:53:58 +020011385static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11386{
11387 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11388 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010011389 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020011390 mode->crtc_hdisplay, mode->crtc_hsync_start,
11391 mode->crtc_hsync_end, mode->crtc_htotal,
11392 mode->crtc_vdisplay, mode->crtc_vsync_start,
11393 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11394}
11395
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011396static inline void
11397intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011398 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011399{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011400 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11401 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011402 m_n->gmch_m, m_n->gmch_n,
11403 m_n->link_m, m_n->link_n, m_n->tu);
11404}
11405
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011406#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11407
11408static const char * const output_type_str[] = {
11409 OUTPUT_TYPE(UNUSED),
11410 OUTPUT_TYPE(ANALOG),
11411 OUTPUT_TYPE(DVO),
11412 OUTPUT_TYPE(SDVO),
11413 OUTPUT_TYPE(LVDS),
11414 OUTPUT_TYPE(TVOUT),
11415 OUTPUT_TYPE(HDMI),
11416 OUTPUT_TYPE(DP),
11417 OUTPUT_TYPE(EDP),
11418 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011419 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011420 OUTPUT_TYPE(DP_MST),
11421};
11422
11423#undef OUTPUT_TYPE
11424
11425static void snprintf_output_types(char *buf, size_t len,
11426 unsigned int output_types)
11427{
11428 char *str = buf;
11429 int i;
11430
11431 str[0] = '\0';
11432
11433 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11434 int r;
11435
11436 if ((output_types & BIT(i)) == 0)
11437 continue;
11438
11439 r = snprintf(str, len, "%s%s",
11440 str != buf ? "," : "", output_type_str[i]);
11441 if (r >= len)
11442 break;
11443 str += r;
11444 len -= r;
11445
11446 output_types &= ~BIT(i);
11447 }
11448
11449 WARN_ON_ONCE(output_types != 0);
11450}
11451
Shashank Sharmad9facae2018-10-12 11:53:07 +053011452static const char * const output_format_str[] = {
11453 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11454 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011455 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011456 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011457};
11458
11459static const char *output_formats(enum intel_output_format format)
11460{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011461 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011462 format = INTEL_OUTPUT_FORMAT_INVALID;
11463 return output_format_str[format];
11464}
11465
Daniel Vetterc0b03412013-05-28 12:05:54 +020011466static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011467 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011468 const char *context)
11469{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011470 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011471 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011472 struct drm_plane *plane;
11473 struct intel_plane *intel_plane;
11474 struct intel_plane_state *state;
11475 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011476 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011477
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011478 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11479 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011480
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011481 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11482 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11483 buf, pipe_config->output_types);
11484
Shashank Sharmad9facae2018-10-12 11:53:07 +053011485 DRM_DEBUG_KMS("output format: %s\n",
11486 output_formats(pipe_config->output_format));
11487
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011488 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11489 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011490 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011491
11492 if (pipe_config->has_pch_encoder)
11493 intel_dump_m_n_config(pipe_config, "fdi",
11494 pipe_config->fdi_lanes,
11495 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011496
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011497 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011498 intel_dump_m_n_config(pipe_config, "dp m_n",
11499 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011500 if (pipe_config->has_drrs)
11501 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11502 pipe_config->lane_count,
11503 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011504 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011505
Daniel Vetter55072d12014-11-20 16:10:28 +010011506 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011507 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011508
Daniel Vetterc0b03412013-05-28 12:05:54 +020011509 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011510 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011511 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011512 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11513 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011514 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011515 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011516 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11517 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011518
11519 if (INTEL_GEN(dev_priv) >= 9)
11520 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11521 crtc->num_scalers,
11522 pipe_config->scaler_state.scaler_users,
11523 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011524
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080011525 if (HAS_GMCH(dev_priv))
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011526 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11527 pipe_config->gmch_pfit.control,
11528 pipe_config->gmch_pfit.pgm_ratios,
11529 pipe_config->gmch_pfit.lvds_border_bits);
11530 else
11531 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11532 pipe_config->pch_pfit.pos,
11533 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011534 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011535
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011536 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11537 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011538
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011539 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011540
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011541 DRM_DEBUG_KMS("planes on this crtc\n");
11542 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011543 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011544 intel_plane = to_intel_plane(plane);
11545 if (intel_plane->pipe != crtc->pipe)
11546 continue;
11547
11548 state = to_intel_plane_state(plane->state);
11549 fb = state->base.fb;
11550 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011551 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11552 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011553 continue;
11554 }
11555
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011556 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11557 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011558 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011559 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011560 if (INTEL_GEN(dev_priv) >= 9)
11561 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11562 state->scaler_id,
11563 state->base.src.x1 >> 16,
11564 state->base.src.y1 >> 16,
11565 drm_rect_width(&state->base.src) >> 16,
11566 drm_rect_height(&state->base.src) >> 16,
11567 state->base.dst.x1, state->base.dst.y1,
11568 drm_rect_width(&state->base.dst),
11569 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011570 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011571}
11572
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011573static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011574{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011575 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011576 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011577 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011578 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011579 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011580 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011581
11582 /*
11583 * Walk the connector list instead of the encoder
11584 * list to detect the problem on ddi platforms
11585 * where there's just one encoder per digital port.
11586 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011587 drm_connector_list_iter_begin(dev, &conn_iter);
11588 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011589 struct drm_connector_state *connector_state;
11590 struct intel_encoder *encoder;
11591
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011592 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011593 if (!connector_state)
11594 connector_state = connector->state;
11595
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011596 if (!connector_state->best_encoder)
11597 continue;
11598
11599 encoder = to_intel_encoder(connector_state->best_encoder);
11600
11601 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011602
11603 switch (encoder->type) {
11604 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011605 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011606 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011607 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011608 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011609 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011610 case INTEL_OUTPUT_HDMI:
11611 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011612 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011613
11614 /* the same port mustn't appear more than once */
11615 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011616 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011617
11618 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011619 break;
11620 case INTEL_OUTPUT_DP_MST:
11621 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011622 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011623 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011624 default:
11625 break;
11626 }
11627 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011628 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011629
Ville Syrjälä477321e2016-07-28 17:50:40 +030011630 /* can't mix MST and SST/HDMI on the same port */
11631 if (used_ports & used_mst_ports)
11632 return false;
11633
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011634 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011635}
11636
Chris Wilsonf81b8452019-02-05 09:27:59 +000011637static int
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011638clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11639{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011640 struct drm_i915_private *dev_priv =
11641 to_i915(crtc_state->base.crtc->dev);
Chris Wilsonf81b8452019-02-05 09:27:59 +000011642 struct intel_crtc_state *saved_state;
11643
11644 saved_state = kzalloc(sizeof(*saved_state), GFP_KERNEL);
11645 if (!saved_state)
11646 return -ENOMEM;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011647
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011648 /* FIXME: before the switch to atomic started, a new pipe_config was
11649 * kzalloc'd. Code that depends on any field being zero should be
11650 * fixed, so that the crtc_state can be safely duplicated. For now,
11651 * only fields that are know to not cause problems are preserved. */
11652
Chris Wilsonf81b8452019-02-05 09:27:59 +000011653 saved_state->scaler_state = crtc_state->scaler_state;
11654 saved_state->shared_dpll = crtc_state->shared_dpll;
11655 saved_state->dpll_hw_state = crtc_state->dpll_hw_state;
11656 saved_state->pch_pfit.force_thru = crtc_state->pch_pfit.force_thru;
11657 saved_state->ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011658 if (IS_G4X(dev_priv) ||
11659 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilsonf81b8452019-02-05 09:27:59 +000011660 saved_state->wm = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011661
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011662 /* Keep base drm_crtc_state intact, only clear our extended struct */
11663 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
Chris Wilsonf81b8452019-02-05 09:27:59 +000011664 memcpy(&crtc_state->base + 1, &saved_state->base + 1,
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011665 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011666
Chris Wilsonf81b8452019-02-05 09:27:59 +000011667 kfree(saved_state);
11668 return 0;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011669}
11670
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011671static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011672intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011673 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011674{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011675 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011676 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011677 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011678 struct drm_connector_state *connector_state;
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011679 int base_bpp, ret;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011680 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011681 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011682
Chris Wilsonf81b8452019-02-05 09:27:59 +000011683 ret = clear_intel_crtc_state(pipe_config);
11684 if (ret)
11685 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011686
Daniel Vettere143a212013-07-04 12:01:15 +020011687 pipe_config->cpu_transcoder =
11688 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011689
Imre Deak2960bc92013-07-30 13:36:32 +030011690 /*
11691 * Sanitize sync polarity flags based on requested ones. If neither
11692 * positive or negative polarity is requested, treat this as meaning
11693 * negative polarity.
11694 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011695 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011696 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011697 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011698
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011699 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011700 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011701 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011702
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011703 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11704 pipe_config);
11705 if (ret)
11706 return ret;
11707
11708 base_bpp = pipe_config->pipe_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011709
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011710 /*
11711 * Determine the real pipe dimensions. Note that stereo modes can
11712 * increase the actual pipe size due to the frame doubling and
11713 * insertion of additional space for blanks between the frame. This
11714 * is stored in the crtc timings. We use the requested mode to do this
11715 * computation to clearly distinguish it from the adjusted mode, which
11716 * can be changed by the connectors in the below retry loop.
11717 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011718 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011719 &pipe_config->pipe_src_w,
11720 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011721
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011722 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011723 if (connector_state->crtc != crtc)
11724 continue;
11725
11726 encoder = to_intel_encoder(connector_state->best_encoder);
11727
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011728 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11729 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011730 return -EINVAL;
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011731 }
11732
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011733 /*
11734 * Determine output_types before calling the .compute_config()
11735 * hooks so that the hooks can use this information safely.
11736 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011737 if (encoder->compute_output_type)
11738 pipe_config->output_types |=
11739 BIT(encoder->compute_output_type(encoder, pipe_config,
11740 connector_state));
11741 else
11742 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011743 }
11744
Daniel Vettere29c22c2013-02-21 00:00:16 +010011745encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011746 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011747 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011748 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011749
Daniel Vetter135c81b2013-07-21 21:37:09 +020011750 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011751 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11752 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011753
Daniel Vetter7758a112012-07-08 19:40:39 +020011754 /* Pass our mode to the connectors and the CRTC to give them a chance to
11755 * adjust it according to limitations or connector properties, and also
11756 * a chance to reject the mode entirely.
11757 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011758 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011759 if (connector_state->crtc != crtc)
11760 continue;
11761
11762 encoder = to_intel_encoder(connector_state->best_encoder);
Lyude Paul96550552019-01-15 15:08:00 -050011763 ret = encoder->compute_config(encoder, pipe_config,
11764 connector_state);
11765 if (ret < 0) {
11766 if (ret != -EDEADLK)
11767 DRM_DEBUG_KMS("Encoder config failure: %d\n",
11768 ret);
11769 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011770 }
11771 }
11772
Daniel Vetterff9a6752013-06-01 17:16:21 +020011773 /* Set default port clock if not overwritten by the encoder. Needs to be
11774 * done afterwards in case the encoder adjusts the mode. */
11775 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011776 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011777 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011778
Daniel Vettera43f6e02013-06-07 23:10:32 +020011779 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020011780 if (ret == -EDEADLK)
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011781 return ret;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011782 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011783 DRM_DEBUG_KMS("CRTC fixup failed\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011784 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011785 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011786
11787 if (ret == RETRY) {
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011788 if (WARN(!retry, "loop in pipe configuration computation\n"))
11789 return -EINVAL;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011790
11791 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11792 retry = false;
11793 goto encoder_retry;
11794 }
11795
Daniel Vettere8fa4272015-08-12 11:43:34 +020011796 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011797 * only enable it on 6bpc panels and when its not a compliance
11798 * test requesting 6bpc video pattern.
11799 */
11800 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11801 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011802 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011803 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011804
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011805 return 0;
Daniel Vetter7758a112012-07-08 19:40:39 +020011806}
11807
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011808static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011809{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011810 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011811
11812 if (clock1 == clock2)
11813 return true;
11814
11815 if (!clock1 || !clock2)
11816 return false;
11817
11818 diff = abs(clock1 - clock2);
11819
11820 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11821 return true;
11822
11823 return false;
11824}
11825
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011826static bool
11827intel_compare_m_n(unsigned int m, unsigned int n,
11828 unsigned int m2, unsigned int n2,
11829 bool exact)
11830{
11831 if (m == m2 && n == n2)
11832 return true;
11833
11834 if (exact || !m || !n || !m2 || !n2)
11835 return false;
11836
11837 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11838
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011839 if (n > n2) {
11840 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011841 m2 <<= 1;
11842 n2 <<= 1;
11843 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011844 } else if (n < n2) {
11845 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011846 m <<= 1;
11847 n <<= 1;
11848 }
11849 }
11850
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011851 if (n != n2)
11852 return false;
11853
11854 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011855}
11856
11857static bool
11858intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11859 struct intel_link_m_n *m2_n2,
11860 bool adjust)
11861{
11862 if (m_n->tu == m2_n2->tu &&
11863 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11864 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11865 intel_compare_m_n(m_n->link_m, m_n->link_n,
11866 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11867 if (adjust)
11868 *m2_n2 = *m_n;
11869
11870 return true;
11871 }
11872
11873 return false;
11874}
11875
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011876static void __printf(3, 4)
11877pipe_config_err(bool adjust, const char *name, const char *format, ...)
11878{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011879 struct va_format vaf;
11880 va_list args;
11881
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011882 va_start(args, format);
11883 vaf.fmt = format;
11884 vaf.va = &args;
11885
Joe Perches99a95482018-03-13 15:02:15 -070011886 if (adjust)
11887 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11888 else
11889 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011890
11891 va_end(args);
11892}
11893
Hans de Goede3d6535c2019-01-24 14:01:14 +010011894static bool fastboot_enabled(struct drm_i915_private *dev_priv)
11895{
11896 if (i915_modparams.fastboot != -1)
11897 return i915_modparams.fastboot;
11898
11899 /* Enable fastboot by default on Skylake and newer */
Hans de Goede7360c9f2019-01-29 15:22:37 +010011900 if (INTEL_GEN(dev_priv) >= 9)
11901 return true;
11902
11903 /* Enable fastboot by default on VLV and CHV */
11904 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
11905 return true;
11906
11907 /* Disabled by default on all others */
11908 return false;
Hans de Goede3d6535c2019-01-24 14:01:14 +010011909}
11910
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011911static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011912intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011913 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011914 struct intel_crtc_state *pipe_config,
11915 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011916{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011917 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011918 bool fixup_inherited = adjust &&
11919 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11920 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011921
Hans de Goede3d6535c2019-01-24 14:01:14 +010011922 if (fixup_inherited && !fastboot_enabled(dev_priv)) {
Maarten Lankhorstd19f9582019-01-08 17:08:40 +010011923 DRM_DEBUG_KMS("initial modeset and fastboot not set\n");
11924 ret = false;
11925 }
11926
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011927#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011928 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011929 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011930 "(expected 0x%08x, found 0x%08x)\n", \
11931 current_config->name, \
11932 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011933 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011934 } \
11935} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011936
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011937#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011938 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011939 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011940 "(expected %i, found %i)\n", \
11941 current_config->name, \
11942 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011943 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011944 } \
11945} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011946
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011947#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011948 if (current_config->name != pipe_config->name) { \
11949 pipe_config_err(adjust, __stringify(name), \
11950 "(expected %s, found %s)\n", \
11951 yesno(current_config->name), \
11952 yesno(pipe_config->name)); \
11953 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011954 } \
11955} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011956
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011957/*
11958 * Checks state where we only read out the enabling, but not the entire
11959 * state itself (like full infoframes or ELD for audio). These states
11960 * require a full modeset on bootup to fix up.
11961 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011962#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011963 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11964 PIPE_CONF_CHECK_BOOL(name); \
11965 } else { \
11966 pipe_config_err(adjust, __stringify(name), \
11967 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11968 yesno(current_config->name), \
11969 yesno(pipe_config->name)); \
11970 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011971 } \
11972} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011973
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011974#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011975 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011976 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011977 "(expected %p, found %p)\n", \
11978 current_config->name, \
11979 pipe_config->name); \
11980 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011981 } \
11982} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011983
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011984#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011985 if (!intel_compare_link_m_n(&current_config->name, \
11986 &pipe_config->name,\
11987 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011988 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011989 "(expected tu %i gmch %i/%i link %i/%i, " \
11990 "found tu %i, gmch %i/%i link %i/%i)\n", \
11991 current_config->name.tu, \
11992 current_config->name.gmch_m, \
11993 current_config->name.gmch_n, \
11994 current_config->name.link_m, \
11995 current_config->name.link_n, \
11996 pipe_config->name.tu, \
11997 pipe_config->name.gmch_m, \
11998 pipe_config->name.gmch_n, \
11999 pipe_config->name.link_m, \
12000 pipe_config->name.link_n); \
12001 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012002 } \
12003} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012004
Daniel Vetter55c561a2016-03-30 11:34:36 +020012005/* This is required for BDW+ where there is only one set of registers for
12006 * switching between high and low RR.
12007 * This macro can be used whenever a comparison has to be made between one
12008 * hw state and multiple sw state variables.
12009 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012010#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012011 if (!intel_compare_link_m_n(&current_config->name, \
12012 &pipe_config->name, adjust) && \
12013 !intel_compare_link_m_n(&current_config->alt_name, \
12014 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000012015 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012016 "(expected tu %i gmch %i/%i link %i/%i, " \
12017 "or tu %i gmch %i/%i link %i/%i, " \
12018 "found tu %i, gmch %i/%i link %i/%i)\n", \
12019 current_config->name.tu, \
12020 current_config->name.gmch_m, \
12021 current_config->name.gmch_n, \
12022 current_config->name.link_m, \
12023 current_config->name.link_n, \
12024 current_config->alt_name.tu, \
12025 current_config->alt_name.gmch_m, \
12026 current_config->alt_name.gmch_n, \
12027 current_config->alt_name.link_m, \
12028 current_config->alt_name.link_n, \
12029 pipe_config->name.tu, \
12030 pipe_config->name.gmch_m, \
12031 pipe_config->name.gmch_n, \
12032 pipe_config->name.link_m, \
12033 pipe_config->name.link_n); \
12034 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012035 } \
12036} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010012037
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012038#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012039 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000012040 pipe_config_err(adjust, __stringify(name), \
12041 "(%x) (expected %i, found %i)\n", \
12042 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012043 current_config->name & (mask), \
12044 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012045 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012046 } \
12047} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012048
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012049#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030012050 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000012051 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030012052 "(expected %i, found %i)\n", \
12053 current_config->name, \
12054 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012055 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020012056 } \
12057} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030012058
Daniel Vetterbb760062013-06-06 14:55:52 +020012059#define PIPE_CONF_QUIRK(quirk) \
12060 ((current_config->quirks | pipe_config->quirks) & (quirk))
12061
Daniel Vettereccb1402013-05-22 00:50:22 +020012062 PIPE_CONF_CHECK_I(cpu_transcoder);
12063
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012064 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020012065 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012066 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020012067
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030012068 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030012069 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070012070
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012071 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012072 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070012073
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012074 if (current_config->has_drrs)
12075 PIPE_CONF_CHECK_M_N(dp_m2_n2);
12076 } else
12077 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030012078
Ville Syrjälä253c84c2016-06-22 21:57:01 +030012079 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020012080
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012081 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
12082 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
12083 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
12084 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
12085 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
12086 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012087
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012088 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
12089 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
12090 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
12091 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
12092 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
12093 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012094
Daniel Vetterc93f54c2013-06-27 19:47:19 +020012095 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053012096 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012097 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010012098 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010012099 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012100 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053012101
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012102 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
12103 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012104 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020012105
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012106 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020012107
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012108 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012109 DRM_MODE_FLAG_INTERLACE);
12110
Daniel Vetterbb760062013-06-06 14:55:52 +020012111 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012112 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012113 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012114 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012115 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012116 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012117 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012118 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020012119 DRM_MODE_FLAG_NVSYNC);
12120 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070012121
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030012122 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020012123 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012124 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020012125 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030012126 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020012127
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020012128 if (!adjust) {
12129 PIPE_CONF_CHECK_I(pipe_src_w);
12130 PIPE_CONF_CHECK_I(pipe_src_h);
12131
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012132 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020012133 if (current_config->pch_pfit.enabled) {
12134 PIPE_CONF_CHECK_X(pch_pfit.pos);
12135 PIPE_CONF_CHECK_X(pch_pfit.size);
12136 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020012137
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020012138 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012139 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020012140 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070012141
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012142 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030012143
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012144 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020012145 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020012146 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020012147 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
12148 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030012149 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010012150 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000012151 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
12152 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
12153 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030012154 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
12155 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
12156 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
12157 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
12158 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
12159 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
12160 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
12161 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
12162 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
12163 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
12164 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
12165 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070012166 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
12167 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
12168 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
12169 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
12170 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
12171 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
12172 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
12173 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
12174 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
12175 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020012176
Ville Syrjälä47eacba2016-04-12 22:14:35 +030012177 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
12178 PIPE_CONF_CHECK_X(dsi_pll.div);
12179
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010012180 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030012181 PIPE_CONF_CHECK_I(pipe_bpp);
12182
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020012183 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080012184 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030012185
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012186 PIPE_CONF_CHECK_I(min_voltage_level);
12187
Daniel Vetter66e985c2013-06-05 13:34:20 +020012188#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020012189#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010012190#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010012191#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012192#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020012193#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030012194#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020012195#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020012196
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012197 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010012198}
12199
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020012200static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
12201 const struct intel_crtc_state *pipe_config)
12202{
12203 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020012204 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020012205 &pipe_config->fdi_m_n);
12206 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
12207
12208 /*
12209 * FDI already provided one idea for the dotclock.
12210 * Yell if the encoder disagrees.
12211 */
12212 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
12213 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
12214 fdi_dotclock, dotclock);
12215 }
12216}
12217
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012218static void verify_wm_state(struct drm_crtc *crtc,
12219 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000012220{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012221 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000012222 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012223 struct skl_pipe_wm hw_wm, *sw_wm;
12224 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
12225 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012226 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
12227 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012228 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12229 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012230 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000012231
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012232 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000012233 return;
12234
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012235 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020012236 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012237
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012238 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
12239
Damien Lespiau08db6652014-11-04 17:06:52 +000012240 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
12241 sw_ddb = &dev_priv->wm.skl_hw.ddb;
12242
Mahesh Kumar74bd8002018-04-26 19:55:15 +053012243 if (INTEL_GEN(dev_priv) >= 11)
12244 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
12245 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
12246 sw_ddb->enabled_slices,
12247 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012248 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070012249 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012250 hw_plane_wm = &hw_wm.planes[plane];
12251 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000012252
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012253 /* Watermarks */
12254 for (level = 0; level <= max_level; level++) {
12255 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12256 &sw_plane_wm->wm[level]))
12257 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000012258
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012259 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",
12260 pipe_name(pipe), plane + 1, level,
12261 sw_plane_wm->wm[level].plane_en,
12262 sw_plane_wm->wm[level].plane_res_b,
12263 sw_plane_wm->wm[level].plane_res_l,
12264 hw_plane_wm->wm[level].plane_en,
12265 hw_plane_wm->wm[level].plane_res_b,
12266 hw_plane_wm->wm[level].plane_res_l);
12267 }
12268
12269 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12270 &sw_plane_wm->trans_wm)) {
12271 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",
12272 pipe_name(pipe), plane + 1,
12273 sw_plane_wm->trans_wm.plane_en,
12274 sw_plane_wm->trans_wm.plane_res_b,
12275 sw_plane_wm->trans_wm.plane_res_l,
12276 hw_plane_wm->trans_wm.plane_en,
12277 hw_plane_wm->trans_wm.plane_res_b,
12278 hw_plane_wm->trans_wm.plane_res_l);
12279 }
12280
12281 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012282 hw_ddb_entry = &hw_ddb_y[plane];
12283 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012284
12285 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012286 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 -040012287 pipe_name(pipe), plane + 1,
12288 sw_ddb_entry->start, sw_ddb_entry->end,
12289 hw_ddb_entry->start, hw_ddb_entry->end);
12290 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012291 }
12292
Lyude27082492016-08-24 07:48:10 +020012293 /*
12294 * cursor
12295 * If the cursor plane isn't active, we may not have updated it's ddb
12296 * allocation. In that case since the ddb allocation will be updated
12297 * once the plane becomes visible, we can skip this check
12298 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030012299 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012300 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12301 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012302
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012303 /* Watermarks */
12304 for (level = 0; level <= max_level; level++) {
12305 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12306 &sw_plane_wm->wm[level]))
12307 continue;
12308
12309 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",
12310 pipe_name(pipe), level,
12311 sw_plane_wm->wm[level].plane_en,
12312 sw_plane_wm->wm[level].plane_res_b,
12313 sw_plane_wm->wm[level].plane_res_l,
12314 hw_plane_wm->wm[level].plane_en,
12315 hw_plane_wm->wm[level].plane_res_b,
12316 hw_plane_wm->wm[level].plane_res_l);
12317 }
12318
12319 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12320 &sw_plane_wm->trans_wm)) {
12321 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12322 pipe_name(pipe),
12323 sw_plane_wm->trans_wm.plane_en,
12324 sw_plane_wm->trans_wm.plane_res_b,
12325 sw_plane_wm->trans_wm.plane_res_l,
12326 hw_plane_wm->trans_wm.plane_en,
12327 hw_plane_wm->trans_wm.plane_res_b,
12328 hw_plane_wm->trans_wm.plane_res_l);
12329 }
12330
12331 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012332 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12333 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012334
12335 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012336 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020012337 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012338 sw_ddb_entry->start, sw_ddb_entry->end,
12339 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020012340 }
Damien Lespiau08db6652014-11-04 17:06:52 +000012341 }
12342}
12343
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012344static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012345verify_connector_state(struct drm_device *dev,
12346 struct drm_atomic_state *state,
12347 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012348{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012349 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012350 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012351 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012352
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012353 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012354 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012355 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012356
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012357 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012358 continue;
12359
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012360 if (crtc)
12361 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12362
12363 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012364
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012365 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012366 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012367 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012368}
12369
12370static void
Daniel Vetter86b04262017-03-01 10:52:26 +010012371verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012372{
12373 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010012374 struct drm_connector *connector;
12375 struct drm_connector_state *old_conn_state, *new_conn_state;
12376 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012377
Damien Lespiaub2784e12014-08-05 11:29:37 +010012378 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010012379 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012380 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012381
12382 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12383 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030012384 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012385
Daniel Vetter86b04262017-03-01 10:52:26 +010012386 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12387 new_conn_state, i) {
12388 if (old_conn_state->best_encoder == &encoder->base)
12389 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012390
Daniel Vetter86b04262017-03-01 10:52:26 +010012391 if (new_conn_state->best_encoder != &encoder->base)
12392 continue;
12393 found = enabled = true;
12394
12395 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012396 encoder->base.crtc,
12397 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012398 }
Daniel Vetter86b04262017-03-01 10:52:26 +010012399
12400 if (!found)
12401 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100012402
Rob Clarke2c719b2014-12-15 13:56:32 -050012403 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012404 "encoder's enabled state mismatch "
12405 "(expected %i, found %i)\n",
12406 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012407
12408 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012409 bool active;
12410
12411 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012412 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012413 "encoder detached but still enabled on pipe %c.\n",
12414 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012415 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012416 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012417}
12418
12419static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012420verify_crtc_state(struct drm_crtc *crtc,
12421 struct drm_crtc_state *old_crtc_state,
12422 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012423{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012424 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010012425 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012426 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012427 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12428 struct intel_crtc_state *pipe_config, *sw_config;
12429 struct drm_atomic_state *old_state;
12430 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012431
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012432 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012433 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012434 pipe_config = to_intel_crtc_state(old_crtc_state);
12435 memset(pipe_config, 0, sizeof(*pipe_config));
12436 pipe_config->base.crtc = crtc;
12437 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012438
Ville Syrjälä78108b72016-05-27 20:59:19 +030012439 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012440
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012441 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012442
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012443 /* we keep both pipes enabled on 830 */
12444 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012445 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012446
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012447 I915_STATE_WARN(new_crtc_state->active != active,
12448 "crtc active state doesn't match with hw state "
12449 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012450
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012451 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12452 "transitional active state does not match atomic hw state "
12453 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012454
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012455 for_each_encoder_on_crtc(dev, crtc, encoder) {
12456 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012457
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012458 active = encoder->get_hw_state(encoder, &pipe);
12459 I915_STATE_WARN(active != new_crtc_state->active,
12460 "[ENCODER:%i] active %i with crtc active %i\n",
12461 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012462
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012463 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12464 "Encoder connected to wrong pipe %c\n",
12465 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012466
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012467 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012468 encoder->get_config(encoder, pipe_config);
12469 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012470
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012471 intel_crtc_compute_pixel_rate(pipe_config);
12472
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012473 if (!new_crtc_state->active)
12474 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012475
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012476 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012477
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012478 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012479 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012480 pipe_config, false)) {
12481 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12482 intel_dump_pipe_config(intel_crtc, pipe_config,
12483 "[hw state]");
12484 intel_dump_pipe_config(intel_crtc, sw_config,
12485 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012486 }
12487}
12488
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012489static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012490intel_verify_planes(struct intel_atomic_state *state)
12491{
12492 struct intel_plane *plane;
12493 const struct intel_plane_state *plane_state;
12494 int i;
12495
12496 for_each_new_intel_plane_in_state(state, plane,
12497 plane_state, i)
12498 assert_plane(plane, plane_state->base.visible);
12499}
12500
12501static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012502verify_single_dpll_state(struct drm_i915_private *dev_priv,
12503 struct intel_shared_dpll *pll,
12504 struct drm_crtc *crtc,
12505 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012506{
12507 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012508 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012509 bool active;
12510
12511 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12512
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012513 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012514
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012515 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012516
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012517 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012518 I915_STATE_WARN(!pll->on && pll->active_mask,
12519 "pll in active use but not on in sw tracking\n");
12520 I915_STATE_WARN(pll->on && !pll->active_mask,
12521 "pll is on but not used by any active crtc\n");
12522 I915_STATE_WARN(pll->on != active,
12523 "pll on state mismatch (expected %i, found %i)\n",
12524 pll->on, active);
12525 }
12526
12527 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012528 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012529 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012530 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012531
12532 return;
12533 }
12534
Ville Syrjälä40560e22018-06-26 22:47:11 +030012535 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012536
12537 if (new_state->active)
12538 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12539 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12540 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12541 else
12542 I915_STATE_WARN(pll->active_mask & crtc_mask,
12543 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12544 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12545
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012546 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012547 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012548 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012549
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012550 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012551 &dpll_hw_state,
12552 sizeof(dpll_hw_state)),
12553 "pll hw state mismatch\n");
12554}
12555
12556static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012557verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12558 struct drm_crtc_state *old_crtc_state,
12559 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012560{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012561 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012562 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12563 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12564
12565 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012566 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012567
12568 if (old_state->shared_dpll &&
12569 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012570 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012571 struct intel_shared_dpll *pll = old_state->shared_dpll;
12572
12573 I915_STATE_WARN(pll->active_mask & crtc_mask,
12574 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12575 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012576 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012577 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12578 pipe_name(drm_crtc_index(crtc)));
12579 }
12580}
12581
12582static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012583intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012584 struct drm_atomic_state *state,
12585 struct drm_crtc_state *old_state,
12586 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012587{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012588 if (!needs_modeset(new_state) &&
12589 !to_intel_crtc_state(new_state)->update_pipe)
12590 return;
12591
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012592 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012593 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012594 verify_crtc_state(crtc, old_state, new_state);
12595 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012596}
12597
12598static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012599verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012600{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012601 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012602 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012603
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012604 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012605 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012606}
Daniel Vetter53589012013-06-05 13:34:16 +020012607
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012608static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012609intel_modeset_verify_disabled(struct drm_device *dev,
12610 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012611{
Daniel Vetter86b04262017-03-01 10:52:26 +010012612 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012613 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012614 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012615}
12616
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012617static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012618{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012619 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012620 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012621
12622 /*
12623 * The scanline counter increments at the leading edge of hsync.
12624 *
12625 * On most platforms it starts counting from vtotal-1 on the
12626 * first active line. That means the scanline counter value is
12627 * always one less than what we would expect. Ie. just after
12628 * start of vblank, which also occurs at start of hsync (on the
12629 * last active line), the scanline counter will read vblank_start-1.
12630 *
12631 * On gen2 the scanline counter starts counting from 1 instead
12632 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12633 * to keep the value positive), instead of adding one.
12634 *
12635 * On HSW+ the behaviour of the scanline counter depends on the output
12636 * type. For DP ports it behaves like most other platforms, but on HDMI
12637 * there's an extra 1 line difference. So we need to add two instead of
12638 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012639 *
12640 * On VLV/CHV DSI the scanline counter would appear to increment
12641 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12642 * that means we can't tell whether we're in vblank or not while
12643 * we're on that particular line. We must still set scanline_offset
12644 * to 1 so that the vblank timestamps come out correct when we query
12645 * the scanline counter from within the vblank interrupt handler.
12646 * However if queried just before the start of vblank we'll get an
12647 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012648 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080012649 if (IS_GEN(dev_priv, 2)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012650 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012651 int vtotal;
12652
Ville Syrjälä124abe02015-09-08 13:40:45 +030012653 vtotal = adjusted_mode->crtc_vtotal;
12654 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012655 vtotal /= 2;
12656
12657 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012658 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012659 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012660 crtc->scanline_offset = 2;
12661 } else
12662 crtc->scanline_offset = 1;
12663}
12664
Maarten Lankhorstad421372015-06-15 12:33:42 +020012665static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012666{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012667 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012668 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012669 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012670 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012671 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012672
12673 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012674 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012675
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012676 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012677 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012678 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012679 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012680
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012681 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012682 continue;
12683
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012684 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012685
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012686 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012687 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012688
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012689 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012690 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012691}
12692
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012693/*
12694 * This implements the workaround described in the "notes" section of the mode
12695 * set sequence documentation. When going from no pipes or single pipe to
12696 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12697 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12698 */
12699static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12700{
12701 struct drm_crtc_state *crtc_state;
12702 struct intel_crtc *intel_crtc;
12703 struct drm_crtc *crtc;
12704 struct intel_crtc_state *first_crtc_state = NULL;
12705 struct intel_crtc_state *other_crtc_state = NULL;
12706 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12707 int i;
12708
12709 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012710 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012711 intel_crtc = to_intel_crtc(crtc);
12712
12713 if (!crtc_state->active || !needs_modeset(crtc_state))
12714 continue;
12715
12716 if (first_crtc_state) {
12717 other_crtc_state = to_intel_crtc_state(crtc_state);
12718 break;
12719 } else {
12720 first_crtc_state = to_intel_crtc_state(crtc_state);
12721 first_pipe = intel_crtc->pipe;
12722 }
12723 }
12724
12725 /* No workaround needed? */
12726 if (!first_crtc_state)
12727 return 0;
12728
12729 /* w/a possibly needed, check how many crtc's are already enabled. */
12730 for_each_intel_crtc(state->dev, intel_crtc) {
12731 struct intel_crtc_state *pipe_config;
12732
12733 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12734 if (IS_ERR(pipe_config))
12735 return PTR_ERR(pipe_config);
12736
12737 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12738
12739 if (!pipe_config->base.active ||
12740 needs_modeset(&pipe_config->base))
12741 continue;
12742
12743 /* 2 or more enabled crtcs means no need for w/a */
12744 if (enabled_pipe != INVALID_PIPE)
12745 return 0;
12746
12747 enabled_pipe = intel_crtc->pipe;
12748 }
12749
12750 if (enabled_pipe != INVALID_PIPE)
12751 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12752 else if (other_crtc_state)
12753 other_crtc_state->hsw_workaround_pipe = first_pipe;
12754
12755 return 0;
12756}
12757
Ville Syrjälä8d965612016-11-14 18:35:10 +020012758static int intel_lock_all_pipes(struct drm_atomic_state *state)
12759{
12760 struct drm_crtc *crtc;
12761
12762 /* Add all pipes to the state */
12763 for_each_crtc(state->dev, crtc) {
12764 struct drm_crtc_state *crtc_state;
12765
12766 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12767 if (IS_ERR(crtc_state))
12768 return PTR_ERR(crtc_state);
12769 }
12770
12771 return 0;
12772}
12773
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012774static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12775{
12776 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012777
Ville Syrjälä8d965612016-11-14 18:35:10 +020012778 /*
12779 * Add all pipes to the state, and force
12780 * a modeset on all the active ones.
12781 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012782 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012783 struct drm_crtc_state *crtc_state;
12784 int ret;
12785
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012786 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12787 if (IS_ERR(crtc_state))
12788 return PTR_ERR(crtc_state);
12789
12790 if (!crtc_state->active || needs_modeset(crtc_state))
12791 continue;
12792
12793 crtc_state->mode_changed = true;
12794
12795 ret = drm_atomic_add_affected_connectors(state, crtc);
12796 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012797 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012798
12799 ret = drm_atomic_add_affected_planes(state, crtc);
12800 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012801 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012802 }
12803
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012804 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012805}
12806
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012807static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012808{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012809 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012810 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012811 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012812 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012813 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012814
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012815 if (!check_digital_port_conflicts(state)) {
12816 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12817 return -EINVAL;
12818 }
12819
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012820 intel_state->modeset = true;
12821 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012822 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12823 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012824
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012825 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12826 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012827 intel_state->active_crtcs |= 1 << i;
12828 else
12829 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012830
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012831 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012832 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012833 }
12834
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012835 /*
12836 * See if the config requires any additional preparation, e.g.
12837 * to adjust global state with pipes off. We need to do this
12838 * here so we can get the modeset_pipe updated config for the new
12839 * mode set on this crtc. For other crtcs we need to use the
12840 * adjusted_mode bits in the crtc directly.
12841 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012842 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012843 ret = dev_priv->display.modeset_calc_cdclk(state);
12844 if (ret < 0)
12845 return ret;
12846
Ville Syrjälä8d965612016-11-14 18:35:10 +020012847 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012848 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012849 * holding all the crtc locks, even if we don't end up
12850 * touching the hardware
12851 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012852 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12853 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012854 ret = intel_lock_all_pipes(state);
12855 if (ret < 0)
12856 return ret;
12857 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012858
Ville Syrjälä8d965612016-11-14 18:35:10 +020012859 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012860 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12861 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012862 ret = intel_modeset_all_pipes(state);
12863 if (ret < 0)
12864 return ret;
12865 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012866
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012867 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12868 intel_state->cdclk.logical.cdclk,
12869 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012870 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12871 intel_state->cdclk.logical.voltage_level,
12872 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012873 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012874 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012875 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012876
Maarten Lankhorstad421372015-06-15 12:33:42 +020012877 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012878
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012879 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012880 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012881
Maarten Lankhorstad421372015-06-15 12:33:42 +020012882 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012883}
12884
Matt Roperaa363132015-09-24 15:53:18 -070012885/*
12886 * Handle calculation of various watermark data at the end of the atomic check
12887 * phase. The code here should be run after the per-crtc and per-plane 'check'
12888 * handlers to ensure that all derived state has been updated.
12889 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012890static int calc_watermark_data(struct intel_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012891{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012892 struct drm_device *dev = state->base.dev;
Matt Roper98d39492016-05-12 07:06:03 -070012893 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012894
12895 /* Is there platform-specific watermark information to calculate? */
12896 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012897 return dev_priv->display.compute_global_watermarks(state);
12898
12899 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012900}
12901
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012902/**
12903 * intel_atomic_check - validate state object
12904 * @dev: drm device
12905 * @state: state to validate
12906 */
12907static int intel_atomic_check(struct drm_device *dev,
12908 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012909{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012910 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012911 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012912 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012913 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012914 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012915 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012916
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012917 /* Catch I915_MODE_FLAG_INHERITED */
12918 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12919 crtc_state, i) {
12920 if (crtc_state->mode.private_flags !=
12921 old_crtc_state->mode.private_flags)
12922 crtc_state->mode_changed = true;
12923 }
12924
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012925 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012926 if (ret)
12927 return ret;
12928
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012929 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012930 struct intel_crtc_state *pipe_config =
12931 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012932
Daniel Vetter26495482015-07-15 14:15:52 +020012933 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012934 continue;
12935
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012936 if (!crtc_state->enable) {
12937 any_ms = true;
12938 continue;
12939 }
12940
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012941 ret = intel_modeset_pipe_config(crtc, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020012942 if (ret == -EDEADLK)
12943 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012944 if (ret) {
12945 intel_dump_pipe_config(to_intel_crtc(crtc),
12946 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012947 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012948 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012949
Maarten Lankhorstd19f9582019-01-08 17:08:40 +010012950 if (intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012951 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012952 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012953 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012954 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012955 }
12956
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012957 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012958 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012959
Daniel Vetter26495482015-07-15 14:15:52 +020012960 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12961 needs_modeset(crtc_state) ?
12962 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012963 }
12964
Lyude Pauleceae142019-01-10 19:53:41 -050012965 ret = drm_dp_mst_atomic_check(state);
12966 if (ret)
12967 return ret;
12968
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012969 if (any_ms) {
12970 ret = intel_modeset_checks(state);
12971
12972 if (ret)
12973 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012974 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012975 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012976 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012977
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012978 ret = icl_add_linked_planes(intel_state);
12979 if (ret)
12980 return ret;
12981
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012982 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012983 if (ret)
12984 return ret;
12985
Ville Syrjälädd576022017-11-17 21:19:14 +020012986 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012987 return calc_watermark_data(intel_state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012988}
12989
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012990static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012991 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012992{
Chris Wilsonfd700752017-07-26 17:00:36 +010012993 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012994}
12995
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012996u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12997{
12998 struct drm_device *dev = crtc->base.dev;
Ville Syrjälä32db0b62018-11-27 22:05:50 +020012999 struct drm_vblank_crtc *vblank = &dev->vblank[drm_crtc_index(&crtc->base)];
Maarten Lankhorsta2991412016-05-17 15:07:48 +020013000
Ville Syrjälä32db0b62018-11-27 22:05:50 +020013001 if (!vblank->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080013002 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020013003
13004 return dev->driver->get_vblank_counter(dev, crtc->pipe);
13005}
13006
Lyude896e5bb2016-08-24 07:48:09 +020013007static void intel_update_crtc(struct drm_crtc *crtc,
13008 struct drm_atomic_state *state,
13009 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013010 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020013011{
13012 struct drm_device *dev = crtc->dev;
13013 struct drm_i915_private *dev_priv = to_i915(dev);
13014 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013015 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
13016 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013017 struct intel_plane_state *new_plane_state =
13018 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
13019 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020013020
13021 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020013022 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020013023 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010013024
13025 /* vblanks work again, re-enable pipe CRC. */
13026 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020013027 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013028 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
13029 pipe_config);
Hans de Goede608ed4a2018-12-20 14:21:18 +010013030
13031 if (pipe_config->update_pipe)
13032 intel_encoders_update_pipe(crtc, pipe_config, state);
Lyude896e5bb2016-08-24 07:48:09 +020013033 }
13034
Maarten Lankhorst50c42fc2018-12-20 16:17:19 +010013035 if (pipe_config->update_pipe && !pipe_config->enable_fbc)
13036 intel_fbc_disable(intel_crtc);
13037 else if (new_plane_state)
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013038 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020013039
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020013040 intel_begin_crtc_commit(crtc, old_crtc_state);
13041
Ville Syrjälä5f2e5112018-11-14 23:07:27 +020013042 if (INTEL_GEN(dev_priv) >= 9)
13043 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
13044 else
13045 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020013046
13047 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020013048}
13049
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013050static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020013051{
13052 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013053 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020013054 int i;
13055
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013056 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
13057 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020013058 continue;
13059
13060 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013061 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020013062 }
13063}
13064
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013065static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020013066{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020013067 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020013068 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
13069 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040013070 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013071 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040013072 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020013073 unsigned int updated = 0;
13074 bool progress;
13075 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013076 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013077 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
13078 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013079 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013080
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013081 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013082 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013083 if (new_crtc_state->active)
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013084 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020013085
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013086 /* If 2nd DBuf slice required, enable it here */
13087 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
13088 icl_dbuf_slices_update(dev_priv, required_slices);
13089
Lyude27082492016-08-24 07:48:10 +020013090 /*
13091 * Whenever the number of active pipes changes, we need to make sure we
13092 * update the pipes in the right order so that their ddb allocations
13093 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
13094 * cause pipe underruns and other bad stuff.
13095 */
13096 do {
Lyude27082492016-08-24 07:48:10 +020013097 progress = false;
13098
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013099 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020013100 bool vbl_wait = false;
13101 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040013102
13103 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030013104 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040013105 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020013106
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013107 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020013108 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010013109
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013110 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
Mika Kahola2b685042017-10-10 13:17:03 +030013111 entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013112 INTEL_INFO(dev_priv)->num_pipes, i))
Lyude27082492016-08-24 07:48:10 +020013113 continue;
13114
13115 updated |= cmask;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020013116 entries[i] = cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020013117
13118 /*
13119 * If this is an already active pipe, it's DDB changed,
13120 * and this isn't the last pipe that needs updating
13121 * then we need to wait for a vblank to pass for the
13122 * new ddb allocation to take effect.
13123 */
Lyudece0ba282016-09-15 10:46:35 -040013124 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010013125 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013126 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020013127 intel_state->wm_results.dirty_pipes != updated)
13128 vbl_wait = true;
13129
13130 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013131 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020013132
13133 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020013134 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020013135
13136 progress = true;
13137 }
13138 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053013139
13140 /* If 2nd DBuf slice is no more required disable it */
13141 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
13142 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020013143}
13144
Chris Wilsonba318c62017-02-02 20:47:41 +000013145static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
13146{
13147 struct intel_atomic_state *state, *next;
13148 struct llist_node *freed;
13149
13150 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
13151 llist_for_each_entry_safe(state, next, freed, freed)
13152 drm_atomic_state_put(&state->base);
13153}
13154
13155static void intel_atomic_helper_free_state_worker(struct work_struct *work)
13156{
13157 struct drm_i915_private *dev_priv =
13158 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
13159
13160 intel_atomic_helper_free_state(dev_priv);
13161}
13162
Daniel Vetter9db529a2017-08-08 10:08:28 +020013163static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
13164{
13165 struct wait_queue_entry wait_fence, wait_reset;
13166 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
13167
13168 init_wait_entry(&wait_fence, 0);
13169 init_wait_entry(&wait_reset, 0);
13170 for (;;) {
13171 prepare_to_wait(&intel_state->commit_ready.wait,
13172 &wait_fence, TASK_UNINTERRUPTIBLE);
13173 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
13174 &wait_reset, TASK_UNINTERRUPTIBLE);
13175
13176
13177 if (i915_sw_fence_done(&intel_state->commit_ready)
13178 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
13179 break;
13180
13181 schedule();
13182 }
13183 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
13184 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
13185}
13186
Chris Wilson8d52e442018-06-23 11:39:51 +010013187static void intel_atomic_cleanup_work(struct work_struct *work)
13188{
13189 struct drm_atomic_state *state =
13190 container_of(work, struct drm_atomic_state, commit_work);
13191 struct drm_i915_private *i915 = to_i915(state->dev);
13192
13193 drm_atomic_helper_cleanup_planes(&i915->drm, state);
13194 drm_atomic_helper_commit_cleanup_done(state);
13195 drm_atomic_state_put(state);
13196
13197 intel_atomic_helper_free_state(i915);
13198}
13199
Daniel Vetter94f05022016-06-14 18:01:00 +020013200static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020013201{
Daniel Vetter94f05022016-06-14 18:01:00 +020013202 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013203 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013204 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013205 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013206 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020013207 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013208 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020013209 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013210 intel_wakeref_t wakeref = 0;
Chris Wilsone95433c2016-10-28 13:58:27 +010013211 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020013212
Daniel Vetter9db529a2017-08-08 10:08:28 +020013213 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013214
Daniel Vetterea0000f2016-06-13 16:13:46 +020013215 drm_atomic_helper_wait_for_dependencies(state);
13216
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013217 if (intel_state->modeset)
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013218 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013219
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013220 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013221 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
13222 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13223 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013224
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013225 if (needs_modeset(new_crtc_state) ||
13226 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013227
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013228 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013229 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013230 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013231 }
13232
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013233 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020013234 continue;
13235
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013236 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010013237
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020013238 if (old_crtc_state->active) {
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020013239 intel_crtc_disable_planes(intel_state, intel_crtc);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010013240
13241 /*
13242 * We need to disable pipe CRC before disabling the pipe,
13243 * or we race against vblank off.
13244 */
13245 intel_crtc_disable_pipe_crc(intel_crtc);
13246
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013247 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020013248 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020013249 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020013250 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020013251
13252 /*
13253 * Underruns don't always raise
13254 * interrupts, so check manually.
13255 */
13256 intel_check_cpu_fifo_underruns(dev_priv);
13257 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010013258
Ville Syrjäläa748fae2018-10-25 16:05:36 +030013259 /* FIXME unify this for all platforms */
13260 if (!new_crtc_state->active &&
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080013261 !HAS_GMCH(dev_priv) &&
Ville Syrjäläa748fae2018-10-25 16:05:36 +030013262 dev_priv->display.initial_watermarks)
13263 dev_priv->display.initial_watermarks(intel_state,
13264 new_intel_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013265 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010013266 }
Daniel Vetter7758a112012-07-08 19:40:39 +020013267
Daniel Vetter7a1530d72017-12-07 15:32:02 +010013268 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
13269 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
13270 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020013271
Maarten Lankhorst565602d2015-12-10 12:33:57 +010013272 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013273 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010013274
Ville Syrjäläb0587e42017-01-26 21:52:01 +020013275 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010013276
Lyude656d1b82016-08-17 15:55:54 -040013277 /*
13278 * SKL workaround: bspec recommends we disable the SAGV when we
13279 * have more then one pipe enabled
13280 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030013281 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013282 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013283
Maarten Lankhorst677100c2016-11-08 13:55:41 +010013284 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013285 }
Daniel Vetter47fab732012-10-26 10:58:18 +020013286
Lyude896e5bb2016-08-24 07:48:09 +020013287 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013288 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13289 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013290
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013291 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013292 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013293 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013294 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013295 spin_unlock_irq(&dev->event_lock);
13296
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013297 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013298 }
Matt Ropered4a6a72016-02-23 17:20:13 -080013299 }
13300
Lyude896e5bb2016-08-24 07:48:09 +020013301 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013302 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020013303
Daniel Vetter94f05022016-06-14 18:01:00 +020013304 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13305 * already, but still need the state for the delayed optimization. To
13306 * fix this:
13307 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13308 * - schedule that vblank worker _before_ calling hw_done
13309 * - at the start of commit_tail, cancel it _synchrously
13310 * - switch over to the vblank wait helper in the core after that since
13311 * we don't need out special handling any more.
13312 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013313 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013314
Ville Syrjälä051a6d82019-02-05 18:08:41 +020013315 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13316 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
13317
13318 if (new_crtc_state->active &&
13319 !needs_modeset(new_crtc_state) &&
13320 (new_intel_crtc_state->base.color_mgmt_changed ||
13321 new_intel_crtc_state->update_pipe))
13322 intel_color_load_luts(new_intel_crtc_state);
13323 }
13324
Daniel Vetter5a21b662016-05-24 17:13:53 +020013325 /*
13326 * Now that the vblank has passed, we can go ahead and program the
13327 * optimal watermarks on platforms that need two-step watermark
13328 * programming.
13329 *
13330 * TODO: Move this (and other cleanup) to an async worker eventually.
13331 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013332 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013333 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013334
13335 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013336 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdcf2018-09-20 12:27:04 +020013337 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013338 }
13339
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013340 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013341 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13342
13343 if (put_domains[i])
13344 modeset_put_power_domains(dev_priv, put_domains[i]);
13345
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013346 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013347 }
13348
Ville Syrjäläcff109f2017-11-17 21:19:17 +020013349 if (intel_state->modeset)
13350 intel_verify_planes(intel_state);
13351
Paulo Zanoni56feca92016-09-22 18:00:28 -030013352 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013353 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013354
Daniel Vetter94f05022016-06-14 18:01:00 +020013355 drm_atomic_helper_commit_hw_done(state);
13356
Chris Wilsond5553c02017-05-04 12:55:08 +010013357 if (intel_state->modeset) {
13358 /* As one of the primary mmio accessors, KMS has a high
13359 * likelihood of triggering bugs in unclaimed access. After we
13360 * finish modesetting, see if an error has been flagged, and if
13361 * so enable debugging for the next modeset - and hope we catch
13362 * the culprit.
13363 */
13364 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Chris Wilson0e6e0be2019-01-14 14:21:24 +000013365 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET, wakeref);
Chris Wilsond5553c02017-05-04 12:55:08 +010013366 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013367
Chris Wilson8d52e442018-06-23 11:39:51 +010013368 /*
13369 * Defer the cleanup of the old state to a separate worker to not
13370 * impede the current task (userspace for blocking modesets) that
13371 * are executed inline. For out-of-line asynchronous modesets/flips,
13372 * deferring to a new worker seems overkill, but we would place a
13373 * schedule point (cond_resched()) here anyway to keep latencies
13374 * down.
13375 */
13376 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010013377 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020013378}
13379
13380static void intel_atomic_commit_work(struct work_struct *work)
13381{
Chris Wilsonc004a902016-10-28 13:58:45 +010013382 struct drm_atomic_state *state =
13383 container_of(work, struct drm_atomic_state, commit_work);
13384
Daniel Vetter94f05022016-06-14 18:01:00 +020013385 intel_atomic_commit_tail(state);
13386}
13387
Chris Wilsonc004a902016-10-28 13:58:45 +010013388static int __i915_sw_fence_call
13389intel_atomic_commit_ready(struct i915_sw_fence *fence,
13390 enum i915_sw_fence_notify notify)
13391{
13392 struct intel_atomic_state *state =
13393 container_of(fence, struct intel_atomic_state, commit_ready);
13394
13395 switch (notify) {
13396 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020013397 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010013398 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010013399 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000013400 {
13401 struct intel_atomic_helper *helper =
13402 &to_i915(state->base.dev)->atomic_helper;
13403
13404 if (llist_add(&state->freed, &helper->free_list))
13405 schedule_work(&helper->free_work);
13406 break;
13407 }
Chris Wilsonc004a902016-10-28 13:58:45 +010013408 }
13409
13410 return NOTIFY_DONE;
13411}
13412
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013413static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13414{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013415 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013416 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013417 int i;
13418
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013419 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013420 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013421 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013422 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013423}
13424
Daniel Vetter94f05022016-06-14 18:01:00 +020013425/**
13426 * intel_atomic_commit - commit validated state object
13427 * @dev: DRM device
13428 * @state: the top-level driver state object
13429 * @nonblock: nonblocking commit
13430 *
13431 * This function commits a top-level state object that has been validated
13432 * with drm_atomic_helper_check().
13433 *
Daniel Vetter94f05022016-06-14 18:01:00 +020013434 * RETURNS
13435 * Zero for success or -errno.
13436 */
13437static int intel_atomic_commit(struct drm_device *dev,
13438 struct drm_atomic_state *state,
13439 bool nonblock)
13440{
13441 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013442 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013443 int ret = 0;
13444
Chris Wilsonc004a902016-10-28 13:58:45 +010013445 drm_atomic_state_get(state);
13446 i915_sw_fence_init(&intel_state->commit_ready,
13447 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013448
Ville Syrjälä440df932017-03-29 17:21:23 +030013449 /*
13450 * The intel_legacy_cursor_update() fast path takes care
13451 * of avoiding the vblank waits for simple cursor
13452 * movement and flips. For cursor on/off and size changes,
13453 * we want to perform the vblank waits so that watermark
13454 * updates happen during the correct frames. Gen9+ have
13455 * double buffered watermarks and so shouldn't need this.
13456 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013457 * Unset state->legacy_cursor_update before the call to
13458 * drm_atomic_helper_setup_commit() because otherwise
13459 * drm_atomic_helper_wait_for_flip_done() is a noop and
13460 * we get FIFO underruns because we didn't wait
13461 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013462 *
13463 * FIXME doing watermarks and fb cleanup from a vblank worker
13464 * (assuming we had any) would solve these problems.
13465 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013466 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13467 struct intel_crtc_state *new_crtc_state;
13468 struct intel_crtc *crtc;
13469 int i;
13470
13471 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13472 if (new_crtc_state->wm.need_postvbl_update ||
13473 new_crtc_state->update_wm_post)
13474 state->legacy_cursor_update = false;
13475 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013476
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013477 ret = intel_atomic_prepare_commit(dev, state);
13478 if (ret) {
13479 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13480 i915_sw_fence_commit(&intel_state->commit_ready);
13481 return ret;
13482 }
13483
13484 ret = drm_atomic_helper_setup_commit(state, nonblock);
13485 if (!ret)
13486 ret = drm_atomic_helper_swap_state(state, true);
13487
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013488 if (ret) {
13489 i915_sw_fence_commit(&intel_state->commit_ready);
13490
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013491 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013492 return ret;
13493 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013494 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013495 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013496 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013497
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013498 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013499 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13500 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013501 memcpy(dev_priv->min_voltage_level,
13502 intel_state->min_voltage_level,
13503 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013504 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013505 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13506 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013507 }
13508
Chris Wilson08536952016-10-14 13:18:18 +010013509 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013510 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013511
13512 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013513 if (nonblock && intel_state->modeset) {
13514 queue_work(dev_priv->modeset_wq, &state->commit_work);
13515 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013516 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013517 } else {
13518 if (intel_state->modeset)
13519 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013520 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013521 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013522
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013523 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013524}
13525
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013526static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013527 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013528 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013529 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013530 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013531 .atomic_duplicate_state = intel_crtc_duplicate_state,
13532 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013533 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013534 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013535 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013536};
13537
Chris Wilson74d290f2017-08-17 13:37:06 +010013538struct wait_rps_boost {
13539 struct wait_queue_entry wait;
13540
13541 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013542 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013543};
13544
13545static int do_rps_boost(struct wait_queue_entry *_wait,
13546 unsigned mode, int sync, void *key)
13547{
13548 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013549 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013550
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013551 /*
13552 * If we missed the vblank, but the request is already running it
13553 * is reasonable to assume that it will complete before the next
13554 * vblank without our intervention, so leave RPS alone.
13555 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013556 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013557 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013558 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013559
13560 drm_crtc_vblank_put(wait->crtc);
13561
13562 list_del(&wait->wait.entry);
13563 kfree(wait);
13564 return 1;
13565}
13566
13567static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13568 struct dma_fence *fence)
13569{
13570 struct wait_rps_boost *wait;
13571
13572 if (!dma_fence_is_i915(fence))
13573 return;
13574
13575 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13576 return;
13577
13578 if (drm_crtc_vblank_get(crtc))
13579 return;
13580
13581 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13582 if (!wait) {
13583 drm_crtc_vblank_put(crtc);
13584 return;
13585 }
13586
13587 wait->request = to_request(dma_fence_get(fence));
13588 wait->crtc = crtc;
13589
13590 wait->wait.func = do_rps_boost;
13591 wait->wait.flags = 0;
13592
13593 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13594}
13595
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013596static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13597{
13598 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13599 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13600 struct drm_framebuffer *fb = plane_state->base.fb;
13601 struct i915_vma *vma;
13602
13603 if (plane->id == PLANE_CURSOR &&
José Roberto de Souzad53db442018-11-30 15:20:48 -080013604 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013605 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13606 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013607 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013608
Chris Wilson4a477652018-08-17 09:24:05 +010013609 err = i915_gem_object_attach_phys(obj, align);
13610 if (err)
13611 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013612 }
13613
13614 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013615 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013616 intel_plane_uses_fence(plane_state),
13617 &plane_state->flags);
13618 if (IS_ERR(vma))
13619 return PTR_ERR(vma);
13620
13621 plane_state->vma = vma;
13622
13623 return 0;
13624}
13625
13626static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13627{
13628 struct i915_vma *vma;
13629
13630 vma = fetch_and_zero(&old_plane_state->vma);
13631 if (vma)
13632 intel_unpin_fb_vma(vma, old_plane_state->flags);
13633}
13634
Chris Wilsonb7268c52018-04-18 19:40:52 +010013635static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13636{
13637 struct i915_sched_attr attr = {
13638 .priority = I915_PRIORITY_DISPLAY,
13639 };
13640
13641 i915_gem_object_wait_priority(obj, 0, &attr);
13642}
13643
Matt Roper6beb8c232014-12-01 15:40:14 -080013644/**
13645 * intel_prepare_plane_fb - Prepare fb for usage on plane
13646 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013647 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013648 *
13649 * Prepares a framebuffer for usage on a display plane. Generally this
13650 * involves pinning the underlying object and updating the frontbuffer tracking
13651 * bits. Some older platforms need special physical address handling for
13652 * cursor planes.
13653 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013654 * Must be called with struct_mutex held.
13655 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013656 * Returns 0 on success, negative error code on failure.
13657 */
13658int
13659intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013660 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013661{
Chris Wilsonc004a902016-10-28 13:58:45 +010013662 struct intel_atomic_state *intel_state =
13663 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013664 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013665 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013666 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013667 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013668 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013669
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013670 if (old_obj) {
13671 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013672 drm_atomic_get_new_crtc_state(new_state->state,
13673 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013674
13675 /* Big Hammer, we also need to ensure that any pending
13676 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13677 * current scanout is retired before unpinning the old
13678 * framebuffer. Note that we rely on userspace rendering
13679 * into the buffer attached to the pipe they are waiting
13680 * on. If not, userspace generates a GPU hang with IPEHR
13681 * point to the MI_WAIT_FOR_EVENT.
13682 *
13683 * This should only fail upon a hung GPU, in which case we
13684 * can safely continue.
13685 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013686 if (needs_modeset(crtc_state)) {
13687 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13688 old_obj->resv, NULL,
13689 false, 0,
13690 GFP_KERNEL);
13691 if (ret < 0)
13692 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013693 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013694 }
13695
Chris Wilsonc004a902016-10-28 13:58:45 +010013696 if (new_state->fence) { /* explicit fencing */
13697 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13698 new_state->fence,
13699 I915_FENCE_TIMEOUT,
13700 GFP_KERNEL);
13701 if (ret < 0)
13702 return ret;
13703 }
13704
Chris Wilsonc37efb92016-06-17 08:28:47 +010013705 if (!obj)
13706 return 0;
13707
Chris Wilson4d3088c2017-07-26 17:00:38 +010013708 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013709 if (ret)
13710 return ret;
13711
Chris Wilson4d3088c2017-07-26 17:00:38 +010013712 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13713 if (ret) {
13714 i915_gem_object_unpin_pages(obj);
13715 return ret;
13716 }
13717
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013718 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013719
Chris Wilsonfd700752017-07-26 17:00:36 +010013720 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013721 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013722 if (ret)
13723 return ret;
13724
Chris Wilsone2f34962018-10-01 15:47:54 +010013725 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013726 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13727
Chris Wilsonc004a902016-10-28 13:58:45 +010013728 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013729 struct dma_fence *fence;
13730
Chris Wilsonc004a902016-10-28 13:58:45 +010013731 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13732 obj->resv, NULL,
13733 false, I915_FENCE_TIMEOUT,
13734 GFP_KERNEL);
13735 if (ret < 0)
13736 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013737
13738 fence = reservation_object_get_excl_rcu(obj->resv);
13739 if (fence) {
13740 add_rps_boost_after_vblank(new_state->crtc, fence);
13741 dma_fence_put(fence);
13742 }
13743 } else {
13744 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013745 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013746
Chris Wilson60548c52018-07-31 14:26:29 +010013747 /*
13748 * We declare pageflips to be interactive and so merit a small bias
13749 * towards upclocking to deliver the frame on time. By only changing
13750 * the RPS thresholds to sample more regularly and aim for higher
13751 * clocks we can hopefully deliver low power workloads (like kodi)
13752 * that are not quite steady state without resorting to forcing
13753 * maximum clocks following a vblank miss (see do_rps_boost()).
13754 */
13755 if (!intel_state->rps_interactive) {
13756 intel_rps_mark_interactive(dev_priv, true);
13757 intel_state->rps_interactive = true;
13758 }
13759
Chris Wilsond07f0e52016-10-28 13:58:44 +010013760 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013761}
13762
Matt Roper38f3ce32014-12-02 07:45:25 -080013763/**
13764 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13765 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013766 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013767 *
13768 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013769 *
13770 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013771 */
13772void
13773intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013774 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013775{
Chris Wilson60548c52018-07-31 14:26:29 +010013776 struct intel_atomic_state *intel_state =
13777 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013778 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013779
Chris Wilson60548c52018-07-31 14:26:29 +010013780 if (intel_state->rps_interactive) {
13781 intel_rps_mark_interactive(dev_priv, false);
13782 intel_state->rps_interactive = false;
13783 }
13784
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013785 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013786 mutex_lock(&dev_priv->drm.struct_mutex);
13787 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13788 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013789}
13790
Chandra Konduru6156a452015-04-27 13:48:39 -070013791int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013792skl_max_scale(const struct intel_crtc_state *crtc_state,
13793 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013794{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013795 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013797 int max_scale, mult;
13798 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013799
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013800 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013801 return DRM_PLANE_HELPER_NO_SCALING;
13802
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013803 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13804 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13805
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013806 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013807 max_dotclk *= 2;
13808
13809 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013810 return DRM_PLANE_HELPER_NO_SCALING;
13811
13812 /*
13813 * skl max scale is lower of:
13814 * close to 3 but not 3, -1 is for that purpose
13815 * or
13816 * cdclk/crtc_clock
13817 */
Juha-Pekka Heikkiladf7d4152019-03-04 17:26:31 +053013818 mult = is_planar_yuv_format(pixel_format) ? 2 : 3;
Chandra Konduru77224cd2018-04-09 09:11:13 +053013819 tmpclk1 = (1 << 16) * mult - 1;
13820 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13821 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013822
13823 return max_scale;
13824}
13825
Daniel Vetter5a21b662016-05-24 17:13:53 +020013826static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13827 struct drm_crtc_state *old_crtc_state)
13828{
13829 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013830 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013831 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013832 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013833 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013834 struct intel_atomic_state *old_intel_state =
13835 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013836 struct intel_crtc_state *intel_cstate =
13837 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13838 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013839
13840 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013841 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013842
13843 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013844 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013845
Ville Syrjälä4d8ed542019-02-05 18:08:40 +020013846 if (intel_cstate->base.color_mgmt_changed ||
13847 intel_cstate->update_pipe)
13848 intel_color_commit(intel_cstate);
13849
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013850 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013851 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013852 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013853 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013854
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013855out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013856 if (dev_priv->display.atomic_update_watermarks)
13857 dev_priv->display.atomic_update_watermarks(old_intel_state,
13858 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013859}
13860
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013861void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13862 struct intel_crtc_state *crtc_state)
13863{
13864 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13865
Lucas De Marchicf819ef2018-12-12 10:10:43 -080013866 if (!IS_GEN(dev_priv, 2))
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013867 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13868
13869 if (crtc_state->has_pch_encoder) {
13870 enum pipe pch_transcoder =
13871 intel_crtc_pch_transcoder(crtc);
13872
13873 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13874 }
13875}
13876
Daniel Vetter5a21b662016-05-24 17:13:53 +020013877static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13878 struct drm_crtc_state *old_crtc_state)
13879{
13880 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013881 struct intel_atomic_state *old_intel_state =
13882 to_intel_atomic_state(old_crtc_state->state);
13883 struct intel_crtc_state *new_crtc_state =
13884 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013885
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013886 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013887
13888 if (new_crtc_state->update_pipe &&
13889 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013890 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13891 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013892}
13893
Matt Ropercf4c7c12014-12-04 10:27:42 -080013894/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013895 * intel_plane_destroy - destroy a plane
13896 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013897 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013898 * Common destruction function for all types of planes (primary, cursor,
13899 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013900 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013901void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013902{
Matt Roper465c1202014-05-29 08:06:54 -070013903 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013904 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013905}
13906
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013907static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13908 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013909{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013910 switch (modifier) {
13911 case DRM_FORMAT_MOD_LINEAR:
13912 case I915_FORMAT_MOD_X_TILED:
13913 break;
13914 default:
13915 return false;
13916 }
13917
Ben Widawsky714244e2017-08-01 09:58:16 -070013918 switch (format) {
13919 case DRM_FORMAT_C8:
13920 case DRM_FORMAT_RGB565:
13921 case DRM_FORMAT_XRGB1555:
13922 case DRM_FORMAT_XRGB8888:
13923 return modifier == DRM_FORMAT_MOD_LINEAR ||
13924 modifier == I915_FORMAT_MOD_X_TILED;
13925 default:
13926 return false;
13927 }
13928}
13929
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013930static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13931 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013932{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013933 switch (modifier) {
13934 case DRM_FORMAT_MOD_LINEAR:
13935 case I915_FORMAT_MOD_X_TILED:
13936 break;
13937 default:
13938 return false;
13939 }
13940
Ben Widawsky714244e2017-08-01 09:58:16 -070013941 switch (format) {
13942 case DRM_FORMAT_C8:
13943 case DRM_FORMAT_RGB565:
13944 case DRM_FORMAT_XRGB8888:
13945 case DRM_FORMAT_XBGR8888:
13946 case DRM_FORMAT_XRGB2101010:
13947 case DRM_FORMAT_XBGR2101010:
13948 return modifier == DRM_FORMAT_MOD_LINEAR ||
13949 modifier == I915_FORMAT_MOD_X_TILED;
13950 default:
13951 return false;
13952 }
13953}
13954
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013955static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13956 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013957{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013958 return modifier == DRM_FORMAT_MOD_LINEAR &&
13959 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013960}
13961
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013962static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013963 .update_plane = drm_atomic_helper_update_plane,
13964 .disable_plane = drm_atomic_helper_disable_plane,
13965 .destroy = intel_plane_destroy,
13966 .atomic_get_property = intel_plane_atomic_get_property,
13967 .atomic_set_property = intel_plane_atomic_set_property,
13968 .atomic_duplicate_state = intel_plane_duplicate_state,
13969 .atomic_destroy_state = intel_plane_destroy_state,
13970 .format_mod_supported = i965_plane_format_mod_supported,
13971};
13972
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013973static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013974 .update_plane = drm_atomic_helper_update_plane,
13975 .disable_plane = drm_atomic_helper_disable_plane,
13976 .destroy = intel_plane_destroy,
13977 .atomic_get_property = intel_plane_atomic_get_property,
13978 .atomic_set_property = intel_plane_atomic_set_property,
13979 .atomic_duplicate_state = intel_plane_duplicate_state,
13980 .atomic_destroy_state = intel_plane_destroy_state,
13981 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013982};
13983
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013984static int
13985intel_legacy_cursor_update(struct drm_plane *plane,
13986 struct drm_crtc *crtc,
13987 struct drm_framebuffer *fb,
13988 int crtc_x, int crtc_y,
13989 unsigned int crtc_w, unsigned int crtc_h,
Jani Nikulaba3f4d02019-01-18 14:01:23 +020013990 u32 src_x, u32 src_y,
13991 u32 src_w, u32 src_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013992 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013993{
13994 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13995 int ret;
13996 struct drm_plane_state *old_plane_state, *new_plane_state;
13997 struct intel_plane *intel_plane = to_intel_plane(plane);
13998 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013999 struct intel_crtc_state *crtc_state =
14000 to_intel_crtc_state(crtc->state);
14001 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014002
14003 /*
14004 * When crtc is inactive or there is a modeset pending,
14005 * wait for it to complete in the slowpath
14006 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014007 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
14008 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014009 goto slow;
14010
14011 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020014012 /*
14013 * Don't do an async update if there is an outstanding commit modifying
14014 * the plane. This prevents our async update's changes from getting
14015 * overridden by a previous synchronous update's state.
14016 */
14017 if (old_plane_state->commit &&
14018 !try_wait_for_completion(&old_plane_state->commit->hw_done))
14019 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014020
14021 /*
14022 * If any parameters change that may affect watermarks,
14023 * take the slowpath. Only changing fb or position should be
14024 * in the fastpath.
14025 */
14026 if (old_plane_state->crtc != crtc ||
14027 old_plane_state->src_w != src_w ||
14028 old_plane_state->src_h != src_h ||
14029 old_plane_state->crtc_w != crtc_w ||
14030 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020014031 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014032 goto slow;
14033
14034 new_plane_state = intel_plane_duplicate_state(plane);
14035 if (!new_plane_state)
14036 return -ENOMEM;
14037
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014038 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
14039 if (!new_crtc_state) {
14040 ret = -ENOMEM;
14041 goto out_free;
14042 }
14043
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014044 drm_atomic_set_fb_for_plane(new_plane_state, fb);
14045
14046 new_plane_state->src_x = src_x;
14047 new_plane_state->src_y = src_y;
14048 new_plane_state->src_w = src_w;
14049 new_plane_state->src_h = src_h;
14050 new_plane_state->crtc_x = crtc_x;
14051 new_plane_state->crtc_y = crtc_y;
14052 new_plane_state->crtc_w = crtc_w;
14053 new_plane_state->crtc_h = crtc_h;
14054
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014055 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
14056 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014057 to_intel_plane_state(new_plane_state));
14058 if (ret)
14059 goto out_free;
14060
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014061 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
14062 if (ret)
14063 goto out_free;
14064
Ville Syrjäläef1a1912018-02-21 18:02:34 +020014065 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
14066 if (ret)
14067 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014068
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080014069 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014070
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080014071 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014072 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
14073 intel_plane->frontbuffer_bit);
14074
14075 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020014076 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014077
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014078 /*
14079 * We cannot swap crtc_state as it may be in use by an atomic commit or
14080 * page flip that's running simultaneously. If we swap crtc_state and
14081 * destroy the old state, we will cause a use-after-free there.
14082 *
14083 * Only update active_planes, which is needed for our internal
14084 * bookkeeping. Either value will do the right thing when updating
14085 * planes atomically. If the cursor was part of the atomic update then
14086 * we would have taken the slowpath.
14087 */
14088 crtc_state->active_planes = new_crtc_state->active_planes;
14089
Ville Syrjälä72259532017-03-02 19:15:05 +020014090 if (plane->state->visible) {
14091 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014092 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020014093 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020014094 } else {
14095 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020014096 intel_plane->disable_plane(intel_plane, crtc_state);
Ville Syrjälä72259532017-03-02 19:15:05 +020014097 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014098
Ville Syrjäläef1a1912018-02-21 18:02:34 +020014099 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014100
14101out_unlock:
14102 mutex_unlock(&dev_priv->drm.struct_mutex);
14103out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020014104 if (new_crtc_state)
14105 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020014106 if (ret)
14107 intel_plane_destroy_state(plane, new_plane_state);
14108 else
14109 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014110 return ret;
14111
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014112slow:
14113 return drm_atomic_helper_update_plane(plane, crtc, fb,
14114 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010014115 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014116}
14117
14118static const struct drm_plane_funcs intel_cursor_plane_funcs = {
14119 .update_plane = intel_legacy_cursor_update,
14120 .disable_plane = drm_atomic_helper_disable_plane,
14121 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014122 .atomic_get_property = intel_plane_atomic_get_property,
14123 .atomic_set_property = intel_plane_atomic_set_property,
14124 .atomic_duplicate_state = intel_plane_duplicate_state,
14125 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014126 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010014127};
14128
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014129static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
14130 enum i9xx_plane_id i9xx_plane)
14131{
14132 if (!HAS_FBC(dev_priv))
14133 return false;
14134
14135 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
14136 return i9xx_plane == PLANE_A; /* tied to pipe A */
14137 else if (IS_IVYBRIDGE(dev_priv))
14138 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
14139 i9xx_plane == PLANE_C;
14140 else if (INTEL_GEN(dev_priv) >= 4)
14141 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
14142 else
14143 return i9xx_plane == PLANE_A;
14144}
14145
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014146static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020014147intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070014148{
Ville Syrjälä881440a2018-10-05 15:58:17 +030014149 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014150 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014151 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030014152 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030014153 const u64 *modifiers;
14154 const u32 *formats;
14155 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014156 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070014157
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014158 if (INTEL_GEN(dev_priv) >= 9)
14159 return skl_universal_plane_create(dev_priv, pipe,
14160 PLANE_PRIMARY);
14161
Ville Syrjälä881440a2018-10-05 15:58:17 +030014162 plane = intel_plane_alloc();
14163 if (IS_ERR(plane))
14164 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080014165
Ville Syrjälä881440a2018-10-05 15:58:17 +030014166 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020014167 /*
14168 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
14169 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
14170 */
14171 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030014172 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020014173 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030014174 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
14175 plane->id = PLANE_PRIMARY;
14176 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014177
Ville Syrjälä881440a2018-10-05 15:58:17 +030014178 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
14179 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014180 struct intel_fbc *fbc = &dev_priv->fbc;
14181
Ville Syrjälä881440a2018-10-05 15:58:17 +030014182 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020014183 }
14184
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014185 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030014186 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010014187 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070014188 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010014189
Ville Syrjälä881440a2018-10-05 15:58:17 +030014190 plane->max_stride = i9xx_plane_max_stride;
14191 plane->update_plane = i9xx_update_plane;
14192 plane->disable_plane = i9xx_disable_plane;
14193 plane->get_hw_state = i9xx_plane_get_hw_state;
14194 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014195
14196 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014197 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030014198 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010014199 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070014200 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010014201
Ville Syrjälä881440a2018-10-05 15:58:17 +030014202 plane->max_stride = i9xx_plane_max_stride;
14203 plane->update_plane = i9xx_update_plane;
14204 plane->disable_plane = i9xx_disable_plane;
14205 plane->get_hw_state = i9xx_plane_get_hw_state;
14206 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030014207
14208 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070014209 }
14210
Ville Syrjälädeb19682018-10-05 15:58:08 +030014211 possible_crtcs = BIT(pipe);
14212
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014213 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030014214 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014215 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030014216 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014217 DRM_PLANE_TYPE_PRIMARY,
14218 "primary %c", pipe_name(pipe));
14219 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030014220 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014221 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030014222 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014223 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020014224 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030014225 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014226 if (ret)
14227 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053014228
Ville Syrjäläb7c80602018-10-05 15:58:15 +030014229 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020014230 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040014231 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
14232 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100014233 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014234 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040014235 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014236 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040014237 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014238 }
14239
Dave Airlie5481e272016-10-25 16:36:13 +100014240 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030014241 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014242 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014243 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053014244
Ville Syrjälä881440a2018-10-05 15:58:17 +030014245 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080014246
Ville Syrjälä881440a2018-10-05 15:58:17 +030014247 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014248
14249fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030014250 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014251
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014252 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070014253}
14254
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014255static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014256intel_cursor_plane_create(struct drm_i915_private *dev_priv,
14257 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070014258{
Ville Syrjälädeb19682018-10-05 15:58:08 +030014259 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030014260 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014261 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070014262
Ville Syrjäläc539b572018-10-05 15:58:14 +030014263 cursor = intel_plane_alloc();
14264 if (IS_ERR(cursor))
14265 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080014266
Matt Roper3d7d6512014-06-10 08:28:13 -070014267 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020014268 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020014269 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020014270 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014271
14272 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014273 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014274 cursor->update_plane = i845_update_cursor;
14275 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014276 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014277 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014278 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030014279 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014280 cursor->update_plane = i9xx_update_cursor;
14281 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020014282 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030014283 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030014284 }
Matt Roper3d7d6512014-06-10 08:28:13 -070014285
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030014286 cursor->cursor.base = ~0;
14287 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030014288
14289 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14290 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014291
Ville Syrjälädeb19682018-10-05 15:58:08 +030014292 possible_crtcs = BIT(pipe);
14293
Ville Syrjälä580503c2016-10-31 22:37:00 +020014294 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014295 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014296 intel_cursor_formats,
14297 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070014298 cursor_format_modifiers,
14299 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014300 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014301 if (ret)
14302 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014303
Dave Airlie5481e272016-10-25 16:36:13 +100014304 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014305 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014306 DRM_MODE_ROTATE_0,
14307 DRM_MODE_ROTATE_0 |
14308 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014309
Matt Roperea2c67b2014-12-23 10:41:52 -080014310 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14311
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014312 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014313
14314fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030014315 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014316
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014317 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070014318}
14319
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014320static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14321 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014322{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014323 struct intel_crtc_scaler_state *scaler_state =
14324 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014325 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014326 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014327
Jani Nikula02584042018-12-31 16:56:41 +020014328 crtc->num_scalers = RUNTIME_INFO(dev_priv)->num_scalers[crtc->pipe];
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014329 if (!crtc->num_scalers)
14330 return;
14331
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014332 for (i = 0; i < crtc->num_scalers; i++) {
14333 struct intel_scaler *scaler = &scaler_state->scalers[i];
14334
14335 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020014336 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014337 }
14338
14339 scaler_state->scaler_id = -1;
14340}
14341
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014342static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080014343{
14344 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014345 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014346 struct intel_plane *primary = NULL;
14347 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014348 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014349
Daniel Vetter955382f2013-09-19 14:05:45 +020014350 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014351 if (!intel_crtc)
14352 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080014353
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014354 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014355 if (!crtc_state) {
14356 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014357 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014358 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030014359 intel_crtc->config = crtc_state;
14360 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080014361 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014362
Ville Syrjälä580503c2016-10-31 22:37:00 +020014363 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014364 if (IS_ERR(primary)) {
14365 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070014366 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014367 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014368 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014369
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014370 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014371 struct intel_plane *plane;
14372
Ville Syrjälä580503c2016-10-31 22:37:00 +020014373 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014374 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014375 ret = PTR_ERR(plane);
14376 goto fail;
14377 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014378 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014379 }
14380
Ville Syrjälä580503c2016-10-31 22:37:00 +020014381 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014382 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014383 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070014384 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014385 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014386 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014387
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014388 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014389 &primary->base, &cursor->base,
14390 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030014391 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070014392 if (ret)
14393 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080014394
Jesse Barnes80824002009-09-10 15:28:06 -070014395 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070014396
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014397 /* initialize shared scalers */
14398 intel_crtc_init_scalers(intel_crtc, crtc_state);
14399
Ville Syrjälä1947fd12018-03-05 19:41:22 +020014400 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14401 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14402 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14403
14404 if (INTEL_GEN(dev_priv) < 9) {
14405 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14406
14407 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14408 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14409 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14410 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080014411
Jesse Barnes79e53942008-11-07 14:24:08 -080014412 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020014413
Matt Roper302da0c2018-12-10 13:54:15 -080014414 intel_color_init(intel_crtc);
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000014415
Daniel Vetter87b6b102014-05-15 15:33:46 +020014416 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014417
14418 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014419
14420fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014421 /*
14422 * drm_mode_config_cleanup() will free up any
14423 * crtcs/planes already initialized.
14424 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014425 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070014426 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014427
14428 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014429}
14430
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020014431int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14432 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070014433{
Carl Worth08d7b3d2009-04-29 14:43:54 -070014434 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040014435 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020014436 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014437
Keith Packard418da172017-03-14 23:25:07 -070014438 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014439 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014440 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014441
Rob Clark7707e652014-07-17 23:30:04 -040014442 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014443 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014444
Daniel Vetterc05422d2009-08-11 16:05:30 +020014445 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014446}
14447
Daniel Vetter66a92782012-07-12 20:08:18 +020014448static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014449{
Daniel Vetter66a92782012-07-12 20:08:18 +020014450 struct drm_device *dev = encoder->base.dev;
14451 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014452 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014453 int entry = 0;
14454
Damien Lespiaub2784e12014-08-05 11:29:37 +010014455 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014456 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014457 index_mask |= (1 << entry);
14458
Jesse Barnes79e53942008-11-07 14:24:08 -080014459 entry++;
14460 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014461
Jesse Barnes79e53942008-11-07 14:24:08 -080014462 return index_mask;
14463}
14464
Jani Nikulaa5916fd2019-01-22 10:23:05 +020014465static bool ilk_has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014466{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014467 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014468 return false;
14469
14470 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14471 return false;
14472
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014473 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014474 return false;
14475
14476 return true;
14477}
14478
Jani Nikula63cb4e62019-01-22 10:23:01 +020014479static bool intel_ddi_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014480{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014481 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014482 return false;
14483
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014484 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014485 return false;
14486
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014487 if (HAS_PCH_LPT_H(dev_priv) &&
14488 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014489 return false;
14490
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014491 /* DDI E can't be used if DDI A requires 4 lanes */
Jani Nikula63cb4e62019-01-22 10:23:01 +020014492 if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014493 return false;
14494
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014495 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014496 return false;
14497
14498 return true;
14499}
14500
Imre Deak8090ba82016-08-10 14:07:33 +030014501void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14502{
14503 int pps_num;
14504 int pps_idx;
14505
14506 if (HAS_DDI(dev_priv))
14507 return;
14508 /*
14509 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14510 * everywhere where registers can be write protected.
14511 */
14512 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14513 pps_num = 2;
14514 else
14515 pps_num = 1;
14516
14517 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14518 u32 val = I915_READ(PP_CONTROL(pps_idx));
14519
14520 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14521 I915_WRITE(PP_CONTROL(pps_idx), val);
14522 }
14523}
14524
Imre Deak44cb7342016-08-10 14:07:29 +030014525static void intel_pps_init(struct drm_i915_private *dev_priv)
14526{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014527 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014528 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14529 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14530 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14531 else
14532 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014533
14534 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014535}
14536
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014537static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014538{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014539 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014540 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014541
Imre Deak44cb7342016-08-10 14:07:29 +030014542 intel_pps_init(dev_priv);
14543
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080014544 if (!HAS_DISPLAY(dev_priv))
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014545 return;
14546
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014547 if (IS_ICELAKE(dev_priv)) {
14548 intel_ddi_init(dev_priv, PORT_A);
14549 intel_ddi_init(dev_priv, PORT_B);
14550 intel_ddi_init(dev_priv, PORT_C);
14551 intel_ddi_init(dev_priv, PORT_D);
14552 intel_ddi_init(dev_priv, PORT_E);
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014553 /*
14554 * On some ICL SKUs port F is not present. No strap bits for
14555 * this, so rely on VBT.
Imre Deak2b34e5622018-12-20 17:52:11 +020014556 * Work around broken VBTs on SKUs known to have no port F.
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014557 */
Imre Deak2b34e5622018-12-20 17:52:11 +020014558 if (IS_ICL_WITH_PORT_F(dev_priv) &&
14559 intel_bios_is_port_present(dev_priv, PORT_F))
Imre Deak3f2e9ed2018-12-20 15:26:03 +020014560 intel_ddi_init(dev_priv, PORT_F);
14561
Madhav Chauhanbf4d57f2018-10-30 13:56:23 +020014562 icl_dsi_init(dev_priv);
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014563 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014564 /*
14565 * FIXME: Broxton doesn't support port detection via the
14566 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14567 * detect the ports.
14568 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014569 intel_ddi_init(dev_priv, PORT_A);
14570 intel_ddi_init(dev_priv, PORT_B);
14571 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014572
Jani Nikulae5186342018-07-05 16:25:08 +030014573 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014574 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014575 int found;
14576
Jani Nikula63cb4e62019-01-22 10:23:01 +020014577 if (intel_ddi_crt_present(dev_priv))
14578 intel_crt_init(dev_priv);
14579
Jesse Barnesde31fac2015-03-06 15:53:32 -080014580 /*
14581 * Haswell uses DDI functions to detect digital outputs.
14582 * On SKL pre-D0 the strap isn't connected, so we assume
14583 * it's there.
14584 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014585 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014586 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014587 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014588 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014589
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014590 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014591 * register */
14592 found = I915_READ(SFUSE_STRAP);
14593
14594 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014595 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014596 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014597 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014598 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014599 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014600 if (found & SFUSE_STRAP_DDIF_DETECTED)
14601 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014602 /*
14603 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14604 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014605 if (IS_GEN9_BC(dev_priv) &&
Imre Deake9d49bb2018-12-20 15:26:02 +020014606 intel_bios_is_port_present(dev_priv, PORT_E))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014607 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014608
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014609 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014610 int found;
Jani Nikula63cb4e62019-01-22 10:23:01 +020014611
Jani Nikula0fafa222019-01-22 10:23:02 +020014612 /*
14613 * intel_edp_init_connector() depends on this completing first,
14614 * to prevent the registration of both eDP and LVDS and the
14615 * incorrect sharing of the PPS.
14616 */
14617 intel_lvds_init(dev_priv);
Jani Nikula74d021e2019-01-22 10:23:07 +020014618 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014619
Jani Nikula7b91bf72017-08-18 12:30:19 +030014620 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014621
Jani Nikulaa5916fd2019-01-22 10:23:05 +020014622 if (ilk_has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014623 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014624
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014625 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014626 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014627 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014628 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014629 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014630 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014631 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014632 }
14633
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014634 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014635 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014636
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014637 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014638 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014639
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014640 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014641 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014642
Daniel Vetter270b3042012-10-27 15:52:05 +020014643 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014644 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014645 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014646 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014647
Jani Nikula63cb4e62019-01-22 10:23:01 +020014648 if (IS_VALLEYVIEW(dev_priv) && dev_priv->vbt.int_crt_support)
14649 intel_crt_init(dev_priv);
14650
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014651 /*
14652 * The DP_DETECTED bit is the latched state of the DDC
14653 * SDA pin at boot. However since eDP doesn't require DDC
14654 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14655 * eDP ports may have been muxed to an alternate function.
14656 * Thus we can't rely on the DP_DETECTED bit alone to detect
14657 * eDP ports. Consult the VBT as well as DP_DETECTED to
14658 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014659 *
14660 * Sadly the straps seem to be missing sometimes even for HDMI
14661 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14662 * and VBT for the presence of the port. Additionally we can't
14663 * trust the port type the VBT declares as we've seen at least
14664 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014665 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014666 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014667 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14668 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014669 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014670 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014671 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014672
Jani Nikula7b91bf72017-08-18 12:30:19 +030014673 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014674 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14675 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014676 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014677 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014678 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014679
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014680 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014681 /*
14682 * eDP not supported on port D,
14683 * so no need to worry about it
14684 */
14685 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14686 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014687 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014688 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014689 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014690 }
14691
Jani Nikulae5186342018-07-05 16:25:08 +030014692 vlv_dsi_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014693 } else if (IS_PINEVIEW(dev_priv)) {
Jani Nikula0fafa222019-01-22 10:23:02 +020014694 intel_lvds_init(dev_priv);
Jani Nikula74d021e2019-01-22 10:23:07 +020014695 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014696 } else if (IS_GEN_RANGE(dev_priv, 3, 4)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014697 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014698
Jani Nikula9bedc7e2019-01-22 10:23:03 +020014699 if (IS_MOBILE(dev_priv))
14700 intel_lvds_init(dev_priv);
Jani Nikula0fafa222019-01-22 10:23:02 +020014701
Jani Nikula74d021e2019-01-22 10:23:07 +020014702 intel_crt_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014703
Paulo Zanonie2debe92013-02-18 19:00:27 -030014704 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014705 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014706 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014707 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014708 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014709 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014710 }
Ma Ling27185ae2009-08-24 13:50:23 +080014711
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014712 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014713 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014714 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014715
14716 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014717
Paulo Zanonie2debe92013-02-18 19:00:27 -030014718 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014719 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014720 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014721 }
Ma Ling27185ae2009-08-24 13:50:23 +080014722
Paulo Zanonie2debe92013-02-18 19:00:27 -030014723 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014724
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014725 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014726 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014727 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014728 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014729 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014730 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014731 }
Ma Ling27185ae2009-08-24 13:50:23 +080014732
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014733 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014734 intel_dp_init(dev_priv, DP_D, PORT_D);
Jesse Barnes79e53942008-11-07 14:24:08 -080014735
Jani Nikulad6521462019-01-22 10:23:04 +020014736 if (SUPPORTS_TV(dev_priv))
14737 intel_tv_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014738 } else if (IS_GEN(dev_priv, 2)) {
Jani Nikula346073c2019-01-22 10:23:06 +020014739 if (IS_I85X(dev_priv))
Jani Nikula9bedc7e2019-01-22 10:23:03 +020014740 intel_lvds_init(dev_priv);
Jani Nikula0fafa222019-01-22 10:23:02 +020014741
Jani Nikula74d021e2019-01-22 10:23:07 +020014742 intel_crt_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014743 intel_dvo_init(dev_priv);
Jani Nikula63cb4e62019-01-22 10:23:01 +020014744 }
Jesse Barnes79e53942008-11-07 14:24:08 -080014745
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014746 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014747
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014748 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014749 encoder->base.possible_crtcs = encoder->crtc_mask;
14750 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014751 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014752 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014753
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014754 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014755
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014756 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014757}
14758
14759static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14760{
14761 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014762 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014763
Daniel Vetteref2d6332014-02-10 18:00:38 +010014764 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014765
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014766 i915_gem_object_lock(obj);
14767 WARN_ON(!obj->framebuffer_references--);
14768 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014769
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014770 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014771
Jesse Barnes79e53942008-11-07 14:24:08 -080014772 kfree(intel_fb);
14773}
14774
14775static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014776 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014777 unsigned int *handle)
14778{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014779 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014780
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014781 if (obj->userptr.mm) {
14782 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14783 return -EINVAL;
14784 }
14785
Chris Wilson05394f32010-11-08 19:18:58 +000014786 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014787}
14788
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014789static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14790 struct drm_file *file,
14791 unsigned flags, unsigned color,
14792 struct drm_clip_rect *clips,
14793 unsigned num_clips)
14794{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014795 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014796
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014797 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014798 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014799
14800 return 0;
14801}
14802
Jesse Barnes79e53942008-11-07 14:24:08 -080014803static const struct drm_framebuffer_funcs intel_fb_funcs = {
14804 .destroy = intel_user_framebuffer_destroy,
14805 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014806 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014807};
14808
Damien Lespiaub3218032015-02-27 11:15:18 +000014809static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014810u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014811 u32 pixel_format, u64 fb_modifier)
Damien Lespiaub3218032015-02-27 11:15:18 +000014812{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014813 struct intel_crtc *crtc;
14814 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014815
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014816 /*
14817 * We assume the primary plane for pipe A has
14818 * the highest stride limits of them all.
14819 */
14820 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14821 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014822
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014823 return plane->max_stride(plane, pixel_format, fb_modifier,
14824 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014825}
14826
Chris Wilson24dbf512017-02-15 10:59:18 +000014827static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14828 struct drm_i915_gem_object *obj,
14829 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014830{
Chris Wilson24dbf512017-02-15 10:59:18 +000014831 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014832 struct drm_framebuffer *fb = &intel_fb->base;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014833 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014834 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014835 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014836 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014837
Chris Wilsondd689282017-03-01 15:41:28 +000014838 i915_gem_object_lock(obj);
14839 obj->framebuffer_references++;
14840 tiling = i915_gem_object_get_tiling(obj);
14841 stride = i915_gem_object_get_stride(obj);
14842 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014843
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014844 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014845 /*
14846 * If there's a fence, enforce that
14847 * the fb modifier and tiling mode match.
14848 */
14849 if (tiling != I915_TILING_NONE &&
14850 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014851 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014852 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014853 }
14854 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014855 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014856 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014857 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014858 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014859 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014860 }
14861 }
14862
Ville Syrjälä17e8fd12018-10-29 20:34:53 +020014863 if (!drm_any_plane_has_format(&dev_priv->drm,
14864 mode_cmd->pixel_format,
14865 mode_cmd->modifier[0])) {
14866 struct drm_format_name_buf format_name;
14867
14868 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14869 drm_get_format_name(mode_cmd->pixel_format,
14870 &format_name),
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014871 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014872 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014873 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014874
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014875 /*
14876 * gen2/3 display engine uses the fence if present,
14877 * so the tiling mode must match the fb modifier exactly.
14878 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014879 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014880 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014881 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014882 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014883 }
14884
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014885 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14886 mode_cmd->modifier[0]);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014887 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014888 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014889 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014890 "tiled" : "linear",
14891 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014892 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014893 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014894
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014895 /*
14896 * If there's a fence, enforce that
14897 * the fb pitch and fence stride match.
14898 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014899 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14900 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14901 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014902 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014903 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014904
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014905 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14906 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014907 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014908
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014909 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014910
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014911 for (i = 0; i < fb->format->num_planes; i++) {
14912 u32 stride_alignment;
14913
14914 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14915 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014916 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014917 }
14918
14919 stride_alignment = intel_fb_stride_alignment(fb, i);
14920
14921 /*
14922 * Display WA #0531: skl,bxt,kbl,glk
14923 *
14924 * Render decompression and plane width > 3840
14925 * combined with horizontal panning requires the
14926 * plane stride to be a multiple of 4. We'll just
14927 * require the entire fb to accommodate that to avoid
14928 * potential runtime errors at plane configuration time.
14929 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014930 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014931 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014932 stride_alignment *= 4;
14933
14934 if (fb->pitches[i] & (stride_alignment - 1)) {
14935 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14936 i, fb->pitches[i], stride_alignment);
14937 goto err;
14938 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014939
Daniel Stonea268bcd2018-05-18 15:30:08 +010014940 fb->obj[i] = &obj->base;
14941 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014942
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014943 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014944 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014945 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014946
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014947 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014948 if (ret) {
14949 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014950 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014951 }
14952
Jesse Barnes79e53942008-11-07 14:24:08 -080014953 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014954
14955err:
Chris Wilsondd689282017-03-01 15:41:28 +000014956 i915_gem_object_lock(obj);
14957 obj->framebuffer_references--;
14958 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014959 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014960}
14961
Jesse Barnes79e53942008-11-07 14:24:08 -080014962static struct drm_framebuffer *
14963intel_user_framebuffer_create(struct drm_device *dev,
14964 struct drm_file *filp,
Ville Syrjälä1eb83452015-11-11 19:11:29 +020014965 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014966{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014967 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014968 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014969 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014970
Chris Wilson03ac0642016-07-20 13:31:51 +010014971 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14972 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014973 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014974
Chris Wilson24dbf512017-02-15 10:59:18 +000014975 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014976 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014977 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014978
14979 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014980}
14981
Chris Wilson778e23a2016-12-05 14:29:39 +000014982static void intel_atomic_state_free(struct drm_atomic_state *state)
14983{
14984 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14985
14986 drm_atomic_state_default_release(state);
14987
14988 i915_sw_fence_fini(&intel_state->commit_ready);
14989
14990 kfree(state);
14991}
14992
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014993static enum drm_mode_status
14994intel_mode_valid(struct drm_device *dev,
14995 const struct drm_display_mode *mode)
14996{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014997 struct drm_i915_private *dev_priv = to_i915(dev);
14998 int hdisplay_max, htotal_max;
14999 int vdisplay_max, vtotal_max;
15000
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030015001 /*
15002 * Can't reject DBLSCAN here because Xorg ddxen can add piles
15003 * of DBLSCAN modes to the output's mode list when they detect
15004 * the scaling mode property on the connector. And they don't
15005 * ask the kernel to validate those modes in any way until
15006 * modeset time at which point the client gets a protocol error.
15007 * So in order to not upset those clients we silently ignore the
15008 * DBLSCAN flag on such connectors. For other connectors we will
15009 * reject modes with the DBLSCAN flag in encoder->compute_config().
15010 * And we always reject DBLSCAN modes in connector->mode_valid()
15011 * as we never want such modes on the connector's mode list.
15012 */
15013
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015014 if (mode->vscan > 1)
15015 return MODE_NO_VSCAN;
15016
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015017 if (mode->flags & DRM_MODE_FLAG_HSKEW)
15018 return MODE_H_ILLEGAL;
15019
15020 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
15021 DRM_MODE_FLAG_NCSYNC |
15022 DRM_MODE_FLAG_PCSYNC))
15023 return MODE_HSYNC;
15024
15025 if (mode->flags & (DRM_MODE_FLAG_BCAST |
15026 DRM_MODE_FLAG_PIXMUX |
15027 DRM_MODE_FLAG_CLKDIV2))
15028 return MODE_BAD;
15029
Ville Syrjäläad77c532018-06-15 20:44:05 +030015030 if (INTEL_GEN(dev_priv) >= 9 ||
15031 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
15032 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
15033 vdisplay_max = 4096;
15034 htotal_max = 8192;
15035 vtotal_max = 8192;
15036 } else if (INTEL_GEN(dev_priv) >= 3) {
15037 hdisplay_max = 4096;
15038 vdisplay_max = 4096;
15039 htotal_max = 8192;
15040 vtotal_max = 8192;
15041 } else {
15042 hdisplay_max = 2048;
15043 vdisplay_max = 2048;
15044 htotal_max = 4096;
15045 vtotal_max = 4096;
15046 }
15047
15048 if (mode->hdisplay > hdisplay_max ||
15049 mode->hsync_start > htotal_max ||
15050 mode->hsync_end > htotal_max ||
15051 mode->htotal > htotal_max)
15052 return MODE_H_ILLEGAL;
15053
15054 if (mode->vdisplay > vdisplay_max ||
15055 mode->vsync_start > vtotal_max ||
15056 mode->vsync_end > vtotal_max ||
15057 mode->vtotal > vtotal_max)
15058 return MODE_V_ILLEGAL;
15059
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015060 return MODE_OK;
15061}
15062
Jesse Barnes79e53942008-11-07 14:24:08 -080015063static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080015064 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070015065 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020015066 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020015067 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080015068 .atomic_check = intel_atomic_check,
15069 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020015070 .atomic_state_alloc = intel_atomic_state_alloc,
15071 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000015072 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080015073};
15074
Imre Deak88212942016-03-16 13:38:53 +020015075/**
15076 * intel_init_display_hooks - initialize the display modesetting hooks
15077 * @dev_priv: device private
15078 */
15079void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070015080{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020015081 intel_init_cdclk_hooks(dev_priv);
15082
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000015083 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000015084 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015085 dev_priv->display.get_initial_plane_config =
15086 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000015087 dev_priv->display.crtc_compute_clock =
15088 haswell_crtc_compute_clock;
15089 dev_priv->display.crtc_enable = haswell_crtc_enable;
15090 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020015091 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015092 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015093 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020015094 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020015095 dev_priv->display.crtc_compute_clock =
15096 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020015097 dev_priv->display.crtc_enable = haswell_crtc_enable;
15098 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020015099 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015100 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015101 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020015102 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020015103 dev_priv->display.crtc_compute_clock =
15104 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020015105 dev_priv->display.crtc_enable = ironlake_crtc_enable;
15106 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020015107 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070015108 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015109 dev_priv->display.get_initial_plane_config =
15110 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020015111 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
15112 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15113 dev_priv->display.crtc_disable = i9xx_crtc_disable;
15114 } else if (IS_VALLEYVIEW(dev_priv)) {
15115 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15116 dev_priv->display.get_initial_plane_config =
15117 i9xx_get_initial_plane_config;
15118 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070015119 dev_priv->display.crtc_enable = valleyview_crtc_enable;
15120 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020015121 } else if (IS_G4X(dev_priv)) {
15122 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15123 dev_priv->display.get_initial_plane_config =
15124 i9xx_get_initial_plane_config;
15125 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
15126 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15127 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020015128 } else if (IS_PINEVIEW(dev_priv)) {
15129 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15130 dev_priv->display.get_initial_plane_config =
15131 i9xx_get_initial_plane_config;
15132 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
15133 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15134 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015135 } else if (!IS_GEN(dev_priv, 2)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010015136 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000015137 dev_priv->display.get_initial_plane_config =
15138 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020015139 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020015140 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15141 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020015142 } else {
15143 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
15144 dev_priv->display.get_initial_plane_config =
15145 i9xx_get_initial_plane_config;
15146 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
15147 dev_priv->display.crtc_enable = i9xx_crtc_enable;
15148 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070015149 }
Jesse Barnese70236a2009-09-21 10:42:27 -070015150
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015151 if (IS_GEN(dev_priv, 5)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015152 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015153 } else if (IS_GEN(dev_priv, 6)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015154 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020015155 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015156 /* FIXME: detect B0+ stepping and use auto training */
15157 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020015158 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053015159 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030015160 }
15161
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070015162 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020015163 dev_priv->display.update_crtcs = skl_update_crtcs;
15164 else
15165 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070015166}
15167
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015168/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015169static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015170{
David Weinehall52a05c32016-08-22 13:32:44 +030015171 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015172 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015173 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015174
Ville Syrjälä2b37c612014-01-22 21:32:38 +020015175 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030015176 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070015177 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015178 sr1 = inb(VGA_SR_DATA);
15179 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030015180 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015181 udelay(300);
15182
Ville Syrjälä01f5a622014-12-16 18:38:37 +020015183 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015184 POSTING_READ(vga_reg);
15185}
15186
Daniel Vetterf8175862012-04-10 15:50:11 +020015187void intel_modeset_init_hw(struct drm_device *dev)
15188{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015189 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010015190
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015191 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030015192 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020015193 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020015194}
15195
Matt Roperd93c0372015-12-03 11:37:41 -080015196/*
15197 * Calculate what we think the watermarks should be for the state we've read
15198 * out of the hardware and then immediately program those watermarks so that
15199 * we ensure the hardware settings match our internal state.
15200 *
15201 * We can calculate what we think WM's should be by creating a duplicate of the
15202 * current state (which was constructed during hardware readout) and running it
15203 * through the atomic check code to calculate new watermark values in the
15204 * state object.
15205 */
15206static void sanitize_watermarks(struct drm_device *dev)
15207{
15208 struct drm_i915_private *dev_priv = to_i915(dev);
15209 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015210 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080015211 struct drm_crtc *crtc;
15212 struct drm_crtc_state *cstate;
15213 struct drm_modeset_acquire_ctx ctx;
15214 int ret;
15215 int i;
15216
15217 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080015218 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080015219 return;
15220
15221 /*
15222 * We need to hold connection_mutex before calling duplicate_state so
15223 * that the connector loop is protected.
15224 */
15225 drm_modeset_acquire_init(&ctx, 0);
15226retry:
Matt Roper0cd12622016-01-12 07:13:37 -080015227 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080015228 if (ret == -EDEADLK) {
15229 drm_modeset_backoff(&ctx);
15230 goto retry;
15231 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080015232 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080015233 }
15234
15235 state = drm_atomic_helper_duplicate_state(dev, &ctx);
15236 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080015237 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080015238
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015239 intel_state = to_intel_atomic_state(state);
15240
Matt Ropered4a6a72016-02-23 17:20:13 -080015241 /*
15242 * Hardware readout is the only time we don't want to calculate
15243 * intermediate watermarks (since we don't trust the current
15244 * watermarks).
15245 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015246 if (!HAS_GMCH(dev_priv))
Ville Syrjälä602ae832017-03-02 19:15:02 +020015247 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080015248
Matt Roperd93c0372015-12-03 11:37:41 -080015249 ret = intel_atomic_check(dev, state);
15250 if (ret) {
15251 /*
15252 * If we fail here, it means that the hardware appears to be
15253 * programmed in a way that shouldn't be possible, given our
15254 * understanding of watermark requirements. This might mean a
15255 * mistake in the hardware readout code or a mistake in the
15256 * watermark calculations for a given platform. Raise a WARN
15257 * so that this is noticeable.
15258 *
15259 * If this actually happens, we'll have to just leave the
15260 * BIOS-programmed watermarks untouched and hope for the best.
15261 */
15262 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020015263 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080015264 }
15265
15266 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010015267 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080015268 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
15269
Matt Ropered4a6a72016-02-23 17:20:13 -080015270 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010015271 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010015272
15273 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080015274 }
15275
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020015276put_state:
Chris Wilson08536952016-10-14 13:18:18 +010015277 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080015278fail:
Matt Roperd93c0372015-12-03 11:37:41 -080015279 drm_modeset_drop_locks(&ctx);
15280 drm_modeset_acquire_fini(&ctx);
15281}
15282
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015283static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
15284{
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015285 if (IS_GEN(dev_priv, 5)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015286 u32 fdi_pll_clk =
15287 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
15288
15289 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015290 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015291 dev_priv->fdi_pll_freq = 270000;
15292 } else {
15293 return;
15294 }
15295
15296 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
15297}
15298
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015299static int intel_initial_commit(struct drm_device *dev)
15300{
15301 struct drm_atomic_state *state = NULL;
15302 struct drm_modeset_acquire_ctx ctx;
15303 struct drm_crtc *crtc;
15304 struct drm_crtc_state *crtc_state;
15305 int ret = 0;
15306
15307 state = drm_atomic_state_alloc(dev);
15308 if (!state)
15309 return -ENOMEM;
15310
15311 drm_modeset_acquire_init(&ctx, 0);
15312
15313retry:
15314 state->acquire_ctx = &ctx;
15315
15316 drm_for_each_crtc(crtc, dev) {
15317 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15318 if (IS_ERR(crtc_state)) {
15319 ret = PTR_ERR(crtc_state);
15320 goto out;
15321 }
15322
15323 if (crtc_state->active) {
15324 ret = drm_atomic_add_affected_planes(state, crtc);
15325 if (ret)
15326 goto out;
Ville Syrjäläfa6af5142018-11-20 15:54:49 +020015327
15328 /*
15329 * FIXME hack to force a LUT update to avoid the
15330 * plane update forcing the pipe gamma on without
15331 * having a proper LUT loaded. Remove once we
15332 * have readout for pipe gamma enable.
15333 */
15334 crtc_state->color_mgmt_changed = true;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015335 }
15336 }
15337
15338 ret = drm_atomic_commit(state);
15339
15340out:
15341 if (ret == -EDEADLK) {
15342 drm_atomic_state_clear(state);
15343 drm_modeset_backoff(&ctx);
15344 goto retry;
15345 }
15346
15347 drm_atomic_state_put(state);
15348
15349 drm_modeset_drop_locks(&ctx);
15350 drm_modeset_acquire_fini(&ctx);
15351
15352 return ret;
15353}
15354
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015355int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080015356{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030015357 struct drm_i915_private *dev_priv = to_i915(dev);
15358 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000015359 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080015360 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015361 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080015362
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015363 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15364
Jesse Barnes79e53942008-11-07 14:24:08 -080015365 drm_mode_config_init(dev);
15366
15367 dev->mode_config.min_width = 0;
15368 dev->mode_config.min_height = 0;
15369
Dave Airlie019d96c2011-09-29 16:20:42 +010015370 dev->mode_config.preferred_depth = 24;
15371 dev->mode_config.prefer_shadow = 1;
15372
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015373 dev->mode_config.allow_fb_modifiers = true;
15374
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015375 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015376
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015377 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015378 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015379 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015380
Jani Nikula27a981b2018-10-17 12:35:39 +030015381 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015382
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015383 intel_fbc_init(dev_priv);
15384
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015385 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015386
Lukas Wunner69f92f62015-07-15 13:57:35 +020015387 /*
15388 * There may be no VBT; and if the BIOS enabled SSC we can
15389 * just keep using it to avoid unnecessary flicker. Whereas if the
15390 * BIOS isn't using it, don't assume it will work even if the VBT
15391 * indicates as much.
15392 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015393 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015394 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15395 DREF_SSC1_ENABLE);
15396
15397 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15398 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15399 bios_lvds_use_ssc ? "en" : "dis",
15400 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15401 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15402 }
15403 }
15404
Ville Syrjäläad77c532018-06-15 20:44:05 +030015405 /* maximum framebuffer dimensions */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015406 if (IS_GEN(dev_priv, 2)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015407 dev->mode_config.max_width = 2048;
15408 dev->mode_config.max_height = 2048;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015409 } else if (IS_GEN(dev_priv, 3)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015410 dev->mode_config.max_width = 4096;
15411 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015412 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015413 dev->mode_config.max_width = 8192;
15414 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015415 }
Damien Lespiau068be562014-03-28 14:17:49 +000015416
Jani Nikula2a307c22016-11-30 17:43:04 +020015417 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15418 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015419 dev->mode_config.cursor_height = 1023;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015420 } else if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015421 dev->mode_config.cursor_width = 64;
15422 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015423 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015424 dev->mode_config.cursor_width = 256;
15425 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015426 }
15427
Matthew Auld73ebd502017-12-11 15:18:20 +000015428 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015429
Zhao Yakui28c97732009-10-09 11:39:41 +080015430 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015431 INTEL_INFO(dev_priv)->num_pipes,
15432 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015433
Damien Lespiau055e3932014-08-18 13:49:10 +010015434 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015435 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015436 if (ret) {
15437 drm_mode_config_cleanup(dev);
15438 return ret;
15439 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015440 }
15441
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015442 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015443 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015444
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015445 intel_update_czclk(dev_priv);
15446 intel_modeset_init_hw(dev);
15447
Ville Syrjäläb2045352016-05-13 23:41:27 +030015448 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015449 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015450
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015451 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015452 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015453 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015454
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015455 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015456 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015457 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015458
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015459 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015460 struct intel_initial_plane_config plane_config = {};
15461
Jesse Barnes46f297f2014-03-07 08:57:48 -080015462 if (!crtc->active)
15463 continue;
15464
Jesse Barnes46f297f2014-03-07 08:57:48 -080015465 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015466 * Note that reserving the BIOS fb up front prevents us
15467 * from stuffing other stolen allocations like the ring
15468 * on top. This prevents some ugliness at boot time, and
15469 * can even allow for smooth boot transitions if the BIOS
15470 * fb is large enough for the active pipe configuration.
15471 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015472 dev_priv->display.get_initial_plane_config(crtc,
15473 &plane_config);
15474
15475 /*
15476 * If the fb is shared between multiple heads, we'll
15477 * just get the first one.
15478 */
15479 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015480 }
Matt Roperd93c0372015-12-03 11:37:41 -080015481
15482 /*
15483 * Make sure hardware watermarks really match the state we read out.
15484 * Note that we need to do this after reconstructing the BIOS fb's
15485 * since the watermark calculation done here will use pstate->fb.
15486 */
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015487 if (!HAS_GMCH(dev_priv))
Ville Syrjälä602ae832017-03-02 19:15:02 +020015488 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015489
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015490 /*
15491 * Force all active planes to recompute their states. So that on
15492 * mode_setcrtc after probe, all the intel_plane_state variables
15493 * are already calculated and there is no assert_plane warnings
15494 * during bootup.
15495 */
15496 ret = intel_initial_commit(dev);
15497 if (ret)
15498 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15499
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015500 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015501}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015502
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015503void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15504{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015505 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015506 /* 640x480@60Hz, ~25175 kHz */
15507 struct dpll clock = {
15508 .m1 = 18,
15509 .m2 = 7,
15510 .p1 = 13,
15511 .p2 = 4,
15512 .n = 2,
15513 };
15514 u32 dpll, fp;
15515 int i;
15516
15517 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15518
15519 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15520 pipe_name(pipe), clock.vco, clock.dot);
15521
15522 fp = i9xx_dpll_compute_fp(&clock);
15523 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15524 DPLL_VGA_MODE_DIS |
15525 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15526 PLL_P2_DIVIDE_BY_4 |
15527 PLL_REF_INPUT_DREFCLK |
15528 DPLL_VCO_ENABLE;
15529
15530 I915_WRITE(FP0(pipe), fp);
15531 I915_WRITE(FP1(pipe), fp);
15532
15533 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15534 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15535 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15536 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15537 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15538 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15539 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15540
15541 /*
15542 * Apparently we need to have VGA mode enabled prior to changing
15543 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15544 * dividers, even though the register value does change.
15545 */
15546 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15547 I915_WRITE(DPLL(pipe), dpll);
15548
15549 /* Wait for the clocks to stabilize. */
15550 POSTING_READ(DPLL(pipe));
15551 udelay(150);
15552
15553 /* The pixel multiplier can only be updated once the
15554 * DPLL is enabled and the clocks are stable.
15555 *
15556 * So write it again.
15557 */
15558 I915_WRITE(DPLL(pipe), dpll);
15559
15560 /* We do this three times for luck */
15561 for (i = 0; i < 3 ; i++) {
15562 I915_WRITE(DPLL(pipe), dpll);
15563 POSTING_READ(DPLL(pipe));
15564 udelay(150); /* wait for warmup */
15565 }
15566
15567 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15568 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015569
15570 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015571}
15572
15573void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15574{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015575 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15576
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015577 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15578 pipe_name(pipe));
15579
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015580 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15581 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15582 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015583 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15584 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015585
15586 I915_WRITE(PIPECONF(pipe), 0);
15587 POSTING_READ(PIPECONF(pipe));
15588
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015589 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015590
15591 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15592 POSTING_READ(DPLL(pipe));
15593}
15594
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015595static void
15596intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15597{
15598 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015599
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015600 if (INTEL_GEN(dev_priv) >= 4)
15601 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015602
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015603 for_each_intel_crtc(&dev_priv->drm, crtc) {
15604 struct intel_plane *plane =
15605 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015606 struct intel_crtc *plane_crtc;
15607 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015608
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015609 if (!plane->get_hw_state(plane, &pipe))
15610 continue;
15611
15612 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015613 continue;
15614
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015615 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15616 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015617
15618 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15619 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015620 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015621}
15622
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015623static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15624{
15625 struct drm_device *dev = crtc->base.dev;
15626 struct intel_encoder *encoder;
15627
15628 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15629 return true;
15630
15631 return false;
15632}
15633
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015634static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15635{
15636 struct drm_device *dev = encoder->base.dev;
15637 struct intel_connector *connector;
15638
15639 for_each_connector_on_encoder(dev, &encoder->base, connector)
15640 return connector;
15641
15642 return NULL;
15643}
15644
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015645static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015646 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015647{
15648 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015649 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015650}
15651
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015652static void intel_sanitize_crtc(struct intel_crtc *crtc,
15653 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015654{
15655 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015656 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015657 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15658 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015659
Daniel Vetter24929352012-07-02 20:28:59 +020015660 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015661 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015662 i915_reg_t reg = PIPECONF(cpu_transcoder);
15663
15664 I915_WRITE(reg,
15665 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15666 }
Daniel Vetter24929352012-07-02 20:28:59 +020015667
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015668 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015669 struct intel_plane *plane;
15670
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015671 /* Disable everything but the primary plane */
15672 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015673 const struct intel_plane_state *plane_state =
15674 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015675
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015676 if (plane_state->base.visible &&
15677 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15678 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015679 }
Matt Roperc0550302019-01-30 10:51:20 -080015680
15681 /*
15682 * Disable any background color set by the BIOS, but enable the
15683 * gamma and CSC to match how we program our planes.
15684 */
15685 if (INTEL_GEN(dev_priv) >= 9)
15686 I915_WRITE(SKL_BOTTOM_COLOR(crtc->pipe),
15687 SKL_BOTTOM_COLOR_GAMMA_ENABLE |
15688 SKL_BOTTOM_COLOR_CSC_ENABLE);
Daniel Vetter96256042015-02-13 21:03:42 +010015689 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015690
Daniel Vetter24929352012-07-02 20:28:59 +020015691 /* Adjust the state of the output pipe according to whether we
15692 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015693 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015694 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015695
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080015696 if (crtc_state->base.active || HAS_GMCH(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015697 /*
15698 * We start out with underrun reporting disabled to avoid races.
15699 * For correct bookkeeping mark this on active crtcs.
15700 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015701 * Also on gmch platforms we dont have any hardware bits to
15702 * disable the underrun reporting. Which means we need to start
15703 * out with underrun reporting disabled also on inactive pipes,
15704 * since otherwise we'll complain about the garbage we read when
15705 * e.g. coming up after runtime pm.
15706 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015707 * No protection against concurrent access is required - at
15708 * worst a fifo underrun happens which also sets this to false.
15709 */
15710 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015711 /*
15712 * We track the PCH trancoder underrun reporting state
15713 * within the crtc. With crtc for pipe A housing the underrun
15714 * reporting state for PCH transcoder A, crtc for pipe B housing
15715 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15716 * and marking underrun reporting as disabled for the non-existing
15717 * PCH transcoders B and C would prevent enabling the south
15718 * error interrupt (see cpt_can_enable_serr_int()).
15719 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015720 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015721 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015722 }
Daniel Vetter24929352012-07-02 20:28:59 +020015723}
15724
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015725static bool has_bogus_dpll_config(const struct intel_crtc_state *crtc_state)
15726{
15727 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
15728
15729 /*
15730 * Some SNB BIOSen (eg. ASUS K53SV) are known to misprogram
15731 * the hardware when a high res displays plugged in. DPLL P
15732 * divider is zero, and the pipe timings are bonkers. We'll
15733 * try to disable everything in that case.
15734 *
15735 * FIXME would be nice to be able to sanitize this state
15736 * without several WARNs, but for now let's take the easy
15737 * road.
15738 */
15739 return IS_GEN(dev_priv, 6) &&
15740 crtc_state->base.active &&
15741 crtc_state->shared_dpll &&
15742 crtc_state->port_clock == 0;
15743}
15744
Daniel Vetter24929352012-07-02 20:28:59 +020015745static void intel_sanitize_encoder(struct intel_encoder *encoder)
15746{
Imre Deak70332ac2018-11-01 16:04:27 +020015747 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015748 struct intel_connector *connector;
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015749 struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
15750 struct intel_crtc_state *crtc_state = crtc ?
15751 to_intel_crtc_state(crtc->base.state) : NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015752
15753 /* We need to check both for a crtc link (meaning that the
15754 * encoder is active and trying to read from a pipe) and the
15755 * pipe itself being active. */
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015756 bool has_active_crtc = crtc_state &&
15757 crtc_state->base.active;
15758
15759 if (crtc_state && has_bogus_dpll_config(crtc_state)) {
15760 DRM_DEBUG_KMS("BIOS has misprogrammed the hardware. Disabling pipe %c\n",
15761 pipe_name(crtc->pipe));
15762 has_active_crtc = false;
15763 }
Daniel Vetter24929352012-07-02 20:28:59 +020015764
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015765 connector = intel_encoder_find_connector(encoder);
15766 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015767 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15768 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015769 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015770
15771 /* Connector is active, but has no active pipe. This is
15772 * fallout from our resume register restoring. Disable
15773 * the encoder manually again. */
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015774 if (crtc_state) {
15775 struct drm_encoder *best_encoder;
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015776
Daniel Vetter24929352012-07-02 20:28:59 +020015777 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15778 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015779 encoder->base.name);
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015780
15781 /* avoid oopsing in case the hooks consult best_encoder */
15782 best_encoder = connector->base.state->best_encoder;
15783 connector->base.state->best_encoder = &encoder->base;
15784
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015785 if (encoder->disable)
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015786 encoder->disable(encoder, crtc_state,
15787 connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015788 if (encoder->post_disable)
Ville Syrjälä7bed8ad2019-01-11 19:49:50 +020015789 encoder->post_disable(encoder, crtc_state,
15790 connector->base.state);
15791
15792 connector->base.state->best_encoder = best_encoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015793 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015794 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015795
15796 /* Inconsistent output/port/pipe state happens presumably due to
15797 * a bug in one of the get_hw_state functions. Or someplace else
15798 * in our code, like the register restore mess on resume. Clamp
15799 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015800
15801 connector->base.dpms = DRM_MODE_DPMS_OFF;
15802 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015803 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015804
15805 /* notify opregion of the sanitized encoder state */
15806 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Imre Deak70332ac2018-11-01 16:04:27 +020015807
15808 if (INTEL_GEN(dev_priv) >= 11)
15809 icl_sanitize_encoder_pll_mapping(encoder);
Daniel Vetter24929352012-07-02 20:28:59 +020015810}
15811
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015812void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015813{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015814 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015815
Imre Deak04098752014-02-18 00:02:16 +020015816 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15817 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015818 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015819 }
15820}
15821
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015822void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015823{
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015824 intel_wakeref_t wakeref;
15825
15826 /*
15827 * This function can be called both from intel_modeset_setup_hw_state or
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015828 * at a very early point in our resume sequence, where the power well
15829 * structures are not yet restored. Since this function is at a very
15830 * paranoid "someone might have enabled VGA while we were not looking"
15831 * level, just check if the power well is enabled instead of trying to
15832 * follow the "don't touch the power well if we don't need it" policy
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015833 * the rest of the driver uses.
15834 */
15835 wakeref = intel_display_power_get_if_enabled(dev_priv,
15836 POWER_DOMAIN_VGA);
15837 if (!wakeref)
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015838 return;
15839
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015840 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015841
Chris Wilson0e6e0be2019-01-14 14:21:24 +000015842 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA, wakeref);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015843}
15844
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015845/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015846static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015847{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015848 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015849 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015850
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015851 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015852 struct intel_plane_state *plane_state =
15853 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015854 struct intel_crtc_state *crtc_state;
15855 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015856 bool visible;
15857
15858 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015859
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015860 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15861 crtc_state = to_intel_crtc_state(crtc->base.state);
15862
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015863 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015864
15865 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15866 plane->base.base.id, plane->base.name,
15867 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015868 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015869
15870 for_each_intel_crtc(&dev_priv->drm, crtc) {
15871 struct intel_crtc_state *crtc_state =
15872 to_intel_crtc_state(crtc->base.state);
15873
15874 fixup_active_planes(crtc_state);
15875 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015876}
15877
Daniel Vetter30e984d2013-06-05 13:34:17 +020015878static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015879{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015880 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015881 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015882 struct intel_crtc *crtc;
15883 struct intel_encoder *encoder;
15884 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015885 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015886 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015887
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015888 dev_priv->active_crtcs = 0;
15889
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015890 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015891 struct intel_crtc_state *crtc_state =
15892 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015893
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015894 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015895 memset(crtc_state, 0, sizeof(*crtc_state));
15896 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015897
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015898 crtc_state->base.active = crtc_state->base.enable =
15899 dev_priv->display.get_pipe_config(crtc, crtc_state);
15900
15901 crtc->base.enabled = crtc_state->base.enable;
15902 crtc->active = crtc_state->base.active;
15903
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015904 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015905 dev_priv->active_crtcs |= 1 << crtc->pipe;
15906
Ville Syrjälä78108b72016-05-27 20:59:19 +030015907 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15908 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015909 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015910 }
15911
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015912 readout_plane_state(dev_priv);
15913
Daniel Vetter53589012013-06-05 13:34:16 +020015914 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15915 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15916
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015917 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15918 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015919 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015920 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015921 struct intel_crtc_state *crtc_state =
15922 to_intel_crtc_state(crtc->base.state);
15923
15924 if (crtc_state->base.active &&
15925 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015926 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015927 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015928 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015929
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015930 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015931 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015932 }
15933
Damien Lespiaub2784e12014-08-05 11:29:37 +010015934 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015935 pipe = 0;
15936
15937 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015938 struct intel_crtc_state *crtc_state;
15939
Ville Syrjälä98187832016-10-31 22:37:10 +020015940 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015941 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015942
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015943 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015944 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015945 } else {
15946 encoder->base.crtc = NULL;
15947 }
15948
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015949 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015950 encoder->base.base.id, encoder->base.name,
15951 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015952 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015953 }
15954
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015955 drm_connector_list_iter_begin(dev, &conn_iter);
15956 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015957 if (connector->get_hw_state(connector)) {
15958 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015959
15960 encoder = connector->encoder;
15961 connector->base.encoder = &encoder->base;
15962
15963 if (encoder->base.crtc &&
15964 encoder->base.crtc->state->active) {
15965 /*
15966 * This has to be done during hardware readout
15967 * because anything calling .crtc_disable may
15968 * rely on the connector_mask being accurate.
15969 */
15970 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015971 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015972 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015973 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015974 }
15975
Daniel Vetter24929352012-07-02 20:28:59 +020015976 } else {
15977 connector->base.dpms = DRM_MODE_DPMS_OFF;
15978 connector->base.encoder = NULL;
15979 }
15980 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015981 connector->base.base.id, connector->base.name,
15982 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015983 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015984 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015985
15986 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015987 struct intel_crtc_state *crtc_state =
15988 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015989 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015990
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015991 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015992 if (crtc_state->base.active) {
15993 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015994 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15995 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015996 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015997 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15998
15999 /*
16000 * The initial mode needs to be set in order to keep
16001 * the atomic core happy. It wants a valid mode if the
16002 * crtc's enabled, so we do the above call.
16003 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010016004 * But we don't set all the derived state fully, hence
16005 * set a flag to indicate that a full recalculation is
16006 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030016007 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020016008 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030016009
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020016010 intel_crtc_compute_pixel_rate(crtc_state);
16011
Ville Syrjälä9c61de42017-07-10 22:33:47 +030016012 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030016013 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030016014 if (WARN_ON(min_cdclk < 0))
16015 min_cdclk = 0;
16016 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020016017
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020016018 drm_calc_timestamping_constants(&crtc->base,
16019 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020016020 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030016021 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020016022
Ville Syrjäläd305e062017-08-30 21:57:03 +030016023 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030016024 dev_priv->min_voltage_level[crtc->pipe] =
16025 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020016026
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020016027 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030016028 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020016029}
16030
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020016031static void
16032get_encoder_power_domains(struct drm_i915_private *dev_priv)
16033{
16034 struct intel_encoder *encoder;
16035
16036 for_each_intel_encoder(&dev_priv->drm, encoder) {
16037 u64 get_domains;
16038 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030016039 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020016040
16041 if (!encoder->get_power_domains)
16042 continue;
16043
Imre Deak52528052018-06-21 21:44:49 +030016044 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030016045 * MST-primary and inactive encoders don't have a crtc state
16046 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030016047 */
Imre Deakb79ebe72018-07-05 15:26:54 +030016048 if (!encoder->base.crtc)
16049 continue;
Imre Deak52528052018-06-21 21:44:49 +030016050
Imre Deakb79ebe72018-07-05 15:26:54 +030016051 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030016052 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020016053 for_each_power_domain(domain, get_domains)
16054 intel_display_power_get(dev_priv, domain);
16055 }
16056}
16057
Rodrigo Vividf49ec82017-11-10 16:03:19 -080016058static void intel_early_display_was(struct drm_i915_private *dev_priv)
16059{
16060 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
16061 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
16062 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
16063 DARBF_GATING_DIS);
16064
16065 if (IS_HASWELL(dev_priv)) {
16066 /*
16067 * WaRsPkgCStateDisplayPMReq:hsw
16068 * System hang if this isn't done before disabling all planes!
16069 */
16070 I915_WRITE(CHICKEN_PAR1_1,
16071 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
16072 }
16073}
16074
Ville Syrjälä3aefb672018-11-08 16:36:35 +020016075static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
16076 enum port port, i915_reg_t hdmi_reg)
16077{
16078 u32 val = I915_READ(hdmi_reg);
16079
16080 if (val & SDVO_ENABLE ||
16081 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
16082 return;
16083
16084 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
16085 port_name(port));
16086
16087 val &= ~SDVO_PIPE_SEL_MASK;
16088 val |= SDVO_PIPE_SEL(PIPE_A);
16089
16090 I915_WRITE(hdmi_reg, val);
16091}
16092
16093static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
16094 enum port port, i915_reg_t dp_reg)
16095{
16096 u32 val = I915_READ(dp_reg);
16097
16098 if (val & DP_PORT_EN ||
16099 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
16100 return;
16101
16102 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
16103 port_name(port));
16104
16105 val &= ~DP_PIPE_SEL_MASK;
16106 val |= DP_PIPE_SEL(PIPE_A);
16107
16108 I915_WRITE(dp_reg, val);
16109}
16110
16111static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
16112{
16113 /*
16114 * The BIOS may select transcoder B on some of the PCH
16115 * ports even it doesn't enable the port. This would trip
16116 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
16117 * Sanitize the transcoder select bits to prevent that. We
16118 * assume that the BIOS never actually enabled the port,
16119 * because if it did we'd actually have to toggle the port
16120 * on and back off to make the transcoder A select stick
16121 * (see. intel_dp_link_down(), intel_disable_hdmi(),
16122 * intel_disable_sdvo()).
16123 */
16124 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
16125 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
16126 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
16127
16128 /* PCH SDVOB multiplex with HDMIB */
16129 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
16130 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
16131 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
16132}
16133
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016134/* Scan out the current hw modeset state,
16135 * and sanitizes it to the current state
16136 */
16137static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030016138intel_modeset_setup_hw_state(struct drm_device *dev,
16139 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020016140{
Chris Wilsonfac5e232016-07-04 11:34:36 +010016141 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016142 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020016143 struct intel_encoder *encoder;
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016144 struct intel_crtc *crtc;
16145 intel_wakeref_t wakeref;
Daniel Vetter35c95372013-07-17 06:55:04 +020016146 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020016147
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016148 wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
Imre Deak2cd9a682018-08-16 15:37:57 +030016149
Rodrigo Vividf49ec82017-11-10 16:03:19 -080016150 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020016151 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020016152
16153 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020016154 get_encoder_power_domains(dev_priv);
16155
Ville Syrjälä3aefb672018-11-08 16:36:35 +020016156 if (HAS_PCH_IBX(dev_priv))
16157 ibx_sanitize_pch_ports(dev_priv);
16158
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016159 /*
16160 * intel_sanitize_plane_mapping() may need to do vblank
16161 * waits, so we need vblank interrupts restored beforehand.
16162 */
16163 for_each_intel_crtc(&dev_priv->drm, crtc) {
Ville Syrjälä32db0b62018-11-27 22:05:50 +020016164 crtc_state = to_intel_crtc_state(crtc->base.state);
16165
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016166 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020016167
Ville Syrjälä32db0b62018-11-27 22:05:50 +020016168 if (crtc_state->base.active)
16169 intel_crtc_vblank_on(crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020016170 }
16171
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016172 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020016173
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030016174 for_each_intel_encoder(dev, encoder)
16175 intel_sanitize_encoder(encoder);
16176
16177 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016178 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030016179 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016180 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020016181 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020016182 }
Daniel Vetter9a935852012-07-05 22:34:27 +020016183
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020016184 intel_modeset_update_connector_atomic_state(dev);
16185
Daniel Vetter35c95372013-07-17 06:55:04 +020016186 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
16187 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
16188
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010016189 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020016190 continue;
16191
Lucas De Marchi72f775f2018-03-20 15:06:34 -070016192 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
16193 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020016194
Lucas De Marchiee1398b2018-03-20 15:06:33 -070016195 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020016196 pll->on = false;
16197 }
16198
Ville Syrjälä04548cb2017-04-21 21:14:29 +030016199 if (IS_G4X(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016200 g4x_wm_get_hw_state(dev_priv);
Ville Syrjälä04548cb2017-04-21 21:14:29 +030016201 g4x_wm_sanitize(dev_priv);
16202 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016203 vlv_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016204 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070016205 } else if (INTEL_GEN(dev_priv) >= 9) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016206 skl_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016207 } else if (HAS_PCH_SPLIT(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080016208 ilk_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020016209 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016210
16211 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020016212 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016213
Maarten Lankhorst91d78192018-10-11 12:04:54 +020016214 crtc_state = to_intel_crtc_state(crtc->base.state);
16215 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020016216 if (WARN_ON(put_domains))
16217 modeset_put_power_domains(dev_priv, put_domains);
16218 }
Imre Deak2cd9a682018-08-16 15:37:57 +030016219
Chris Wilson0e6e0be2019-01-14 14:21:24 +000016220 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
Paulo Zanoni010cf732016-01-19 11:35:48 -020016221
16222 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016223}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030016224
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016225void intel_display_resume(struct drm_device *dev)
16226{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016227 struct drm_i915_private *dev_priv = to_i915(dev);
16228 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
16229 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016230 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020016231
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016232 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030016233 if (state)
16234 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016235
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016236 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016237
Maarten Lankhorst73974892016-08-05 23:28:27 +030016238 while (1) {
16239 ret = drm_modeset_lock_all_ctx(dev, &ctx);
16240 if (ret != -EDEADLK)
16241 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016242
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016243 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016244 }
16245
Maarten Lankhorst73974892016-08-05 23:28:27 +030016246 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010016247 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030016248
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053016249 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016250 drm_modeset_drop_locks(&ctx);
16251 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020016252
Chris Wilson08536952016-10-14 13:18:18 +010016253 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010016254 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000016255 if (state)
16256 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010016257}
16258
Manasi Navare886c6b82017-10-26 14:52:00 -070016259static void intel_hpd_poll_fini(struct drm_device *dev)
16260{
16261 struct intel_connector *connector;
16262 struct drm_connector_list_iter conn_iter;
16263
Chris Wilson448aa912017-11-28 11:01:47 +000016264 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070016265 drm_connector_list_iter_begin(dev, &conn_iter);
16266 for_each_intel_connector_iter(connector, &conn_iter) {
16267 if (connector->modeset_retry_work.func)
16268 cancel_work_sync(&connector->modeset_retry_work);
Ramalingam Cd3dacc72018-10-29 15:15:46 +053016269 if (connector->hdcp.shim) {
16270 cancel_delayed_work_sync(&connector->hdcp.check_work);
16271 cancel_work_sync(&connector->hdcp.prop_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050016272 }
Manasi Navare886c6b82017-10-26 14:52:00 -070016273 }
16274 drm_connector_list_iter_end(&conn_iter);
16275}
16276
Jesse Barnes79e53942008-11-07 14:24:08 -080016277void intel_modeset_cleanup(struct drm_device *dev)
16278{
Chris Wilsonfac5e232016-07-04 11:34:36 +010016279 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070016280
Chris Wilson8bcf9f72018-07-10 10:44:20 +010016281 flush_workqueue(dev_priv->modeset_wq);
16282
Chris Wilsoneb955ee2017-01-23 21:29:39 +000016283 flush_work(&dev_priv->atomic_helper.free_work);
16284 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
16285
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016286 /*
16287 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020016288 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016289 * experience fancy races otherwise.
16290 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020016291 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070016292
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016293 /*
16294 * Due to the hpd irq storm handling the hotplug work can re-arm the
16295 * poll handlers. Hence disable polling after hpd handling is shut down.
16296 */
Manasi Navare886c6b82017-10-26 14:52:00 -070016297 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020016298
Daniel Vetter4f256d82017-07-15 00:46:55 +020016299 /* poll work can call into fbdev, hence clean that up afterwards */
16300 intel_fbdev_fini(dev_priv);
16301
Jesse Barnes723bfd72010-10-07 16:01:13 -070016302 intel_unregister_dsm_handler();
16303
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020016304 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050016305
Chris Wilson1630fe72011-07-08 12:22:42 +010016306 /* flush any delayed tasks or pending work */
16307 flush_scheduled_work();
16308
Jesse Barnes79e53942008-11-07 14:24:08 -080016309 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010016310
José Roberto de Souza58db08a72018-11-07 16:16:47 -080016311 intel_overlay_cleanup(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030016312
Tvrtko Ursulin40196442016-12-01 14:16:42 +000016313 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020016314
16315 destroy_workqueue(dev_priv->modeset_wq);
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080016316
16317 intel_fbc_cleanup_cfb(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080016318}
16319
Dave Airlie28d52042009-09-21 14:33:58 +100016320/*
16321 * set vga decode state - true == enable VGA decode
16322 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000016323int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100016324{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000016325 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100016326 u16 gmch_ctrl;
16327
Chris Wilson75fa0412014-02-07 18:37:02 -020016328 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
16329 DRM_ERROR("failed to read control word\n");
16330 return -EIO;
16331 }
16332
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020016333 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
16334 return 0;
16335
Dave Airlie28d52042009-09-21 14:33:58 +100016336 if (state)
16337 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
16338 else
16339 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020016340
16341 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
16342 DRM_ERROR("failed to write control word\n");
16343 return -EIO;
16344 }
16345
Dave Airlie28d52042009-09-21 14:33:58 +100016346 return 0;
16347}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016348
Chris Wilson98a2f412016-10-12 10:05:18 +010016349#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
16350
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016351struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016352
16353 u32 power_well_driver;
16354
Chris Wilson63b66e52013-08-08 15:12:06 +020016355 int num_transcoders;
16356
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016357 struct intel_cursor_error_state {
16358 u32 control;
16359 u32 position;
16360 u32 base;
16361 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010016362 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016363
16364 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016365 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016366 u32 source;
Imre Deakf301b1e2014-04-18 15:55:04 +030016367 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010016368 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016369
16370 struct intel_plane_error_state {
16371 u32 control;
16372 u32 stride;
16373 u32 size;
16374 u32 pos;
16375 u32 addr;
16376 u32 surface;
16377 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010016378 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020016379
16380 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016381 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020016382 enum transcoder cpu_transcoder;
16383
16384 u32 conf;
16385
16386 u32 htotal;
16387 u32 hblank;
16388 u32 hsync;
16389 u32 vtotal;
16390 u32 vblank;
16391 u32 vsync;
16392 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016393};
16394
16395struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010016396intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016397{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016398 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020016399 int transcoders[] = {
16400 TRANSCODER_A,
16401 TRANSCODER_B,
16402 TRANSCODER_C,
16403 TRANSCODER_EDP,
16404 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016405 int i;
16406
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080016407 if (!HAS_DISPLAY(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016408 return NULL;
16409
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016410 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016411 if (error == NULL)
16412 return NULL;
16413
Chris Wilsonc0336662016-05-06 15:40:21 +010016414 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030016415 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016416
Damien Lespiau055e3932014-08-18 13:49:10 +010016417 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020016418 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016419 __intel_display_power_is_enabled(dev_priv,
16420 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020016421 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016422 continue;
16423
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030016424 error->cursor[i].control = I915_READ(CURCNTR(i));
16425 error->cursor[i].position = I915_READ(CURPOS(i));
16426 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016427
16428 error->plane[i].control = I915_READ(DSPCNTR(i));
16429 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016430 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030016431 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016432 error->plane[i].pos = I915_READ(DSPPOS(i));
16433 }
Chris Wilsonc0336662016-05-06 15:40:21 +010016434 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030016435 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016436 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016437 error->plane[i].surface = I915_READ(DSPSURF(i));
16438 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16439 }
16440
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016441 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e2014-04-18 15:55:04 +030016442
Rodrigo Vivib2ae3182019-02-04 14:25:38 -080016443 if (HAS_GMCH(dev_priv))
Imre Deakf301b1e2014-04-18 15:55:04 +030016444 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020016445 }
16446
Jani Nikula4d1de972016-03-18 17:05:42 +020016447 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010016448 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030016449 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016450 error->num_transcoders++; /* Account for eDP. */
16451
16452 for (i = 0; i < error->num_transcoders; i++) {
16453 enum transcoder cpu_transcoder = transcoders[i];
16454
Imre Deakddf9c532013-11-27 22:02:02 +020016455 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016456 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020016457 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016458 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016459 continue;
16460
Chris Wilson63b66e52013-08-08 15:12:06 +020016461 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16462
16463 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16464 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16465 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16466 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16467 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16468 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16469 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016470 }
16471
16472 return error;
16473}
16474
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016475#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16476
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016477void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016478intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016479 struct intel_display_error_state *error)
16480{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000016481 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016482 int i;
16483
Chris Wilson63b66e52013-08-08 15:12:06 +020016484 if (!error)
16485 return;
16486
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000016487 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010016488 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016489 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016490 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010016491 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016492 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020016493 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016494 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016495 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e2014-04-18 15:55:04 +030016496 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016497
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016498 err_printf(m, "Plane [%d]:\n", i);
16499 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16500 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016501 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016502 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16503 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016504 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016505 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016506 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016507 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016508 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16509 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016510 }
16511
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016512 err_printf(m, "Cursor [%d]:\n", i);
16513 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16514 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16515 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016516 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016517
16518 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016519 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016520 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016521 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016522 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016523 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16524 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16525 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16526 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16527 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16528 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16529 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16530 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016531}
Chris Wilson98a2f412016-10-12 10:05:18 +010016532
16533#endif