blob: 3b7094822aa973beff8165a7f3851fd07e5b752e [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006-2007 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 */
26
Jesse Barnesc1c7af62009-09-10 15:28:03 -070027#include <linux/module.h>
28#include <linux/input.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080029#include <linux/i2c.h>
Shaohua Li7662c8b2009-06-26 11:23:55 +080030#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Jesse Barnes9cce37f2010-08-13 15:11:26 -070032#include <linux/vgaarb.h>
Wu Fengguange0dac652011-09-05 14:25:34 +080033#include <drm/drm_edid.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080035#include "intel_drv.h"
Chris Wilson5d723d72016-08-04 16:32:35 +010036#include "intel_frontbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/i915_drm.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "i915_drv.h"
Chris Wilson57822dc2017-02-22 11:40:48 +000039#include "i915_gem_clflush.h"
Imre Deakdb18b6a2016-03-24 12:41:40 +020040#include "intel_dsi.h"
Jesse Barnese5510fa2010-07-01 16:48:37 -070041#include "i915_trace.h"
Xi Ruoyao319c1d42015-03-12 20:16:32 +080042#include <drm/drm_atomic.h>
Matt Roperc196e1d2015-01-21 16:35:48 -080043#include <drm/drm_atomic_helper.h>
David Howells760285e2012-10-02 18:01:07 +010044#include <drm/drm_dp_helper.h>
45#include <drm/drm_crtc_helper.h>
Matt Roper465c1202014-05-29 08:06:54 -070046#include <drm/drm_plane_helper.h>
47#include <drm/drm_rect.h>
Daniel Vetter72fdb40c2018-09-05 15:57:11 +020048#include <drm/drm_atomic_uapi.h>
Keith Packardc0f372b32011-11-16 22:24:52 -080049#include <linux/dma_remapping.h>
Alex Goinsfd8e0582015-11-25 18:43:38 -080050#include <linux/reservation.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080051
Matt Roper465c1202014-05-29 08:06:54 -070052/* Primary plane formats for gen <= 3 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010053static const uint32_t i8xx_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010054 DRM_FORMAT_C8,
55 DRM_FORMAT_RGB565,
Matt Roper465c1202014-05-29 08:06:54 -070056 DRM_FORMAT_XRGB1555,
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010057 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070058};
59
60/* Primary plane formats for gen >= 4 */
Damien Lespiau568db4f2015-05-12 16:13:18 +010061static const uint32_t i965_primary_formats[] = {
Damien Lespiau67fe7dc2015-05-15 19:06:00 +010062 DRM_FORMAT_C8,
63 DRM_FORMAT_RGB565,
64 DRM_FORMAT_XRGB8888,
Matt Roper465c1202014-05-29 08:06:54 -070065 DRM_FORMAT_XBGR8888,
Damien Lespiau6c0fd452015-05-19 12:29:16 +010066 DRM_FORMAT_XRGB2101010,
67 DRM_FORMAT_XBGR2101010,
68};
69
Ben Widawsky714244e2017-08-01 09:58:16 -070070static const uint64_t i9xx_format_modifiers[] = {
71 I915_FORMAT_MOD_X_TILED,
72 DRM_FORMAT_MOD_LINEAR,
73 DRM_FORMAT_MOD_INVALID
74};
75
Matt Roper3d7d6512014-06-10 08:28:13 -070076/* Cursor formats */
77static const uint32_t intel_cursor_formats[] = {
78 DRM_FORMAT_ARGB8888,
79};
80
Ben Widawsky714244e2017-08-01 09:58:16 -070081static const uint64_t cursor_format_modifiers[] = {
82 DRM_FORMAT_MOD_LINEAR,
83 DRM_FORMAT_MOD_INVALID
84};
85
Jesse Barnesf1f644d2013-06-27 00:39:25 +030086static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020087 struct intel_crtc_state *pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +030088static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020089 struct intel_crtc_state *pipe_config);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030090
Chris Wilson24dbf512017-02-15 10:59:18 +000091static int intel_framebuffer_init(struct intel_framebuffer *ifb,
92 struct drm_i915_gem_object *obj,
93 struct drm_mode_fb_cmd2 *mode_cmd);
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +020094static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state);
95static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state);
Maarten Lankhorst4c354752018-10-11 12:04:49 +020096static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
97 const struct intel_link_m_n *m_n,
98 const struct intel_link_m_n *m2_n2);
Maarten Lankhorstfdf73512018-10-04 11:45:52 +020099static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state);
100static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state);
101static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state);
102static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200103static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200104 const struct intel_crtc_state *pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +0200105static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +0200106 const struct intel_crtc_state *pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200107static void intel_begin_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
108static void intel_finish_crtc_commit(struct drm_crtc *, struct drm_crtc_state *);
Nabendu Maiti1c74eea2016-11-29 11:23:14 +0530109static void intel_crtc_init_scalers(struct intel_crtc *crtc,
110 struct intel_crtc_state *crtc_state);
Maarten Lankhorstb2562712018-10-04 11:45:53 +0200111static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state);
112static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state);
113static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +0300114static void intel_modeset_setup_hw_state(struct drm_device *dev,
115 struct drm_modeset_acquire_ctx *ctx);
Ville Syrjälä2622a082016-03-09 19:07:26 +0200116static void intel_pre_disable_primary_noatomic(struct drm_crtc *crtc);
Damien Lespiaue7457a92013-08-08 22:28:59 +0100117
Ma Lingd4906092009-03-18 20:13:27 +0800118struct intel_limit {
Ander Conselvan de Oliveira4c5def92016-05-04 12:11:58 +0300119 struct {
120 int min, max;
121 } dot, vco, n, m, m1, m2, p, p1;
122
123 struct {
124 int dot_limit;
125 int p2_slow, p2_fast;
126 } p2;
Ma Lingd4906092009-03-18 20:13:27 +0800127};
Jesse Barnes79e53942008-11-07 14:24:08 -0800128
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300129/* returns HPLL frequency in kHz */
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200130int vlv_get_hpll_vco(struct drm_i915_private *dev_priv)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300131{
132 int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 };
133
134 /* Obtain SKU information */
135 mutex_lock(&dev_priv->sb_lock);
136 hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) &
137 CCK_FUSE_HPLL_FREQ_MASK;
138 mutex_unlock(&dev_priv->sb_lock);
139
140 return vco_freq[hpll_freq] * 1000;
141}
142
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200143int vlv_get_cck_clock(struct drm_i915_private *dev_priv,
144 const char *name, u32 reg, int ref_freq)
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300145{
146 u32 val;
147 int divider;
148
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300149 mutex_lock(&dev_priv->sb_lock);
150 val = vlv_cck_read(dev_priv, reg);
151 mutex_unlock(&dev_priv->sb_lock);
152
153 divider = val & CCK_FREQUENCY_VALUES;
154
155 WARN((val & CCK_FREQUENCY_STATUS) !=
156 (divider << CCK_FREQUENCY_STATUS_SHIFT),
157 "%s change in progress\n", name);
158
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200159 return DIV_ROUND_CLOSEST(ref_freq << 1, divider + 1);
160}
161
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +0200162int vlv_get_cck_clock_hpll(struct drm_i915_private *dev_priv,
163 const char *name, u32 reg)
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200164{
165 if (dev_priv->hpll_freq == 0)
Ville Syrjälä49cd97a2017-02-07 20:33:45 +0200166 dev_priv->hpll_freq = vlv_get_hpll_vco(dev_priv);
Ville Syrjäläc30fec62016-03-04 21:43:02 +0200167
168 return vlv_get_cck_clock(dev_priv, name, reg,
169 dev_priv->hpll_freq);
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300170}
171
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300172static void intel_update_czclk(struct drm_i915_private *dev_priv)
173{
Wayne Boyer666a4532015-12-09 12:29:35 -0800174 if (!(IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)))
Ville Syrjäläbfa7df02015-09-24 23:29:18 +0300175 return;
176
177 dev_priv->czclk_freq = vlv_get_cck_clock_hpll(dev_priv, "czclk",
178 CCK_CZ_CLOCK_CONTROL);
179
180 DRM_DEBUG_DRIVER("CZ clock rate: %d kHz\n", dev_priv->czclk_freq);
181}
182
Chris Wilson021357a2010-09-07 20:54:59 +0100183static inline u32 /* units of 100MHz */
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200184intel_fdi_link_freq(struct drm_i915_private *dev_priv,
185 const struct intel_crtc_state *pipe_config)
Chris Wilson021357a2010-09-07 20:54:59 +0100186{
Ville Syrjälä21a727b2016-02-17 21:41:10 +0200187 if (HAS_DDI(dev_priv))
188 return pipe_config->port_clock; /* SPLL */
Ville Syrjäläe3b247d2016-02-17 21:41:09 +0200189 else
Chris Wilson58ecd9d2017-11-05 13:49:05 +0000190 return dev_priv->fdi_pll_freq;
Chris Wilson021357a2010-09-07 20:54:59 +0100191}
192
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300193static const struct intel_limit intel_limits_i8xx_dac = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400194 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200195 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200196 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400197 .m = { .min = 96, .max = 140 },
198 .m1 = { .min = 18, .max = 26 },
199 .m2 = { .min = 6, .max = 16 },
200 .p = { .min = 4, .max = 128 },
201 .p1 = { .min = 2, .max = 33 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700202 .p2 = { .dot_limit = 165000,
203 .p2_slow = 4, .p2_fast = 2 },
Keith Packarde4b36692009-06-05 19:22:17 -0700204};
205
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300206static const struct intel_limit intel_limits_i8xx_dvo = {
Daniel Vetter5d536e22013-07-06 12:52:06 +0200207 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200208 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200209 .n = { .min = 2, .max = 16 },
Daniel Vetter5d536e22013-07-06 12:52:06 +0200210 .m = { .min = 96, .max = 140 },
211 .m1 = { .min = 18, .max = 26 },
212 .m2 = { .min = 6, .max = 16 },
213 .p = { .min = 4, .max = 128 },
214 .p1 = { .min = 2, .max = 33 },
215 .p2 = { .dot_limit = 165000,
216 .p2_slow = 4, .p2_fast = 4 },
217};
218
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300219static const struct intel_limit intel_limits_i8xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400220 .dot = { .min = 25000, .max = 350000 },
Ville Syrjälä9c333712013-12-09 18:54:17 +0200221 .vco = { .min = 908000, .max = 1512000 },
Ville Syrjälä91dbe5f2013-12-09 18:54:14 +0200222 .n = { .min = 2, .max = 16 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400223 .m = { .min = 96, .max = 140 },
224 .m1 = { .min = 18, .max = 26 },
225 .m2 = { .min = 6, .max = 16 },
226 .p = { .min = 4, .max = 128 },
227 .p1 = { .min = 1, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700228 .p2 = { .dot_limit = 165000,
229 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700230};
Eric Anholt273e27c2011-03-30 13:01:10 -0700231
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300232static const struct intel_limit intel_limits_i9xx_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400233 .dot = { .min = 20000, .max = 400000 },
234 .vco = { .min = 1400000, .max = 2800000 },
235 .n = { .min = 1, .max = 6 },
236 .m = { .min = 70, .max = 120 },
Patrik Jakobsson4f7dfb62013-02-13 22:20:22 +0100237 .m1 = { .min = 8, .max = 18 },
238 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400239 .p = { .min = 5, .max = 80 },
240 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700241 .p2 = { .dot_limit = 200000,
242 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700243};
244
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300245static const struct intel_limit intel_limits_i9xx_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400246 .dot = { .min = 20000, .max = 400000 },
247 .vco = { .min = 1400000, .max = 2800000 },
248 .n = { .min = 1, .max = 6 },
249 .m = { .min = 70, .max = 120 },
Patrik Jakobsson53a7d2d2013-02-13 22:20:21 +0100250 .m1 = { .min = 8, .max = 18 },
251 .m2 = { .min = 3, .max = 7 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400252 .p = { .min = 7, .max = 98 },
253 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700254 .p2 = { .dot_limit = 112000,
255 .p2_slow = 14, .p2_fast = 7 },
Keith Packarde4b36692009-06-05 19:22:17 -0700256};
257
Eric Anholt273e27c2011-03-30 13:01:10 -0700258
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300259static const struct intel_limit intel_limits_g4x_sdvo = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700260 .dot = { .min = 25000, .max = 270000 },
261 .vco = { .min = 1750000, .max = 3500000},
262 .n = { .min = 1, .max = 4 },
263 .m = { .min = 104, .max = 138 },
264 .m1 = { .min = 17, .max = 23 },
265 .m2 = { .min = 5, .max = 11 },
266 .p = { .min = 10, .max = 30 },
267 .p1 = { .min = 1, .max = 3},
268 .p2 = { .dot_limit = 270000,
269 .p2_slow = 10,
270 .p2_fast = 10
Ma Ling044c7c42009-03-18 20:13:23 +0800271 },
Keith Packarde4b36692009-06-05 19:22:17 -0700272};
273
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300274static const struct intel_limit intel_limits_g4x_hdmi = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700275 .dot = { .min = 22000, .max = 400000 },
276 .vco = { .min = 1750000, .max = 3500000},
277 .n = { .min = 1, .max = 4 },
278 .m = { .min = 104, .max = 138 },
279 .m1 = { .min = 16, .max = 23 },
280 .m2 = { .min = 5, .max = 11 },
281 .p = { .min = 5, .max = 80 },
282 .p1 = { .min = 1, .max = 8},
283 .p2 = { .dot_limit = 165000,
284 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700285};
286
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300287static const struct intel_limit intel_limits_g4x_single_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700288 .dot = { .min = 20000, .max = 115000 },
289 .vco = { .min = 1750000, .max = 3500000 },
290 .n = { .min = 1, .max = 3 },
291 .m = { .min = 104, .max = 138 },
292 .m1 = { .min = 17, .max = 23 },
293 .m2 = { .min = 5, .max = 11 },
294 .p = { .min = 28, .max = 112 },
295 .p1 = { .min = 2, .max = 8 },
296 .p2 = { .dot_limit = 0,
297 .p2_slow = 14, .p2_fast = 14
Ma Ling044c7c42009-03-18 20:13:23 +0800298 },
Keith Packarde4b36692009-06-05 19:22:17 -0700299};
300
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300301static const struct intel_limit intel_limits_g4x_dual_channel_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700302 .dot = { .min = 80000, .max = 224000 },
303 .vco = { .min = 1750000, .max = 3500000 },
304 .n = { .min = 1, .max = 3 },
305 .m = { .min = 104, .max = 138 },
306 .m1 = { .min = 17, .max = 23 },
307 .m2 = { .min = 5, .max = 11 },
308 .p = { .min = 14, .max = 42 },
309 .p1 = { .min = 2, .max = 6 },
310 .p2 = { .dot_limit = 0,
311 .p2_slow = 7, .p2_fast = 7
Ma Ling044c7c42009-03-18 20:13:23 +0800312 },
Keith Packarde4b36692009-06-05 19:22:17 -0700313};
314
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300315static const struct intel_limit intel_limits_pineview_sdvo = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400316 .dot = { .min = 20000, .max = 400000},
317 .vco = { .min = 1700000, .max = 3500000 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700318 /* Pineview's Ncounter is a ring counter */
Akshay Joshi0206e352011-08-16 15:34:10 -0400319 .n = { .min = 3, .max = 6 },
320 .m = { .min = 2, .max = 256 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700321 /* Pineview only has one combined m divider, which we treat as m2. */
Akshay Joshi0206e352011-08-16 15:34:10 -0400322 .m1 = { .min = 0, .max = 0 },
323 .m2 = { .min = 0, .max = 254 },
324 .p = { .min = 5, .max = 80 },
325 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700326 .p2 = { .dot_limit = 200000,
327 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700328};
329
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300330static const struct intel_limit intel_limits_pineview_lvds = {
Akshay Joshi0206e352011-08-16 15:34:10 -0400331 .dot = { .min = 20000, .max = 400000 },
332 .vco = { .min = 1700000, .max = 3500000 },
333 .n = { .min = 3, .max = 6 },
334 .m = { .min = 2, .max = 256 },
335 .m1 = { .min = 0, .max = 0 },
336 .m2 = { .min = 0, .max = 254 },
337 .p = { .min = 7, .max = 112 },
338 .p1 = { .min = 1, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700339 .p2 = { .dot_limit = 112000,
340 .p2_slow = 14, .p2_fast = 14 },
Keith Packarde4b36692009-06-05 19:22:17 -0700341};
342
Eric Anholt273e27c2011-03-30 13:01:10 -0700343/* Ironlake / Sandybridge
344 *
345 * We calculate clock using (register_value + 2) for N/M1/M2, so here
346 * the range value for them is (actual_value - 2).
347 */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300348static const struct intel_limit intel_limits_ironlake_dac = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700349 .dot = { .min = 25000, .max = 350000 },
350 .vco = { .min = 1760000, .max = 3510000 },
351 .n = { .min = 1, .max = 5 },
352 .m = { .min = 79, .max = 127 },
353 .m1 = { .min = 12, .max = 22 },
354 .m2 = { .min = 5, .max = 9 },
355 .p = { .min = 5, .max = 80 },
356 .p1 = { .min = 1, .max = 8 },
357 .p2 = { .dot_limit = 225000,
358 .p2_slow = 10, .p2_fast = 5 },
Keith Packarde4b36692009-06-05 19:22:17 -0700359};
360
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300361static const struct intel_limit intel_limits_ironlake_single_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700362 .dot = { .min = 25000, .max = 350000 },
363 .vco = { .min = 1760000, .max = 3510000 },
364 .n = { .min = 1, .max = 3 },
365 .m = { .min = 79, .max = 118 },
366 .m1 = { .min = 12, .max = 22 },
367 .m2 = { .min = 5, .max = 9 },
368 .p = { .min = 28, .max = 112 },
369 .p1 = { .min = 2, .max = 8 },
370 .p2 = { .dot_limit = 225000,
371 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800372};
373
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300374static const struct intel_limit intel_limits_ironlake_dual_lvds = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700375 .dot = { .min = 25000, .max = 350000 },
376 .vco = { .min = 1760000, .max = 3510000 },
377 .n = { .min = 1, .max = 3 },
378 .m = { .min = 79, .max = 127 },
379 .m1 = { .min = 12, .max = 22 },
380 .m2 = { .min = 5, .max = 9 },
381 .p = { .min = 14, .max = 56 },
382 .p1 = { .min = 2, .max = 8 },
383 .p2 = { .dot_limit = 225000,
384 .p2_slow = 7, .p2_fast = 7 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800385};
386
Eric Anholt273e27c2011-03-30 13:01:10 -0700387/* LVDS 100mhz refclk limits. */
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300388static const struct intel_limit intel_limits_ironlake_single_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700389 .dot = { .min = 25000, .max = 350000 },
390 .vco = { .min = 1760000, .max = 3510000 },
391 .n = { .min = 1, .max = 2 },
392 .m = { .min = 79, .max = 126 },
393 .m1 = { .min = 12, .max = 22 },
394 .m2 = { .min = 5, .max = 9 },
395 .p = { .min = 28, .max = 112 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400396 .p1 = { .min = 2, .max = 8 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700397 .p2 = { .dot_limit = 225000,
398 .p2_slow = 14, .p2_fast = 14 },
Zhenyu Wangb91ad0e2010-02-05 09:14:17 +0800399};
400
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300401static const struct intel_limit intel_limits_ironlake_dual_lvds_100m = {
Eric Anholt273e27c2011-03-30 13:01:10 -0700402 .dot = { .min = 25000, .max = 350000 },
403 .vco = { .min = 1760000, .max = 3510000 },
404 .n = { .min = 1, .max = 3 },
405 .m = { .min = 79, .max = 126 },
406 .m1 = { .min = 12, .max = 22 },
407 .m2 = { .min = 5, .max = 9 },
408 .p = { .min = 14, .max = 42 },
Akshay Joshi0206e352011-08-16 15:34:10 -0400409 .p1 = { .min = 2, .max = 6 },
Eric Anholt273e27c2011-03-30 13:01:10 -0700410 .p2 = { .dot_limit = 225000,
411 .p2_slow = 7, .p2_fast = 7 },
Zhao Yakui45476682009-12-31 16:06:04 +0800412};
413
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300414static const struct intel_limit intel_limits_vlv = {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300415 /*
416 * These are the data rate limits (measured in fast clocks)
417 * since those are the strictest limits we have. The fast
418 * clock and actual rate limits are more relaxed, so checking
419 * them would make no difference.
420 */
421 .dot = { .min = 25000 * 5, .max = 270000 * 5 },
Daniel Vetter75e53982013-04-18 21:10:43 +0200422 .vco = { .min = 4000000, .max = 6000000 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700423 .n = { .min = 1, .max = 7 },
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700424 .m1 = { .min = 2, .max = 3 },
425 .m2 = { .min = 11, .max = 156 },
Ville Syrjäläb99ab662013-09-24 21:26:26 +0300426 .p1 = { .min = 2, .max = 3 },
Ville Syrjälä5fdc9c492013-09-24 21:26:29 +0300427 .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700428};
429
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300430static const struct intel_limit intel_limits_chv = {
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300431 /*
432 * These are the data rate limits (measured in fast clocks)
433 * since those are the strictest limits we have. The fast
434 * clock and actual rate limits are more relaxed, so checking
435 * them would make no difference.
436 */
437 .dot = { .min = 25000 * 5, .max = 540000 * 5},
Ville Syrjälä17fe1022015-02-26 21:01:52 +0200438 .vco = { .min = 4800000, .max = 6480000 },
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300439 .n = { .min = 1, .max = 1 },
440 .m1 = { .min = 2, .max = 2 },
441 .m2 = { .min = 24 << 22, .max = 175 << 22 },
442 .p1 = { .min = 2, .max = 4 },
443 .p2 = { .p2_slow = 1, .p2_fast = 14 },
444};
445
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300446static const struct intel_limit intel_limits_bxt = {
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200447 /* FIXME: find real dot limits */
448 .dot = { .min = 0, .max = INT_MAX },
Vandana Kannane6292552015-07-01 17:02:57 +0530449 .vco = { .min = 4800000, .max = 6700000 },
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200450 .n = { .min = 1, .max = 1 },
451 .m1 = { .min = 2, .max = 2 },
452 /* FIXME: find real m2 limits */
453 .m2 = { .min = 2 << 22, .max = 255 << 22 },
454 .p1 = { .min = 2, .max = 4 },
455 .p2 = { .p2_slow = 1, .p2_fast = 20 },
456};
457
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530458static void
459skl_wa_clkgate(struct drm_i915_private *dev_priv, int pipe, bool enable)
460{
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +0530461 if (enable)
462 I915_WRITE(CLKGATE_DIS_PSL(pipe),
463 DUPS1_GATING_DIS | DUPS2_GATING_DIS);
464 else
465 I915_WRITE(CLKGATE_DIS_PSL(pipe),
466 I915_READ(CLKGATE_DIS_PSL(pipe)) &
467 ~(DUPS1_GATING_DIS | DUPS2_GATING_DIS));
468}
469
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200470static bool
Maarten Lankhorst24f28452017-11-22 19:39:01 +0100471needs_modeset(const struct drm_crtc_state *state)
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200472{
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200473 return drm_atomic_crtc_needs_modeset(state);
Ander Conselvan de Oliveiracdba9542015-06-01 12:49:51 +0200474}
475
Imre Deakdccbea32015-06-22 23:35:51 +0300476/*
477 * Platform specific helpers to calculate the port PLL loopback- (clock.m),
478 * and post-divider (clock.p) values, pre- (clock.vco) and post-divided fast
479 * (clock.dot) clock rates. This fast dot clock is fed to the port's IO logic.
480 * The helpers' return value is the rate of the clock that is fed to the
481 * display engine's pipe which can be the above fast dot clock rate or a
482 * divided-down version of it.
483 */
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500484/* m1 is reserved as 0 in Pineview, n is a ring counter */
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300485static int pnv_calc_dpll_params(int refclk, struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800486{
Shaohua Li21778322009-02-23 15:19:16 +0800487 clock->m = clock->m2 + 2;
488 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200489 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300490 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300491 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
492 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300493
494 return clock->dot;
Shaohua Li21778322009-02-23 15:19:16 +0800495}
496
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200497static uint32_t i9xx_dpll_compute_m(struct dpll *dpll)
498{
499 return 5 * (dpll->m1 + 2) + (dpll->m2 + 2);
500}
501
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300502static int i9xx_calc_dpll_params(int refclk, struct dpll *clock)
Shaohua Li21778322009-02-23 15:19:16 +0800503{
Daniel Vetter7429e9d2013-04-20 17:19:46 +0200504 clock->m = i9xx_dpll_compute_m(clock);
Jesse Barnes79e53942008-11-07 14:24:08 -0800505 clock->p = clock->p1 * clock->p2;
Ville Syrjäläed5ca772013-12-02 19:00:45 +0200506 if (WARN_ON(clock->n + 2 == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300507 return 0;
Ville Syrjäläfb03ac02013-10-14 14:50:30 +0300508 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2);
509 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300510
511 return clock->dot;
Jesse Barnes79e53942008-11-07 14:24:08 -0800512}
513
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300514static int vlv_calc_dpll_params(int refclk, struct dpll *clock)
Imre Deak589eca62015-06-22 23:35:50 +0300515{
516 clock->m = clock->m1 * clock->m2;
517 clock->p = clock->p1 * clock->p2;
518 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300519 return 0;
Imre Deak589eca62015-06-22 23:35:50 +0300520 clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n);
521 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300522
523 return clock->dot / 5;
Imre Deak589eca62015-06-22 23:35:50 +0300524}
525
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300526int chv_calc_dpll_params(int refclk, struct dpll *clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300527{
528 clock->m = clock->m1 * clock->m2;
529 clock->p = clock->p1 * clock->p2;
530 if (WARN_ON(clock->n == 0 || clock->p == 0))
Imre Deakdccbea32015-06-22 23:35:51 +0300531 return 0;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300532 clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m,
533 clock->n << 22);
534 clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p);
Imre Deakdccbea32015-06-22 23:35:51 +0300535
536 return clock->dot / 5;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300537}
538
Jesse Barnes7c04d1d2009-02-23 15:36:40 -0800539#define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
Chris Wilsonc38c1452018-02-14 13:49:22 +0000540
541/*
Jesse Barnes79e53942008-11-07 14:24:08 -0800542 * Returns whether the given set of divisors are valid for a given refclk with
543 * the given connectors.
544 */
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100545static bool intel_PLL_is_valid(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300546 const struct intel_limit *limit,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300547 const struct dpll *clock)
Jesse Barnes79e53942008-11-07 14:24:08 -0800548{
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300549 if (clock->n < limit->n.min || limit->n.max < clock->n)
550 INTELPllInvalid("n out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800551 if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400552 INTELPllInvalid("p1 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800553 if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
Akshay Joshi0206e352011-08-16 15:34:10 -0400554 INTELPllInvalid("m2 out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800555 if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
Akshay Joshi0206e352011-08-16 15:34:10 -0400556 INTELPllInvalid("m1 out of range\n");
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300557
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100558 if (!IS_PINEVIEW(dev_priv) && !IS_VALLEYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200559 !IS_CHERRYVIEW(dev_priv) && !IS_GEN9_LP(dev_priv))
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300560 if (clock->m1 <= clock->m2)
561 INTELPllInvalid("m1 <= m2\n");
562
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100563 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv) &&
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +0200564 !IS_GEN9_LP(dev_priv)) {
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300565 if (clock->p < limit->p.min || limit->p.max < clock->p)
566 INTELPllInvalid("p out of range\n");
567 if (clock->m < limit->m.min || limit->m.max < clock->m)
568 INTELPllInvalid("m out of range\n");
569 }
570
Jesse Barnes79e53942008-11-07 14:24:08 -0800571 if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
Akshay Joshi0206e352011-08-16 15:34:10 -0400572 INTELPllInvalid("vco out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800573 /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
574 * connector, etc., rather than just a single range.
575 */
576 if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
Akshay Joshi0206e352011-08-16 15:34:10 -0400577 INTELPllInvalid("dot out of range\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800578
579 return true;
580}
581
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300582static int
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300583i9xx_select_p2_div(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300584 const struct intel_crtc_state *crtc_state,
585 int target)
Jesse Barnes79e53942008-11-07 14:24:08 -0800586{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300587 struct drm_device *dev = crtc_state->base.crtc->dev;
Jesse Barnes79e53942008-11-07 14:24:08 -0800588
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +0300589 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800590 /*
Daniel Vettera210b022012-11-26 17:22:08 +0100591 * For LVDS just rely on its current settings for dual-channel.
592 * We haven't figured out how to reliably set up different
593 * single/dual channel state, if we even can.
Jesse Barnes79e53942008-11-07 14:24:08 -0800594 */
Daniel Vetter1974cad2012-11-26 17:22:09 +0100595 if (intel_is_dual_link_lvds(dev))
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300596 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800597 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300598 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800599 } else {
600 if (target < limit->p2.dot_limit)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300601 return limit->p2.p2_slow;
Jesse Barnes79e53942008-11-07 14:24:08 -0800602 else
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300603 return limit->p2.p2_fast;
Jesse Barnes79e53942008-11-07 14:24:08 -0800604 }
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300605}
606
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200607/*
608 * Returns a set of divisors for the desired target clock with the given
609 * refclk, or FALSE. The returned values represent the clock equation:
610 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
611 *
612 * Target and reference clocks are specified in kHz.
613 *
614 * If match_clock is provided, then best_clock P divider must match the P
615 * divider from @match_clock used for LVDS downclocking.
616 */
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300617static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300618i9xx_find_best_dpll(const struct intel_limit *limit,
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300619 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300620 int target, int refclk, struct dpll *match_clock,
621 struct dpll *best_clock)
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300622{
623 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300624 struct dpll clock;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300625 int err = target;
Jesse Barnes79e53942008-11-07 14:24:08 -0800626
Akshay Joshi0206e352011-08-16 15:34:10 -0400627 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnes79e53942008-11-07 14:24:08 -0800628
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300629 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
630
Zhao Yakui42158662009-11-20 11:24:18 +0800631 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
632 clock.m1++) {
633 for (clock.m2 = limit->m2.min;
634 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterc0efc382013-06-03 20:56:24 +0200635 if (clock.m2 >= clock.m1)
Zhao Yakui42158662009-11-20 11:24:18 +0800636 break;
637 for (clock.n = limit->n.min;
638 clock.n <= limit->n.max; clock.n++) {
639 for (clock.p1 = limit->p1.min;
640 clock.p1 <= limit->p1.max; clock.p1++) {
Jesse Barnes79e53942008-11-07 14:24:08 -0800641 int this_err;
642
Imre Deakdccbea32015-06-22 23:35:51 +0300643 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100644 if (!intel_PLL_is_valid(to_i915(dev),
645 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000646 &clock))
Jesse Barnes79e53942008-11-07 14:24:08 -0800647 continue;
Sean Paulcec2f352012-01-10 15:09:36 -0800648 if (match_clock &&
649 clock.p != match_clock->p)
650 continue;
Jesse Barnes79e53942008-11-07 14:24:08 -0800651
652 this_err = abs(clock.dot - target);
653 if (this_err < err) {
654 *best_clock = clock;
655 err = this_err;
656 }
657 }
658 }
659 }
660 }
661
662 return (err != target);
663}
664
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200665/*
666 * Returns a set of divisors for the desired target clock with the given
667 * refclk, or FALSE. The returned values represent the clock equation:
668 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
669 *
670 * Target and reference clocks are specified in kHz.
671 *
672 * If match_clock is provided, then best_clock P divider must match the P
673 * divider from @match_clock used for LVDS downclocking.
674 */
Ma Lingd4906092009-03-18 20:13:27 +0800675static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300676pnv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200677 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300678 int target, int refclk, struct dpll *match_clock,
679 struct dpll *best_clock)
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200680{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300681 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300682 struct dpll clock;
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200683 int err = target;
684
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200685 memset(best_clock, 0, sizeof(*best_clock));
686
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300687 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
688
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200689 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
690 clock.m1++) {
691 for (clock.m2 = limit->m2.min;
692 clock.m2 <= limit->m2.max; clock.m2++) {
Daniel Vetterac58c3f2013-06-01 17:16:17 +0200693 for (clock.n = limit->n.min;
694 clock.n <= limit->n.max; clock.n++) {
695 for (clock.p1 = limit->p1.min;
696 clock.p1 <= limit->p1.max; clock.p1++) {
697 int this_err;
698
Imre Deakdccbea32015-06-22 23:35:51 +0300699 pnv_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100700 if (!intel_PLL_is_valid(to_i915(dev),
701 limit,
Jesse Barnes79e53942008-11-07 14:24:08 -0800702 &clock))
703 continue;
704 if (match_clock &&
705 clock.p != match_clock->p)
706 continue;
707
708 this_err = abs(clock.dot - target);
709 if (this_err < err) {
710 *best_clock = clock;
711 err = this_err;
712 }
713 }
714 }
715 }
716 }
717
718 return (err != target);
719}
720
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200721/*
722 * Returns a set of divisors for the desired target clock with the given
723 * refclk, or FALSE. The returned values represent the clock equation:
724 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +0200725 *
726 * Target and reference clocks are specified in kHz.
727 *
728 * If match_clock is provided, then best_clock P divider must match the P
729 * divider from @match_clock used for LVDS downclocking.
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +0200730 */
Ma Lingd4906092009-03-18 20:13:27 +0800731static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300732g4x_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200733 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300734 int target, int refclk, struct dpll *match_clock,
735 struct dpll *best_clock)
Ma Lingd4906092009-03-18 20:13:27 +0800736{
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300737 struct drm_device *dev = crtc_state->base.crtc->dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300738 struct dpll clock;
Ma Lingd4906092009-03-18 20:13:27 +0800739 int max_n;
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300740 bool found = false;
Adam Jackson6ba770d2010-07-02 16:43:30 -0400741 /* approximately equals target * 0.00585 */
742 int err_most = (target >> 8) + (target >> 9);
Ma Lingd4906092009-03-18 20:13:27 +0800743
744 memset(best_clock, 0, sizeof(*best_clock));
Ville Syrjälä3b1429d2015-06-18 13:47:22 +0300745
746 clock.p2 = i9xx_select_p2_div(limit, crtc_state, target);
747
Ma Lingd4906092009-03-18 20:13:27 +0800748 max_n = limit->n.max;
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200749 /* based on hardware requirement, prefer smaller n to precision */
Ma Lingd4906092009-03-18 20:13:27 +0800750 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Gilles Espinassef77f13e2010-03-29 15:41:47 +0200751 /* based on hardware requirement, prefere larger m1,m2 */
Ma Lingd4906092009-03-18 20:13:27 +0800752 for (clock.m1 = limit->m1.max;
753 clock.m1 >= limit->m1.min; clock.m1--) {
754 for (clock.m2 = limit->m2.max;
755 clock.m2 >= limit->m2.min; clock.m2--) {
756 for (clock.p1 = limit->p1.max;
757 clock.p1 >= limit->p1.min; clock.p1--) {
758 int this_err;
759
Imre Deakdccbea32015-06-22 23:35:51 +0300760 i9xx_calc_dpll_params(refclk, &clock);
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100761 if (!intel_PLL_is_valid(to_i915(dev),
762 limit,
Chris Wilson1b894b52010-12-14 20:04:54 +0000763 &clock))
Ma Lingd4906092009-03-18 20:13:27 +0800764 continue;
Chris Wilson1b894b52010-12-14 20:04:54 +0000765
766 this_err = abs(clock.dot - target);
Ma Lingd4906092009-03-18 20:13:27 +0800767 if (this_err < err_most) {
768 *best_clock = clock;
769 err_most = this_err;
770 max_n = clock.n;
771 found = true;
772 }
773 }
774 }
775 }
776 }
Zhenyu Wang2c072452009-06-05 15:38:42 +0800777 return found;
778}
Ma Lingd4906092009-03-18 20:13:27 +0800779
Imre Deakd5dd62b2015-03-17 11:40:03 +0200780/*
781 * Check if the calculated PLL configuration is more optimal compared to the
782 * best configuration and error found so far. Return the calculated error.
783 */
784static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300785 const struct dpll *calculated_clock,
786 const struct dpll *best_clock,
Imre Deakd5dd62b2015-03-17 11:40:03 +0200787 unsigned int best_error_ppm,
788 unsigned int *error_ppm)
789{
Imre Deak9ca3ba02015-03-17 11:40:05 +0200790 /*
791 * For CHV ignore the error and consider only the P value.
792 * Prefer a bigger P value based on HW requirements.
793 */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +0100794 if (IS_CHERRYVIEW(to_i915(dev))) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200795 *error_ppm = 0;
796
797 return calculated_clock->p > best_clock->p;
798 }
799
Imre Deak24be4e42015-03-17 11:40:04 +0200800 if (WARN_ON_ONCE(!target_freq))
801 return false;
802
Imre Deakd5dd62b2015-03-17 11:40:03 +0200803 *error_ppm = div_u64(1000000ULL *
804 abs(target_freq - calculated_clock->dot),
805 target_freq);
806 /*
807 * Prefer a better P value over a better (smaller) error if the error
808 * is small. Ensure this preference for future configurations too by
809 * setting the error to 0.
810 */
811 if (*error_ppm < 100 && calculated_clock->p > best_clock->p) {
812 *error_ppm = 0;
813
814 return true;
815 }
816
817 return *error_ppm + 10 < best_error_ppm;
818}
819
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200820/*
821 * Returns a set of divisors for the desired target clock with the given
822 * refclk, or FALSE. The returned values represent the clock equation:
823 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
824 */
Zhenyu Wang2c072452009-06-05 15:38:42 +0800825static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300826vlv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200827 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300828 int target, int refclk, struct dpll *match_clock,
829 struct dpll *best_clock)
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700830{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200831 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300832 struct drm_device *dev = crtc->base.dev;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300833 struct dpll clock;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300834 unsigned int bestppm = 1000000;
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300835 /* min update 19.2 MHz */
836 int max_n = min(limit->n.max, refclk / 19200);
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300837 bool found = false;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700838
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300839 target *= 5; /* fast clock */
840
841 memset(best_clock, 0, sizeof(*best_clock));
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700842
843 /* based on hardware requirement, prefer smaller n to precision */
Ville Syrjälä27e639b2013-09-24 21:26:24 +0300844 for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
Ville Syrjälä811bbf02013-09-24 21:26:25 +0300845 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
Ville Syrjälä889059d2013-09-24 21:26:27 +0300846 for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow;
Ville Syrjäläc1a9ae42013-09-24 21:26:23 +0300847 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300848 clock.p = clock.p1 * clock.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700849 /* based on hardware requirement, prefer bigger m1,m2 values */
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300850 for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
Imre Deakd5dd62b2015-03-17 11:40:03 +0200851 unsigned int ppm;
Ville Syrjälä69e4f9002013-09-24 21:26:20 +0300852
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300853 clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n,
854 refclk * clock.m1);
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300855
Imre Deakdccbea32015-06-22 23:35:51 +0300856 vlv_calc_dpll_params(refclk, &clock);
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300857
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100858 if (!intel_PLL_is_valid(to_i915(dev),
859 limit,
Ville Syrjäläf01b7962013-09-27 16:55:49 +0300860 &clock))
Ville Syrjälä43b0ac52013-09-24 21:26:18 +0300861 continue;
862
Imre Deakd5dd62b2015-03-17 11:40:03 +0200863 if (!vlv_PLL_is_optimal(dev, target,
864 &clock,
865 best_clock,
866 bestppm, &ppm))
867 continue;
Ville Syrjälä6b4bf1c2013-09-27 16:54:19 +0300868
Imre Deakd5dd62b2015-03-17 11:40:03 +0200869 *best_clock = clock;
870 bestppm = ppm;
871 found = true;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700872 }
873 }
874 }
875 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700876
Ville Syrjälä49e497e2013-09-24 21:26:31 +0300877 return found;
Jesse Barnesa0c4da242012-06-15 11:55:13 -0700878}
Keith Packarda4fc5ed2009-04-07 16:16:42 -0700879
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200880/*
881 * Returns a set of divisors for the desired target clock with the given
882 * refclk, or FALSE. The returned values represent the clock equation:
883 * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
884 */
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300885static bool
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300886chv_find_best_dpll(const struct intel_limit *limit,
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200887 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300888 int target, int refclk, struct dpll *match_clock,
889 struct dpll *best_clock)
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300890{
Ander Conselvan de Oliveiraa93e2552015-03-20 16:18:17 +0200891 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveiraa919ff12014-10-20 13:46:43 +0300892 struct drm_device *dev = crtc->base.dev;
Imre Deak9ca3ba02015-03-17 11:40:05 +0200893 unsigned int best_error_ppm;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300894 struct dpll clock;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300895 uint64_t m2;
896 int found = false;
897
898 memset(best_clock, 0, sizeof(*best_clock));
Imre Deak9ca3ba02015-03-17 11:40:05 +0200899 best_error_ppm = 1000000;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300900
901 /*
902 * Based on hardware doc, the n always set to 1, and m1 always
903 * set to 2. If requires to support 200Mhz refclk, we need to
904 * revisit this because n may not 1 anymore.
905 */
906 clock.n = 1, clock.m1 = 2;
907 target *= 5; /* fast clock */
908
909 for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) {
910 for (clock.p2 = limit->p2.p2_fast;
911 clock.p2 >= limit->p2.p2_slow;
912 clock.p2 -= clock.p2 > 10 ? 2 : 1) {
Imre Deak9ca3ba02015-03-17 11:40:05 +0200913 unsigned int error_ppm;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300914
915 clock.p = clock.p1 * clock.p2;
916
917 m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p *
918 clock.n) << 22, refclk * clock.m1);
919
920 if (m2 > INT_MAX/clock.m1)
921 continue;
922
923 clock.m2 = m2;
924
Imre Deakdccbea32015-06-22 23:35:51 +0300925 chv_calc_dpll_params(refclk, &clock);
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300926
Tvrtko Ursuline2d214a2016-10-13 11:03:04 +0100927 if (!intel_PLL_is_valid(to_i915(dev), limit, &clock))
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300928 continue;
929
Imre Deak9ca3ba02015-03-17 11:40:05 +0200930 if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock,
931 best_error_ppm, &error_ppm))
932 continue;
933
934 *best_clock = clock;
935 best_error_ppm = error_ppm;
936 found = true;
Chon Ming Leeef9348c2014-04-09 13:28:18 +0300937 }
938 }
939
940 return found;
941}
942
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200943bool bxt_find_best_dpll(struct intel_crtc_state *crtc_state, int target_clock,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +0300944 struct dpll *best_clock)
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200945{
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200946 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +0300947 const struct intel_limit *limit = &intel_limits_bxt;
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200948
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +0200949 return chv_find_best_dpll(limit, crtc_state,
Imre Deak5ab7b0b2015-03-06 03:29:25 +0200950 target_clock, refclk, NULL, best_clock);
951}
952
Ville Syrjälä525b9312016-10-31 22:37:02 +0200953bool intel_crtc_active(struct intel_crtc *crtc)
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300954{
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300955 /* Be paranoid as we can arrive here with only partial
956 * state retrieved from the hardware during setup.
957 *
Damien Lespiau241bfc32013-09-25 16:45:37 +0100958 * We can ditch the adjusted_mode.crtc_clock check as soon
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300959 * as Haswell has gained clock readout/fastboot support.
960 *
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +0300961 * We can ditch the crtc->primary->state->fb check as soon as we can
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300962 * properly reconstruct framebuffers.
Matt Roperc3d1f432015-03-09 10:19:23 -0700963 *
964 * FIXME: The intel_crtc->active here should be switched to
965 * crtc->state->active once we have proper CRTC states wired up
966 * for atomic.
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300967 */
Ville Syrjälä525b9312016-10-31 22:37:02 +0200968 return crtc->active && crtc->base.primary->state->fb &&
969 crtc->config->base.adjusted_mode.crtc_clock;
Ville Syrjälä20ddf662013-09-04 18:25:25 +0300970}
971
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200972enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
973 enum pipe pipe)
974{
Ville Syrjälä98187832016-10-31 22:37:10 +0200975 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200976
Ville Syrjäläe2af48c2016-10-31 22:37:05 +0200977 return crtc->config->cpu_transcoder;
Paulo Zanonia5c961d2012-10-24 15:59:34 -0200978}
979
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200980static bool pipe_scanline_is_moving(struct drm_i915_private *dev_priv,
981 enum pipe pipe)
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300982{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200983 i915_reg_t reg = PIPEDSL(pipe);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300984 u32 line1, line2;
985 u32 line_mask;
986
Lucas De Marchicf819ef2018-12-12 10:10:43 -0800987 if (IS_GEN(dev_priv, 2))
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300988 line_mask = DSL_LINEMASK_GEN2;
989 else
990 line_mask = DSL_LINEMASK_GEN3;
991
992 line1 = I915_READ(reg) & line_mask;
Daniel Vetter6adfb1e2015-07-07 09:10:40 +0200993 msleep(5);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +0300994 line2 = I915_READ(reg) & line_mask;
995
Ville Syrjälä8fedd642017-11-29 17:37:30 +0200996 return line1 != line2;
997}
998
999static void wait_for_pipe_scanline_moving(struct intel_crtc *crtc, bool state)
1000{
1001 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1002 enum pipe pipe = crtc->pipe;
1003
1004 /* Wait for the display line to settle/start moving */
1005 if (wait_for(pipe_scanline_is_moving(dev_priv, pipe) == state, 100))
1006 DRM_ERROR("pipe %c scanline %s wait timed out\n",
1007 pipe_name(pipe), onoff(state));
1008}
1009
1010static void intel_wait_for_pipe_scanline_stopped(struct intel_crtc *crtc)
1011{
1012 wait_for_pipe_scanline_moving(crtc, false);
1013}
1014
1015static void intel_wait_for_pipe_scanline_moving(struct intel_crtc *crtc)
1016{
1017 wait_for_pipe_scanline_moving(crtc, true);
Ville Syrjäläfbf49ea2013-10-11 14:21:31 +03001018}
1019
Ville Syrjälä4972f702017-11-29 17:37:32 +02001020static void
1021intel_wait_for_pipe_off(const struct intel_crtc_state *old_crtc_state)
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001022{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001023 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001024 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001025
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001026 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001027 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001028 i915_reg_t reg = PIPECONF(cpu_transcoder);
Jesse Barnes9d0498a2010-08-18 13:20:54 -07001029
Keith Packardab7ad7f2010-10-03 00:33:06 -07001030 /* Wait for the Pipe State to go off */
Chris Wilsonb8511f52016-06-30 15:32:53 +01001031 if (intel_wait_for_register(dev_priv,
1032 reg, I965_PIPECONF_ACTIVE, 0,
1033 100))
Daniel Vetter284637d2012-07-09 09:51:57 +02001034 WARN(1, "pipe_off wait timed out\n");
Keith Packardab7ad7f2010-10-03 00:33:06 -07001035 } else {
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001036 intel_wait_for_pipe_scanline_stopped(crtc);
Keith Packardab7ad7f2010-10-03 00:33:06 -07001037 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001038}
1039
Jesse Barnesb24e7172011-01-04 15:09:30 -08001040/* Only for pre-ILK configs */
Daniel Vetter55607e82013-06-16 21:42:39 +02001041void assert_pll(struct drm_i915_private *dev_priv,
1042 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001043{
Jesse Barnesb24e7172011-01-04 15:09:30 -08001044 u32 val;
1045 bool cur_state;
1046
Ville Syrjälä649636e2015-09-22 19:50:01 +03001047 val = I915_READ(DPLL(pipe));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001048 cur_state = !!(val & DPLL_VCO_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001049 I915_STATE_WARN(cur_state != state,
Jesse Barnesb24e7172011-01-04 15:09:30 -08001050 "PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001051 onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001052}
Jesse Barnesb24e7172011-01-04 15:09:30 -08001053
Jani Nikula23538ef2013-08-27 15:12:22 +03001054/* XXX: the dsi pll is shared between MIPI DSI ports */
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +00001055void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state)
Jani Nikula23538ef2013-08-27 15:12:22 +03001056{
1057 u32 val;
1058 bool cur_state;
1059
Ville Syrjäläa5805162015-05-26 20:42:30 +03001060 mutex_lock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001061 val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL);
Ville Syrjäläa5805162015-05-26 20:42:30 +03001062 mutex_unlock(&dev_priv->sb_lock);
Jani Nikula23538ef2013-08-27 15:12:22 +03001063
1064 cur_state = val & DSI_PLL_VCO_EN;
Rob Clarke2c719b2014-12-15 13:56:32 -05001065 I915_STATE_WARN(cur_state != state,
Jani Nikula23538ef2013-08-27 15:12:22 +03001066 "DSI PLL state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001067 onoff(state), onoff(cur_state));
Jani Nikula23538ef2013-08-27 15:12:22 +03001068}
Jani Nikula23538ef2013-08-27 15:12:22 +03001069
Jesse Barnes040484a2011-01-03 12:14:26 -08001070static void assert_fdi_tx(struct drm_i915_private *dev_priv,
1071 enum pipe pipe, bool state)
1072{
Jesse Barnes040484a2011-01-03 12:14:26 -08001073 bool cur_state;
Paulo Zanoniad80a812012-10-24 16:06:19 -02001074 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1075 pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001076
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001077 if (HAS_DDI(dev_priv)) {
Paulo Zanoniaffa9352012-11-23 15:30:39 -02001078 /* DDI does not have a specific FDI_TX register */
Ville Syrjälä649636e2015-09-22 19:50:01 +03001079 u32 val = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
Paulo Zanoniad80a812012-10-24 16:06:19 -02001080 cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001081 } else {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001082 u32 val = I915_READ(FDI_TX_CTL(pipe));
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001083 cur_state = !!(val & FDI_TX_ENABLE);
1084 }
Rob Clarke2c719b2014-12-15 13:56:32 -05001085 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001086 "FDI TX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001087 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001088}
1089#define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
1090#define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
1091
1092static void assert_fdi_rx(struct drm_i915_private *dev_priv,
1093 enum pipe pipe, bool state)
1094{
Jesse Barnes040484a2011-01-03 12:14:26 -08001095 u32 val;
1096 bool cur_state;
1097
Ville Syrjälä649636e2015-09-22 19:50:01 +03001098 val = I915_READ(FDI_RX_CTL(pipe));
Paulo Zanonid63fa0d2012-11-20 13:27:35 -02001099 cur_state = !!(val & FDI_RX_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001100 I915_STATE_WARN(cur_state != state,
Jesse Barnes040484a2011-01-03 12:14:26 -08001101 "FDI RX state assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001102 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001103}
1104#define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
1105#define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
1106
1107static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
1108 enum pipe pipe)
1109{
Jesse Barnes040484a2011-01-03 12:14:26 -08001110 u32 val;
1111
1112 /* ILK FDI PLL is always enabled */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001113 if (IS_GEN(dev_priv, 5))
Jesse Barnes040484a2011-01-03 12:14:26 -08001114 return;
1115
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001116 /* On Haswell, DDI ports are responsible for the FDI PLL setup */
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001117 if (HAS_DDI(dev_priv))
Eugeni Dodonovbf507ef2012-05-09 15:37:18 -03001118 return;
1119
Ville Syrjälä649636e2015-09-22 19:50:01 +03001120 val = I915_READ(FDI_TX_CTL(pipe));
Rob Clarke2c719b2014-12-15 13:56:32 -05001121 I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
Jesse Barnes040484a2011-01-03 12:14:26 -08001122}
1123
Daniel Vetter55607e82013-06-16 21:42:39 +02001124void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
1125 enum pipe pipe, bool state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001126{
Jesse Barnes040484a2011-01-03 12:14:26 -08001127 u32 val;
Daniel Vetter55607e82013-06-16 21:42:39 +02001128 bool cur_state;
Jesse Barnes040484a2011-01-03 12:14:26 -08001129
Ville Syrjälä649636e2015-09-22 19:50:01 +03001130 val = I915_READ(FDI_RX_CTL(pipe));
Daniel Vetter55607e82013-06-16 21:42:39 +02001131 cur_state = !!(val & FDI_RX_PLL_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001132 I915_STATE_WARN(cur_state != state,
Daniel Vetter55607e82013-06-16 21:42:39 +02001133 "FDI RX PLL assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001134 onoff(state), onoff(cur_state));
Jesse Barnes040484a2011-01-03 12:14:26 -08001135}
1136
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001137void assert_panel_unlocked(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnesea0760c2011-01-04 15:09:32 -08001138{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001139 i915_reg_t pp_reg;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001140 u32 val;
Ville Syrjälä10ed55e2018-05-23 17:57:18 +03001141 enum pipe panel_pipe = INVALID_PIPE;
Thomas Jarosch0de3b482011-08-25 15:37:45 +02001142 bool locked = true;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001143
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001144 if (WARN_ON(HAS_DDI(dev_priv)))
Jani Nikulabedd4db2014-08-22 15:04:13 +03001145 return;
1146
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001147 if (HAS_PCH_SPLIT(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001148 u32 port_sel;
1149
Imre Deak44cb7342016-08-10 14:07:29 +03001150 pp_reg = PP_CONTROL(0);
1151 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
Jani Nikulabedd4db2014-08-22 15:04:13 +03001152
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001153 switch (port_sel) {
1154 case PANEL_PORT_SELECT_LVDS:
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001155 intel_lvds_port_enabled(dev_priv, PCH_LVDS, &panel_pipe);
Ville Syrjälä4c23dea2018-05-18 18:29:30 +03001156 break;
1157 case PANEL_PORT_SELECT_DPA:
1158 intel_dp_port_enabled(dev_priv, DP_A, PORT_A, &panel_pipe);
1159 break;
1160 case PANEL_PORT_SELECT_DPC:
1161 intel_dp_port_enabled(dev_priv, PCH_DP_C, PORT_C, &panel_pipe);
1162 break;
1163 case PANEL_PORT_SELECT_DPD:
1164 intel_dp_port_enabled(dev_priv, PCH_DP_D, PORT_D, &panel_pipe);
1165 break;
1166 default:
1167 MISSING_CASE(port_sel);
1168 break;
1169 }
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01001170 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Jani Nikulabedd4db2014-08-22 15:04:13 +03001171 /* presumably write lock depends on pipe, not port select */
Imre Deak44cb7342016-08-10 14:07:29 +03001172 pp_reg = PP_CONTROL(pipe);
Jani Nikulabedd4db2014-08-22 15:04:13 +03001173 panel_pipe = pipe;
Jesse Barnesea0760c2011-01-04 15:09:32 -08001174 } else {
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001175 u32 port_sel;
1176
Imre Deak44cb7342016-08-10 14:07:29 +03001177 pp_reg = PP_CONTROL(0);
Ville Syrjäläf0d2b752018-05-18 18:29:31 +03001178 port_sel = I915_READ(PP_ON_DELAYS(0)) & PANEL_PORT_SELECT_MASK;
1179
1180 WARN_ON(port_sel != PANEL_PORT_SELECT_LVDS);
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001181 intel_lvds_port_enabled(dev_priv, LVDS, &panel_pipe);
Jesse Barnesea0760c2011-01-04 15:09:32 -08001182 }
1183
1184 val = I915_READ(pp_reg);
1185 if (!(val & PANEL_POWER_ON) ||
Jani Nikulaec49ba22014-08-21 15:06:25 +03001186 ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS))
Jesse Barnesea0760c2011-01-04 15:09:32 -08001187 locked = false;
1188
Rob Clarke2c719b2014-12-15 13:56:32 -05001189 I915_STATE_WARN(panel_pipe == pipe && locked,
Jesse Barnesea0760c2011-01-04 15:09:32 -08001190 "panel assertion failure, pipe %c regs locked\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001191 pipe_name(pipe));
Jesse Barnesea0760c2011-01-04 15:09:32 -08001192}
1193
Jesse Barnesb840d907f2011-12-13 13:19:38 -08001194void assert_pipe(struct drm_i915_private *dev_priv,
1195 enum pipe pipe, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001196{
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001197 bool cur_state;
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001198 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
1199 pipe);
Imre Deak4feed0e2016-02-12 18:55:14 +02001200 enum intel_display_power_domain power_domain;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001201
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001202 /* we keep both pipes enabled on 830 */
1203 if (IS_I830(dev_priv))
Daniel Vetter8e636782012-01-22 01:36:48 +01001204 state = true;
1205
Imre Deak4feed0e2016-02-12 18:55:14 +02001206 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
1207 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ville Syrjälä649636e2015-09-22 19:50:01 +03001208 u32 val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni69310162013-01-29 16:35:19 -02001209 cur_state = !!(val & PIPECONF_ENABLE);
Imre Deak4feed0e2016-02-12 18:55:14 +02001210
1211 intel_display_power_put(dev_priv, power_domain);
1212 } else {
1213 cur_state = false;
Paulo Zanoni69310162013-01-29 16:35:19 -02001214 }
1215
Rob Clarke2c719b2014-12-15 13:56:32 -05001216 I915_STATE_WARN(cur_state != state,
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001217 "pipe %c assertion failure (expected %s, current %s)\n",
Jani Nikula87ad3212016-01-14 12:53:34 +02001218 pipe_name(pipe), onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001219}
1220
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001221static void assert_plane(struct intel_plane *plane, bool state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001222{
Ville Syrjäläeade6c82018-01-30 22:38:03 +02001223 enum pipe pipe;
1224 bool cur_state;
1225
1226 cur_state = plane->get_hw_state(plane, &pipe);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001227
Rob Clarke2c719b2014-12-15 13:56:32 -05001228 I915_STATE_WARN(cur_state != state,
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001229 "%s assertion failure (expected %s, current %s)\n",
1230 plane->base.name, onoff(state), onoff(cur_state));
Jesse Barnesb24e7172011-01-04 15:09:30 -08001231}
1232
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001233#define assert_plane_enabled(p) assert_plane(p, true)
1234#define assert_plane_disabled(p) assert_plane(p, false)
Chris Wilson931872f2012-01-16 23:01:13 +00001235
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001236static void assert_planes_disabled(struct intel_crtc *crtc)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001237{
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001238 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1239 struct intel_plane *plane;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001240
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001241 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane)
1242 assert_plane_disabled(plane);
Jesse Barnes19332d72013-03-28 09:55:38 -07001243}
1244
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001245static void assert_vblank_disabled(struct drm_crtc *crtc)
1246{
Rob Clarke2c719b2014-12-15 13:56:32 -05001247 if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0))
Ville Syrjälä08c71e52014-08-06 14:49:45 +03001248 drm_crtc_vblank_put(crtc);
1249}
1250
Ander Conselvan de Oliveira7abd4b32016-03-08 17:46:15 +02001251void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv,
1252 enum pipe pipe)
Jesse Barnes92f25842011-01-04 15:09:34 -08001253{
Jesse Barnes92f25842011-01-04 15:09:34 -08001254 u32 val;
1255 bool enabled;
1256
Ville Syrjälä649636e2015-09-22 19:50:01 +03001257 val = I915_READ(PCH_TRANSCONF(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001258 enabled = !!(val & TRANS_ENABLE);
Rob Clarke2c719b2014-12-15 13:56:32 -05001259 I915_STATE_WARN(enabled,
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001260 "transcoder assertion failed, should be off on pipe %c but is still active\n",
1261 pipe_name(pipe));
Jesse Barnes92f25842011-01-04 15:09:34 -08001262}
1263
Jesse Barnes291906f2011-02-02 12:28:03 -08001264static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001265 enum pipe pipe, enum port port,
1266 i915_reg_t dp_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001267{
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001268 enum pipe port_pipe;
1269 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001270
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001271 state = intel_dp_port_enabled(dev_priv, dp_reg, port, &port_pipe);
1272
1273 I915_STATE_WARN(state && port_pipe == pipe,
1274 "PCH DP %c enabled on transcoder %c, should be disabled\n",
1275 port_name(port), pipe_name(pipe));
1276
1277 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1278 "IBX PCH DP %c still using transcoder B\n",
1279 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001280}
1281
1282static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
Ville Syrjälä76203462018-05-14 20:24:21 +03001283 enum pipe pipe, enum port port,
1284 i915_reg_t hdmi_reg)
Jesse Barnes291906f2011-02-02 12:28:03 -08001285{
Ville Syrjälä76203462018-05-14 20:24:21 +03001286 enum pipe port_pipe;
1287 bool state;
Daniel Vetterde9a35a2012-06-05 11:03:40 +02001288
Ville Syrjälä76203462018-05-14 20:24:21 +03001289 state = intel_sdvo_port_enabled(dev_priv, hdmi_reg, &port_pipe);
1290
1291 I915_STATE_WARN(state && port_pipe == pipe,
1292 "PCH HDMI %c enabled on transcoder %c, should be disabled\n",
1293 port_name(port), pipe_name(pipe));
1294
1295 I915_STATE_WARN(HAS_PCH_IBX(dev_priv) && !state && port_pipe == PIPE_B,
1296 "IBX PCH HDMI %c still using transcoder B\n",
1297 port_name(port));
Jesse Barnes291906f2011-02-02 12:28:03 -08001298}
1299
1300static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
1301 enum pipe pipe)
1302{
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001303 enum pipe port_pipe;
Jesse Barnes291906f2011-02-02 12:28:03 -08001304
Ville Syrjälä59b74c42018-05-18 18:29:28 +03001305 assert_pch_dp_disabled(dev_priv, pipe, PORT_B, PCH_DP_B);
1306 assert_pch_dp_disabled(dev_priv, pipe, PORT_C, PCH_DP_C);
1307 assert_pch_dp_disabled(dev_priv, pipe, PORT_D, PCH_DP_D);
Jesse Barnes291906f2011-02-02 12:28:03 -08001308
Ville Syrjälä6102a8e2018-05-14 20:24:19 +03001309 I915_STATE_WARN(intel_crt_port_enabled(dev_priv, PCH_ADPA, &port_pipe) &&
1310 port_pipe == pipe,
1311 "PCH VGA enabled on transcoder %c, should be disabled\n",
1312 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001313
Ville Syrjäläa44628b2018-05-14 21:28:27 +03001314 I915_STATE_WARN(intel_lvds_port_enabled(dev_priv, PCH_LVDS, &port_pipe) &&
1315 port_pipe == pipe,
1316 "PCH LVDS enabled on transcoder %c, should be disabled\n",
1317 pipe_name(pipe));
Jesse Barnes291906f2011-02-02 12:28:03 -08001318
Ville Syrjälä3aefb672018-11-08 16:36:35 +02001319 /* PCH SDVOB multiplex with HDMIB */
Ville Syrjälä76203462018-05-14 20:24:21 +03001320 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_B, PCH_HDMIB);
1321 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_C, PCH_HDMIC);
1322 assert_pch_hdmi_disabled(dev_priv, pipe, PORT_D, PCH_HDMID);
Jesse Barnes291906f2011-02-02 12:28:03 -08001323}
1324
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001325static void _vlv_enable_pll(struct intel_crtc *crtc,
1326 const struct intel_crtc_state *pipe_config)
1327{
1328 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1329 enum pipe pipe = crtc->pipe;
1330
1331 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
1332 POSTING_READ(DPLL(pipe));
1333 udelay(150);
1334
Chris Wilson2c30b432016-06-30 15:32:54 +01001335 if (intel_wait_for_register(dev_priv,
1336 DPLL(pipe),
1337 DPLL_LOCK_VLV,
1338 DPLL_LOCK_VLV,
1339 1))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001340 DRM_ERROR("DPLL %d failed to lock\n", pipe);
1341}
1342
Ville Syrjäläd288f652014-10-28 13:20:22 +02001343static void vlv_enable_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02001344 const struct intel_crtc_state *pipe_config)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001345{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001346 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001347 enum pipe pipe = crtc->pipe;
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001348
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001349 assert_pipe_disabled(dev_priv, pipe);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001350
Daniel Vetter87442f72013-06-06 00:52:17 +02001351 /* PLL is protected by panel, make sure we can write it */
Ville Syrjälä7d1a83c2016-03-15 16:39:58 +02001352 assert_panel_unlocked(dev_priv, pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001353
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001354 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1355 _vlv_enable_pll(crtc, pipe_config);
Daniel Vetter426115c2013-07-11 22:13:42 +02001356
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001357 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1358 POSTING_READ(DPLL_MD(pipe));
Daniel Vetter87442f72013-06-06 00:52:17 +02001359}
1360
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001361
1362static void _chv_enable_pll(struct intel_crtc *crtc,
1363 const struct intel_crtc_state *pipe_config)
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001364{
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001365 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä8bd3f302016-03-15 16:39:57 +02001366 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001367 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001368 u32 tmp;
1369
Ville Syrjäläa5805162015-05-26 20:42:30 +03001370 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001371
1372 /* Enable back the 10bit clock to display controller */
1373 tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1374 tmp |= DPIO_DCLKP_EN;
1375 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp);
1376
Ville Syrjälä54433e92015-05-26 20:42:31 +03001377 mutex_unlock(&dev_priv->sb_lock);
1378
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001379 /*
1380 * Need to wait > 100ns between dclkp clock enable bit and PLL enable.
1381 */
1382 udelay(1);
1383
1384 /* Enable PLL */
Ville Syrjäläd288f652014-10-28 13:20:22 +02001385 I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001386
1387 /* Check PLL is locked */
Chris Wilson6b188262016-06-30 15:32:55 +01001388 if (intel_wait_for_register(dev_priv,
1389 DPLL(pipe), DPLL_LOCK_VLV, DPLL_LOCK_VLV,
1390 1))
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001391 DRM_ERROR("PLL %d failed to lock\n", pipe);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03001392}
1393
1394static void chv_enable_pll(struct intel_crtc *crtc,
1395 const struct intel_crtc_state *pipe_config)
1396{
1397 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1398 enum pipe pipe = crtc->pipe;
1399
1400 assert_pipe_disabled(dev_priv, pipe);
1401
1402 /* PLL is protected by panel, make sure we can write it */
1403 assert_panel_unlocked(dev_priv, pipe);
1404
1405 if (pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)
1406 _chv_enable_pll(crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001407
Ville Syrjäläc2317752016-03-15 16:39:56 +02001408 if (pipe != PIPE_A) {
1409 /*
1410 * WaPixelRepeatModeFixForC0:chv
1411 *
1412 * DPLLCMD is AWOL. Use chicken bits to propagate
1413 * the value from DPLLBMD to either pipe B or C.
1414 */
Ville Syrjälädfa311f2017-09-13 17:08:54 +03001415 I915_WRITE(CBR4_VLV, CBR_DPLLBMD_PIPE(pipe));
Ville Syrjäläc2317752016-03-15 16:39:56 +02001416 I915_WRITE(DPLL_MD(PIPE_B), pipe_config->dpll_hw_state.dpll_md);
1417 I915_WRITE(CBR4_VLV, 0);
1418 dev_priv->chv_dpll_md[pipe] = pipe_config->dpll_hw_state.dpll_md;
1419
1420 /*
1421 * DPLLB VGA mode also seems to cause problems.
1422 * We should always have it disabled.
1423 */
1424 WARN_ON((I915_READ(DPLL(PIPE_B)) & DPLL_VGA_MODE_DIS) == 0);
1425 } else {
1426 I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md);
1427 POSTING_READ(DPLL_MD(pipe));
1428 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03001429}
1430
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001431static int intel_num_dvo_pipes(struct drm_i915_private *dev_priv)
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001432{
1433 struct intel_crtc *crtc;
1434 int count = 0;
1435
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001436 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst3538b9d2015-06-01 12:50:10 +02001437 count += crtc->base.state->active &&
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03001438 intel_crtc_has_type(crtc->config, INTEL_OUTPUT_DVO);
1439 }
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001440
1441 return count;
1442}
1443
Ville Syrjälä939994d2017-09-13 17:08:56 +03001444static void i9xx_enable_pll(struct intel_crtc *crtc,
1445 const struct intel_crtc_state *crtc_state)
Daniel Vetter87442f72013-06-06 00:52:17 +02001446{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001447 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001448 i915_reg_t reg = DPLL(crtc->pipe);
Ville Syrjälä939994d2017-09-13 17:08:56 +03001449 u32 dpll = crtc_state->dpll_hw_state.dpll;
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001450 int i;
Daniel Vetter87442f72013-06-06 00:52:17 +02001451
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001452 assert_pipe_disabled(dev_priv, crtc->pipe);
Daniel Vetter87442f72013-06-06 00:52:17 +02001453
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001454 /* PLL is protected by panel, make sure we can write it */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001455 if (IS_MOBILE(dev_priv) && !IS_I830(dev_priv))
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001456 assert_panel_unlocked(dev_priv, crtc->pipe);
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001457
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001458 /* Enable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001459 if (IS_I830(dev_priv) && intel_num_dvo_pipes(dev_priv) > 0) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001460 /*
1461 * It appears to be important that we don't enable this
1462 * for the current pipe before otherwise configuring the
1463 * PLL. No idea how this should be handled if multiple
1464 * DVO outputs are enabled simultaneosly.
1465 */
1466 dpll |= DPLL_DVO_2X_MODE;
1467 I915_WRITE(DPLL(!crtc->pipe),
1468 I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE);
1469 }
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001470
Ville Syrjäläc2b63372015-10-07 22:08:25 +03001471 /*
1472 * Apparently we need to have VGA mode enabled prior to changing
1473 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
1474 * dividers, even though the register value does change.
1475 */
1476 I915_WRITE(reg, 0);
1477
Ville Syrjälä8e7a65a2015-10-07 22:08:24 +03001478 I915_WRITE(reg, dpll);
1479
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001480 /* Wait for the clocks to stabilize. */
1481 POSTING_READ(reg);
1482 udelay(150);
1483
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001484 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001485 I915_WRITE(DPLL_MD(crtc->pipe),
Ville Syrjälä939994d2017-09-13 17:08:56 +03001486 crtc_state->dpll_hw_state.dpll_md);
Daniel Vetter66e3d5c2013-06-16 21:24:16 +02001487 } else {
1488 /* The pixel multiplier can only be updated once the
1489 * DPLL is enabled and the clocks are stable.
1490 *
1491 * So write it again.
1492 */
1493 I915_WRITE(reg, dpll);
1494 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001495
1496 /* We do this three times for luck */
Ville Syrjäläbb408dd2017-06-01 17:36:15 +03001497 for (i = 0; i < 3; i++) {
1498 I915_WRITE(reg, dpll);
1499 POSTING_READ(reg);
1500 udelay(150); /* wait for warmup */
1501 }
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001502}
1503
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001504static void i9xx_disable_pll(const struct intel_crtc_state *crtc_state)
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001505{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001506 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001507 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001508 enum pipe pipe = crtc->pipe;
1509
1510 /* Disable DVO 2x clock on both PLLs if necessary */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01001511 if (IS_I830(dev_priv) &&
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02001512 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO) &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00001513 !intel_num_dvo_pipes(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03001514 I915_WRITE(DPLL(PIPE_B),
1515 I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE);
1516 I915_WRITE(DPLL(PIPE_A),
1517 I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE);
1518 }
1519
Ville Syrjäläb6b5d042014-08-15 01:22:07 +03001520 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001521 if (IS_I830(dev_priv))
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001522 return;
1523
1524 /* Make sure the pipe isn't still relying on us */
1525 assert_pipe_disabled(dev_priv, pipe);
1526
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001527 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
Daniel Vetter50b44a42013-06-05 13:34:33 +02001528 POSTING_READ(DPLL(pipe));
Jesse Barnes63d7bbe2011-01-04 15:09:33 -08001529}
1530
Jesse Barnesf6071162013-10-01 10:41:38 -07001531static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1532{
Ville Syrjäläb8afb912015-06-29 15:25:48 +03001533 u32 val;
Jesse Barnesf6071162013-10-01 10:41:38 -07001534
1535 /* Make sure the pipe isn't still relying on us */
1536 assert_pipe_disabled(dev_priv, pipe);
1537
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001538 val = DPLL_INTEGRATED_REF_CLK_VLV |
1539 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
1540 if (pipe != PIPE_A)
1541 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
1542
Jesse Barnesf6071162013-10-01 10:41:38 -07001543 I915_WRITE(DPLL(pipe), val);
1544 POSTING_READ(DPLL(pipe));
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001545}
1546
1547static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
1548{
Ville Syrjäläd7520482014-04-09 13:28:59 +03001549 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001550 u32 val;
1551
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001552 /* Make sure the pipe isn't still relying on us */
1553 assert_pipe_disabled(dev_priv, pipe);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03001554
Ville Syrjälä60bfe442015-06-29 15:25:49 +03001555 val = DPLL_SSC_REF_CLK_CHV |
1556 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001557 if (pipe != PIPE_A)
1558 val |= DPLL_INTEGRATED_CRI_CLK_VLV;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02001559
Ville Syrjäläa11b0702014-04-09 13:28:57 +03001560 I915_WRITE(DPLL(pipe), val);
1561 POSTING_READ(DPLL(pipe));
Ville Syrjäläd7520482014-04-09 13:28:59 +03001562
Ville Syrjäläa5805162015-05-26 20:42:30 +03001563 mutex_lock(&dev_priv->sb_lock);
Ville Syrjäläd7520482014-04-09 13:28:59 +03001564
1565 /* Disable 10bit clock to display controller */
1566 val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port));
1567 val &= ~DPIO_DCLKP_EN;
1568 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val);
1569
Ville Syrjäläa5805162015-05-26 20:42:30 +03001570 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesf6071162013-10-01 10:41:38 -07001571}
1572
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001573void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001574 struct intel_digital_port *dport,
1575 unsigned int expected_mask)
Jesse Barnes89b667f2013-04-18 14:51:36 -07001576{
1577 u32 port_mask;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001578 i915_reg_t dpll_reg;
Jesse Barnes89b667f2013-04-18 14:51:36 -07001579
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001580 switch (dport->base.port) {
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001581 case PORT_B:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001582 port_mask = DPLL_PORTB_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001583 dpll_reg = DPLL(0);
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001584 break;
1585 case PORT_C:
Jesse Barnes89b667f2013-04-18 14:51:36 -07001586 port_mask = DPLL_PORTC_READY_MASK;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001587 dpll_reg = DPLL(0);
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001588 expected_mask <<= 4;
Chon Ming Lee00fc31b2014-04-09 13:28:15 +03001589 break;
1590 case PORT_D:
1591 port_mask = DPLL_PORTD_READY_MASK;
1592 dpll_reg = DPIO_PHY_STATUS;
Chon Ming Leee4607fc2013-11-06 14:36:35 +08001593 break;
1594 default:
1595 BUG();
1596 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07001597
Chris Wilson370004d2016-06-30 15:32:56 +01001598 if (intel_wait_for_register(dev_priv,
1599 dpll_reg, port_mask, expected_mask,
1600 1000))
Ville Syrjälä9b6de0a2015-04-10 18:21:31 +03001601 WARN(1, "timed out waiting for port %c ready: got 0x%x, expected 0x%x\n",
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02001602 port_name(dport->base.port),
1603 I915_READ(dpll_reg) & port_mask, expected_mask);
Jesse Barnes89b667f2013-04-18 14:51:36 -07001604}
1605
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001606static void ironlake_enable_pch_transcoder(const struct intel_crtc_state *crtc_state)
Jesse Barnes040484a2011-01-03 12:14:26 -08001607{
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001608 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
1609 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1610 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001611 i915_reg_t reg;
1612 uint32_t val, pipeconf_val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001613
Jesse Barnes040484a2011-01-03 12:14:26 -08001614 /* Make sure PCH DPLL is enabled */
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001615 assert_shared_dpll_enabled(dev_priv, crtc_state->shared_dpll);
Jesse Barnes040484a2011-01-03 12:14:26 -08001616
1617 /* FDI must be feeding us bits for PCH ports */
1618 assert_fdi_tx_enabled(dev_priv, pipe);
1619 assert_fdi_rx_enabled(dev_priv, pipe);
1620
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001621 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001622 /* Workaround: Set the timing override bit before enabling the
1623 * pch transcoder. */
1624 reg = TRANS_CHICKEN2(pipe);
1625 val = I915_READ(reg);
1626 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
1627 I915_WRITE(reg, val);
Eugeni Dodonov59c859d2012-05-09 15:37:19 -03001628 }
Daniel Vetter23670b322012-11-01 09:15:30 +01001629
Daniel Vetterab9412b2013-05-03 11:49:46 +02001630 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001631 val = I915_READ(reg);
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001632 pipeconf_val = I915_READ(PIPECONF(pipe));
Jesse Barnese9bcff52011-06-24 12:19:20 -07001633
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001634 if (HAS_PCH_IBX(dev_priv)) {
Jesse Barnese9bcff52011-06-24 12:19:20 -07001635 /*
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001636 * Make the BPC in transcoder be consistent with
1637 * that in pipeconf reg. For HDMI we must use 8bpc
1638 * here for both 8bpc and 12bpc.
Jesse Barnese9bcff52011-06-24 12:19:20 -07001639 */
Daniel Vetterdfd07d72012-12-17 11:21:38 +01001640 val &= ~PIPECONF_BPC_MASK;
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001641 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Ville Syrjäläc5de7c62015-05-05 17:06:22 +03001642 val |= PIPECONF_8BPC;
1643 else
1644 val |= pipeconf_val & PIPECONF_BPC_MASK;
Jesse Barnese9bcff52011-06-24 12:19:20 -07001645 }
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001646
1647 val &= ~TRANS_INTERLACE_MASK;
1648 if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001649 if (HAS_PCH_IBX(dev_priv) &&
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02001650 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Paulo Zanoni7c26e5c2012-02-14 17:07:09 -02001651 val |= TRANS_LEGACY_INTERLACED_ILK;
1652 else
1653 val |= TRANS_INTERLACED;
Paulo Zanoni5f7f7262012-02-03 17:47:15 -02001654 else
1655 val |= TRANS_PROGRESSIVE;
1656
Jesse Barnes040484a2011-01-03 12:14:26 -08001657 I915_WRITE(reg, val | TRANS_ENABLE);
Chris Wilson650fbd82016-06-30 15:32:57 +01001658 if (intel_wait_for_register(dev_priv,
1659 reg, TRANS_STATE_ENABLE, TRANS_STATE_ENABLE,
1660 100))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001661 DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe));
Jesse Barnes040484a2011-01-03 12:14:26 -08001662}
1663
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001664static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
Paulo Zanoni937bb612012-10-31 18:12:47 -02001665 enum transcoder cpu_transcoder)
Jesse Barnes040484a2011-01-03 12:14:26 -08001666{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001667 u32 val, pipeconf_val;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001668
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001669 /* FDI must be feeding us bits for PCH ports */
Daniel Vetter1a240d42012-11-29 22:18:51 +01001670 assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001671 assert_fdi_rx_enabled(dev_priv, PIPE_A);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001672
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001673 /* Workaround: set timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001674 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001675 val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001676 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001677
Paulo Zanoni25f3ef12012-10-31 18:12:49 -02001678 val = TRANS_ENABLE;
Paulo Zanoni937bb612012-10-31 18:12:47 -02001679 pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001680
Paulo Zanoni9a76b1c2012-10-31 18:12:48 -02001681 if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
1682 PIPECONF_INTERLACED_ILK)
Paulo Zanonia35f2672012-10-31 18:12:45 -02001683 val |= TRANS_INTERLACED;
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001684 else
1685 val |= TRANS_PROGRESSIVE;
1686
Daniel Vetterab9412b2013-05-03 11:49:46 +02001687 I915_WRITE(LPT_TRANSCONF, val);
Chris Wilsond9f96242016-06-30 15:32:58 +01001688 if (intel_wait_for_register(dev_priv,
1689 LPT_TRANSCONF,
1690 TRANS_STATE_ENABLE,
1691 TRANS_STATE_ENABLE,
1692 100))
Paulo Zanoni937bb612012-10-31 18:12:47 -02001693 DRM_ERROR("Failed to enable PCH transcoder\n");
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001694}
1695
Paulo Zanonib8a4f402012-10-31 18:12:42 -02001696static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
1697 enum pipe pipe)
Jesse Barnes040484a2011-01-03 12:14:26 -08001698{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001699 i915_reg_t reg;
1700 uint32_t val;
Jesse Barnes040484a2011-01-03 12:14:26 -08001701
1702 /* FDI relies on the transcoder */
1703 assert_fdi_tx_disabled(dev_priv, pipe);
1704 assert_fdi_rx_disabled(dev_priv, pipe);
1705
Jesse Barnes291906f2011-02-02 12:28:03 -08001706 /* Ports must be off as well */
1707 assert_pch_ports_disabled(dev_priv, pipe);
1708
Daniel Vetterab9412b2013-05-03 11:49:46 +02001709 reg = PCH_TRANSCONF(pipe);
Jesse Barnes040484a2011-01-03 12:14:26 -08001710 val = I915_READ(reg);
1711 val &= ~TRANS_ENABLE;
1712 I915_WRITE(reg, val);
1713 /* wait for PCH transcoder off, transcoder state */
Chris Wilsona7d04662016-06-30 15:32:59 +01001714 if (intel_wait_for_register(dev_priv,
1715 reg, TRANS_STATE_ENABLE, 0,
1716 50))
Ville Syrjälä4bb6f1f2013-04-17 17:48:50 +03001717 DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe));
Daniel Vetter23670b322012-11-01 09:15:30 +01001718
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01001719 if (HAS_PCH_CPT(dev_priv)) {
Daniel Vetter23670b322012-11-01 09:15:30 +01001720 /* Workaround: Clear the timing override chicken bit again. */
1721 reg = TRANS_CHICKEN2(pipe);
1722 val = I915_READ(reg);
1723 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
1724 I915_WRITE(reg, val);
1725 }
Jesse Barnes040484a2011-01-03 12:14:26 -08001726}
1727
Maarten Lankhorstb7076542016-08-23 16:18:08 +02001728void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001729{
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001730 u32 val;
1731
Daniel Vetterab9412b2013-05-03 11:49:46 +02001732 val = I915_READ(LPT_TRANSCONF);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001733 val &= ~TRANS_ENABLE;
Daniel Vetterab9412b2013-05-03 11:49:46 +02001734 I915_WRITE(LPT_TRANSCONF, val);
Paulo Zanoni8fb033d2012-10-31 18:12:43 -02001735 /* wait for PCH transcoder off, transcoder state */
Chris Wilsondfdb4742016-06-30 15:33:00 +01001736 if (intel_wait_for_register(dev_priv,
1737 LPT_TRANSCONF, TRANS_STATE_ENABLE, 0,
1738 50))
Paulo Zanoni8a52fd92012-10-31 18:12:51 -02001739 DRM_ERROR("Failed to disable PCH transcoder\n");
Paulo Zanoni223a6fd2012-10-31 18:12:52 -02001740
1741 /* Workaround: clear timing override bit. */
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001742 val = I915_READ(TRANS_CHICKEN2(PIPE_A));
Daniel Vetter23670b322012-11-01 09:15:30 +01001743 val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
Ville Syrjälä36c0d0c2015-09-18 20:03:31 +03001744 I915_WRITE(TRANS_CHICKEN2(PIPE_A), val);
Jesse Barnes92f25842011-01-04 15:09:34 -08001745}
1746
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001747enum pipe intel_crtc_pch_transcoder(struct intel_crtc *crtc)
Ville Syrjälä65f21302016-10-14 20:02:53 +03001748{
1749 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1750
Ville Syrjälä65f21302016-10-14 20:02:53 +03001751 if (HAS_PCH_LPT(dev_priv))
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001752 return PIPE_A;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001753 else
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001754 return crtc->pipe;
Ville Syrjälä65f21302016-10-14 20:02:53 +03001755}
1756
Ville Syrjälä4972f702017-11-29 17:37:32 +02001757static void intel_enable_pipe(const struct intel_crtc_state *new_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001758{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001759 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
1760 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
1761 enum transcoder cpu_transcoder = new_crtc_state->cpu_transcoder;
Paulo Zanoni03722642014-01-17 13:51:09 -02001762 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001763 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001764 u32 val;
1765
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001766 DRM_DEBUG_KMS("enabling pipe %c\n", pipe_name(pipe));
1767
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001768 assert_planes_disabled(crtc);
Daniel Vetter58c6eaa2013-04-11 16:29:09 +02001769
Jesse Barnesb24e7172011-01-04 15:09:30 -08001770 /*
1771 * A pipe without a PLL won't actually be able to drive bits from
1772 * a plane. On ILK+ the pipe PLLs are integrated, so we don't
1773 * need the check.
1774 */
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001775 if (HAS_GMCH_DISPLAY(dev_priv)) {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001776 if (intel_crtc_has_type(new_crtc_state, INTEL_OUTPUT_DSI))
Jani Nikula23538ef2013-08-27 15:12:22 +03001777 assert_dsi_pll_enabled(dev_priv);
1778 else
1779 assert_pll_enabled(dev_priv, pipe);
Ville Syrjälä09fa8bb2016-08-05 20:41:34 +03001780 } else {
Ville Syrjälä4972f702017-11-29 17:37:32 +02001781 if (new_crtc_state->has_pch_encoder) {
Jesse Barnes040484a2011-01-03 12:14:26 -08001782 /* if driving the PCH, we need FDI enabled */
Ville Syrjälä65f21302016-10-14 20:02:53 +03001783 assert_fdi_rx_pll_enabled(dev_priv,
Matthias Kaehlckea2196032017-07-17 11:14:03 -07001784 intel_crtc_pch_transcoder(crtc));
Daniel Vetter1a240d42012-11-29 22:18:51 +01001785 assert_fdi_tx_pll_enabled(dev_priv,
1786 (enum pipe) cpu_transcoder);
Jesse Barnes040484a2011-01-03 12:14:26 -08001787 }
1788 /* FIXME: assert CPU port conditions for SNB+ */
1789 }
Jesse Barnesb24e7172011-01-04 15:09:30 -08001790
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001791 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001792 val = I915_READ(reg);
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001793 if (val & PIPECONF_ENABLE) {
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001794 /* we keep both pipes enabled on 830 */
1795 WARN_ON(!IS_I830(dev_priv));
Chris Wilson00d70b12011-03-17 07:18:29 +00001796 return;
Paulo Zanoni7ad25d42014-01-17 13:51:13 -02001797 }
Chris Wilson00d70b12011-03-17 07:18:29 +00001798
1799 I915_WRITE(reg, val | PIPECONF_ENABLE);
Paulo Zanoni851855d2013-12-19 19:12:29 -02001800 POSTING_READ(reg);
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001801
1802 /*
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001803 * Until the pipe starts PIPEDSL reads will return a stale value,
1804 * which causes an apparent vblank timestamp jump when PIPEDSL
1805 * resets to its proper value. That also messes up the frame count
1806 * when it's derived from the timestamps. So let's wait for the
1807 * pipe to start properly before we call drm_crtc_vblank_on()
Ville Syrjäläb7792d82015-12-14 18:23:43 +02001808 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001809 if (dev_priv->drm.max_vblank_count == 0)
Ville Syrjälä8fedd642017-11-29 17:37:30 +02001810 intel_wait_for_pipe_scanline_moving(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001811}
1812
Ville Syrjälä4972f702017-11-29 17:37:32 +02001813static void intel_disable_pipe(const struct intel_crtc_state *old_crtc_state)
Jesse Barnesb24e7172011-01-04 15:09:30 -08001814{
Ville Syrjälä4972f702017-11-29 17:37:32 +02001815 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Chris Wilsonfac5e232016-07-04 11:34:36 +01001816 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä4972f702017-11-29 17:37:32 +02001817 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Ville Syrjälä575f7ab2014-08-15 01:21:56 +03001818 enum pipe pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001819 i915_reg_t reg;
Jesse Barnesb24e7172011-01-04 15:09:30 -08001820 u32 val;
1821
Ville Syrjälä9e2ee2d2015-06-24 21:59:35 +03001822 DRM_DEBUG_KMS("disabling pipe %c\n", pipe_name(pipe));
1823
Jesse Barnesb24e7172011-01-04 15:09:30 -08001824 /*
1825 * Make sure planes won't keep trying to pump pixels to us,
1826 * or we might hang the display.
1827 */
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02001828 assert_planes_disabled(crtc);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001829
Paulo Zanoni702e7a52012-10-23 18:29:59 -02001830 reg = PIPECONF(cpu_transcoder);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001831 val = I915_READ(reg);
Chris Wilson00d70b12011-03-17 07:18:29 +00001832 if ((val & PIPECONF_ENABLE) == 0)
1833 return;
1834
Ville Syrjälä67adc642014-08-15 01:21:57 +03001835 /*
1836 * Double wide has implications for planes
1837 * so best keep it disabled when not needed.
1838 */
Ville Syrjälä4972f702017-11-29 17:37:32 +02001839 if (old_crtc_state->double_wide)
Ville Syrjälä67adc642014-08-15 01:21:57 +03001840 val &= ~PIPECONF_DOUBLE_WIDE;
1841
1842 /* Don't disable pipe or pipe PLLs if needed */
Ville Syrjäläe56134b2017-06-01 17:36:19 +03001843 if (!IS_I830(dev_priv))
Ville Syrjälä67adc642014-08-15 01:21:57 +03001844 val &= ~PIPECONF_ENABLE;
1845
1846 I915_WRITE(reg, val);
1847 if ((val & PIPECONF_ENABLE) == 0)
Ville Syrjälä4972f702017-11-29 17:37:32 +02001848 intel_wait_for_pipe_off(old_crtc_state);
Jesse Barnesb24e7172011-01-04 15:09:30 -08001849}
1850
Ville Syrjälä832be822016-01-12 21:08:33 +02001851static unsigned int intel_tile_size(const struct drm_i915_private *dev_priv)
1852{
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001853 return IS_GEN(dev_priv, 2) ? 2048 : 4096;
Ville Syrjälä832be822016-01-12 21:08:33 +02001854}
1855
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001856static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001857intel_tile_width_bytes(const struct drm_framebuffer *fb, int color_plane)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001858{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001859 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001860 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001861
1862 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001863 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001864 return cpp;
1865 case I915_FORMAT_MOD_X_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001866 if (IS_GEN(dev_priv, 2))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001867 return 128;
1868 else
1869 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001870 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001871 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001872 return 128;
1873 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001874 case I915_FORMAT_MOD_Y_TILED:
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001875 if (IS_GEN(dev_priv, 2) || HAS_128_BYTE_Y_TILING(dev_priv))
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001876 return 128;
1877 else
1878 return 512;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001879 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001880 if (color_plane == 1)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001881 return 128;
1882 /* fall through */
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001883 case I915_FORMAT_MOD_Yf_TILED:
1884 switch (cpp) {
1885 case 1:
1886 return 64;
1887 case 2:
1888 case 4:
1889 return 128;
1890 case 8:
1891 case 16:
1892 return 256;
1893 default:
1894 MISSING_CASE(cpp);
1895 return cpp;
1896 }
1897 break;
1898 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001899 MISSING_CASE(fb->modifier);
Ville Syrjälä7b49f942016-01-12 21:08:32 +02001900 return cpp;
1901 }
1902}
1903
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001904static unsigned int
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001905intel_tile_height(const struct drm_framebuffer *fb, int color_plane)
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001906{
Ben Widawsky2f075562017-03-24 14:29:48 -07001907 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä832be822016-01-12 21:08:33 +02001908 return 1;
1909 else
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001910 return intel_tile_size(to_i915(fb->dev)) /
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001911 intel_tile_width_bytes(fb, color_plane);
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001912}
1913
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001914/* Return the tile dimensions in pixel units */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001915static void intel_tile_dims(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001916 unsigned int *tile_width,
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001917 unsigned int *tile_height)
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001918{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001919 unsigned int tile_width_bytes = intel_tile_width_bytes(fb, color_plane);
1920 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001921
1922 *tile_width = tile_width_bytes / cpp;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001923 *tile_height = intel_tile_size(to_i915(fb->dev)) / tile_width_bytes;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02001924}
1925
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001926unsigned int
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001927intel_fb_align_height(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001928 int color_plane, unsigned int height)
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00001929{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001930 unsigned int tile_height = intel_tile_height(fb, color_plane);
Ville Syrjälä832be822016-01-12 21:08:33 +02001931
1932 return ALIGN(height, tile_height);
Jesse Barnesa57ce0b2014-02-07 12:10:35 -08001933}
1934
Ville Syrjälä1663b9d2016-02-15 22:54:45 +02001935unsigned int intel_rotation_info_size(const struct intel_rotation_info *rot_info)
1936{
1937 unsigned int size = 0;
1938 int i;
1939
1940 for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++)
1941 size += rot_info->plane[i].width * rot_info->plane[i].height;
1942
1943 return size;
1944}
1945
Daniel Vetter75c82a52015-10-14 16:51:04 +02001946static void
Ville Syrjälä3465c582016-02-15 22:54:43 +02001947intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
1948 const struct drm_framebuffer *fb,
1949 unsigned int rotation)
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00001950{
Chris Wilson7b92c042017-01-14 00:28:26 +00001951 view->type = I915_GGTT_VIEW_NORMAL;
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03001952 if (drm_rotation_90_or_270(rotation)) {
Chris Wilson7b92c042017-01-14 00:28:26 +00001953 view->type = I915_GGTT_VIEW_ROTATED;
Chris Wilson8bab11932017-01-14 00:28:25 +00001954 view->rotated = to_intel_framebuffer(fb)->rot_info;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +02001955 }
1956}
1957
Ville Syrjäläfabac482017-03-27 21:55:43 +03001958static unsigned int intel_cursor_alignment(const struct drm_i915_private *dev_priv)
1959{
1960 if (IS_I830(dev_priv))
1961 return 16 * 1024;
1962 else if (IS_I85X(dev_priv))
1963 return 256;
Ville Syrjäläd9e15512017-03-27 21:55:45 +03001964 else if (IS_I845G(dev_priv) || IS_I865G(dev_priv))
1965 return 32;
Ville Syrjäläfabac482017-03-27 21:55:43 +03001966 else
1967 return 4 * 1024;
1968}
1969
Ville Syrjälä603525d2016-01-12 21:08:37 +02001970static unsigned int intel_linear_alignment(const struct drm_i915_private *dev_priv)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001971{
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001972 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001973 return 256 * 1024;
Jani Nikulac0f86832016-12-07 12:13:04 +02001974 else if (IS_I965G(dev_priv) || IS_I965GM(dev_priv) ||
Wayne Boyer666a4532015-12-09 12:29:35 -08001975 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001976 return 128 * 1024;
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00001977 else if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001978 return 4 * 1024;
1979 else
Ville Syrjälä44c59052015-06-11 16:31:16 +03001980 return 0;
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03001981}
1982
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001983static unsigned int intel_surf_alignment(const struct drm_framebuffer *fb,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001984 int color_plane)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001985{
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001986 struct drm_i915_private *dev_priv = to_i915(fb->dev);
1987
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001988 /* AUX_DIST needs only 4K alignment */
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03001989 if (color_plane == 1)
Ville Syrjäläb90c1ee2017-03-07 21:42:07 +02001990 return 4096;
1991
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001992 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07001993 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjälä603525d2016-01-12 21:08:37 +02001994 return intel_linear_alignment(dev_priv);
1995 case I915_FORMAT_MOD_X_TILED:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02001996 if (INTEL_GEN(dev_priv) >= 9)
Ville Syrjälä603525d2016-01-12 21:08:37 +02001997 return 256 * 1024;
1998 return 0;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07001999 case I915_FORMAT_MOD_Y_TILED_CCS:
2000 case I915_FORMAT_MOD_Yf_TILED_CCS:
Ville Syrjälä603525d2016-01-12 21:08:37 +02002001 case I915_FORMAT_MOD_Y_TILED:
2002 case I915_FORMAT_MOD_Yf_TILED:
2003 return 1 * 1024 * 1024;
2004 default:
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002005 MISSING_CASE(fb->modifier);
Ville Syrjälä603525d2016-01-12 21:08:37 +02002006 return 0;
2007 }
2008}
2009
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002010static bool intel_plane_uses_fence(const struct intel_plane_state *plane_state)
2011{
2012 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2013 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
2014
Ville Syrjälä32febd92018-02-21 18:02:33 +02002015 return INTEL_GEN(dev_priv) < 4 || plane->has_fbc;
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002016}
2017
Chris Wilson058d88c2016-08-15 10:49:06 +01002018struct i915_vma *
Chris Wilson59354852018-02-20 13:42:06 +00002019intel_pin_and_fence_fb_obj(struct drm_framebuffer *fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002020 const struct i915_ggtt_view *view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002021 bool uses_fence,
Chris Wilson59354852018-02-20 13:42:06 +00002022 unsigned long *out_flags)
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002023{
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002024 struct drm_device *dev = fb->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002025 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulin850c4cd2014-10-30 16:39:38 +00002026 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Chris Wilson058d88c2016-08-15 10:49:06 +01002027 struct i915_vma *vma;
Chris Wilson59354852018-02-20 13:42:06 +00002028 unsigned int pinctl;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002029 u32 alignment;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002030
Matt Roperebcdd392014-07-09 16:22:11 -07002031 WARN_ON(!mutex_is_locked(&dev->struct_mutex));
2032
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002033 alignment = intel_surf_alignment(fb, 0);
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002034
Chris Wilson693db182013-03-05 14:52:39 +00002035 /* Note that the w/a also requires 64 PTE of padding following the
2036 * bo. We currently fill all unused PTE with the shadow page and so
2037 * we should always have valid PTE following the scanout preventing
2038 * the VT-d warning.
2039 */
Chris Wilson48f112f2016-06-24 14:07:14 +01002040 if (intel_scanout_needs_vtd_wa(dev_priv) && alignment < 256 * 1024)
Chris Wilson693db182013-03-05 14:52:39 +00002041 alignment = 256 * 1024;
2042
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002043 /*
2044 * Global gtt pte registers are special registers which actually forward
2045 * writes to a chunk of system memory. Which means that there is no risk
2046 * that the register values disappear as soon as we call
2047 * intel_runtime_pm_put(), so it is correct to wrap only the
2048 * pin/unpin/fence and not more.
2049 */
2050 intel_runtime_pm_get(dev_priv);
2051
Daniel Vetter9db529a2017-08-08 10:08:28 +02002052 atomic_inc(&dev_priv->gpu_error.pending_fb_pin);
2053
Chris Wilson59354852018-02-20 13:42:06 +00002054 pinctl = 0;
2055
2056 /* Valleyview is definitely limited to scanning out the first
2057 * 512MiB. Lets presume this behaviour was inherited from the
2058 * g4x display engine and that all earlier gen are similarly
2059 * limited. Testing suggests that it is a little more
2060 * complicated than this. For example, Cherryview appears quite
2061 * happy to scanout from anywhere within its global aperture.
2062 */
2063 if (HAS_GMCH_DISPLAY(dev_priv))
2064 pinctl |= PIN_MAPPABLE;
2065
2066 vma = i915_gem_object_pin_to_display_plane(obj,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002067 alignment, view, pinctl);
Chris Wilson49ef5292016-08-18 17:17:00 +01002068 if (IS_ERR(vma))
2069 goto err;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002070
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002071 if (uses_fence && i915_vma_is_map_and_fenceable(vma)) {
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002072 int ret;
2073
Chris Wilson49ef5292016-08-18 17:17:00 +01002074 /* Install a fence for tiled scan-out. Pre-i965 always needs a
2075 * fence, whereas 965+ only requires a fence if using
2076 * framebuffer compression. For simplicity, we always, when
2077 * possible, install a fence as the cost is not that onerous.
2078 *
2079 * If we fail to fence the tiled scanout, then either the
2080 * modeset will reject the change (which is highly unlikely as
2081 * the affected systems, all but one, do not have unmappable
2082 * space) or we will not be able to enable full powersaving
2083 * techniques (also likely not to apply due to various limits
2084 * FBC and the like impose on the size of the buffer, which
2085 * presumably we violated anyway with this unmappable buffer).
2086 * Anyway, it is presumably better to stumble onwards with
2087 * something and try to run the system in a "less than optimal"
2088 * mode that matches the user configuration.
2089 */
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002090 ret = i915_vma_pin_fence(vma);
2091 if (ret != 0 && INTEL_GEN(dev_priv) < 4) {
Chris Wilson75097022018-03-05 10:33:12 +00002092 i915_gem_object_unpin_from_display_plane(vma);
Ville Syrjälä85798ac2018-02-21 18:02:30 +02002093 vma = ERR_PTR(ret);
2094 goto err;
2095 }
2096
2097 if (ret == 0 && vma->fence)
Chris Wilson59354852018-02-20 13:42:06 +00002098 *out_flags |= PLANE_HAS_FENCE;
Vivek Kasireddy98072162015-10-29 18:54:38 -07002099 }
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002100
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002101 i915_vma_get(vma);
Chris Wilson49ef5292016-08-18 17:17:00 +01002102err:
Daniel Vetter9db529a2017-08-08 10:08:28 +02002103 atomic_dec(&dev_priv->gpu_error.pending_fb_pin);
2104
Paulo Zanonid6dd6842014-08-15 15:59:32 -03002105 intel_runtime_pm_put(dev_priv);
Chris Wilson058d88c2016-08-15 10:49:06 +01002106 return vma;
Kristian Høgsberg6b95a202009-11-18 11:25:18 -05002107}
2108
Chris Wilson59354852018-02-20 13:42:06 +00002109void intel_unpin_fb_vma(struct i915_vma *vma, unsigned long flags)
Chris Wilson1690e1e2011-12-14 13:57:08 +01002110{
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002111 lockdep_assert_held(&vma->vm->i915->drm.struct_mutex);
Tvrtko Ursulinf64b98c2015-03-23 11:10:35 +00002112
Chris Wilson59354852018-02-20 13:42:06 +00002113 if (flags & PLANE_HAS_FENCE)
2114 i915_vma_unpin_fence(vma);
Chris Wilson058d88c2016-08-15 10:49:06 +01002115 i915_gem_object_unpin_from_display_plane(vma);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002116 i915_vma_put(vma);
Chris Wilson1690e1e2011-12-14 13:57:08 +01002117}
2118
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002119static int intel_fb_pitch(const struct drm_framebuffer *fb, int color_plane,
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002120 unsigned int rotation)
2121{
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002122 if (drm_rotation_90_or_270(rotation))
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002123 return to_intel_framebuffer(fb)->rotated[color_plane].pitch;
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002124 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002125 return fb->pitches[color_plane];
Ville Syrjäläef78ec92015-10-13 22:48:39 +03002126}
2127
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002128/*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002129 * Convert the x/y offsets into a linear offset.
2130 * Only valid with 0/180 degree rotation, which is fine since linear
2131 * offset is only used with linear buffers on pre-hsw and tiled buffers
2132 * with gen2/3, and 90/270 degree rotations isn't supported on any of them.
2133 */
2134u32 intel_fb_xy_to_linear(int x, int y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002135 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002136 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002137{
Ville Syrjälä29490562016-01-20 18:02:50 +02002138 const struct drm_framebuffer *fb = state->base.fb;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002139 unsigned int cpp = fb->format->cpp[color_plane];
2140 unsigned int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002141
2142 return y * pitch + x * cpp;
2143}
2144
2145/*
2146 * Add the x/y offsets derived from fb->offsets[] to the user
2147 * specified plane src x/y offsets. The resulting x/y offsets
2148 * specify the start of scanout from the beginning of the gtt mapping.
2149 */
2150void intel_add_fb_offsets(int *x, int *y,
Ville Syrjälä29490562016-01-20 18:02:50 +02002151 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002152 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002153
2154{
Ville Syrjälä29490562016-01-20 18:02:50 +02002155 const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
2156 unsigned int rotation = state->base.rotation;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002157
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002158 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002159 *x += intel_fb->rotated[color_plane].x;
2160 *y += intel_fb->rotated[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002161 } else {
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002162 *x += intel_fb->normal[color_plane].x;
2163 *y += intel_fb->normal[color_plane].y;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002164 }
2165}
2166
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002167static u32 intel_adjust_tile_offset(int *x, int *y,
2168 unsigned int tile_width,
2169 unsigned int tile_height,
2170 unsigned int tile_size,
2171 unsigned int pitch_tiles,
2172 u32 old_offset,
2173 u32 new_offset)
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002174{
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002175 unsigned int pitch_pixels = pitch_tiles * tile_width;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002176 unsigned int tiles;
2177
2178 WARN_ON(old_offset & (tile_size - 1));
2179 WARN_ON(new_offset & (tile_size - 1));
2180 WARN_ON(new_offset > old_offset);
2181
2182 tiles = (old_offset - new_offset) / tile_size;
2183
2184 *y += tiles / pitch_tiles * tile_height;
2185 *x += tiles % pitch_tiles * tile_width;
2186
Ville Syrjäläb9b24032016-02-08 18:28:00 +02002187 /* minimize x in case it got needlessly big */
2188 *y += *x / pitch_pixels * tile_height;
2189 *x %= pitch_pixels;
2190
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002191 return new_offset;
2192}
2193
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002194static bool is_surface_linear(u64 modifier, int color_plane)
2195{
2196 return modifier == DRM_FORMAT_MOD_LINEAR;
2197}
2198
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002199static u32 intel_adjust_aligned_offset(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002200 const struct drm_framebuffer *fb,
2201 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002202 unsigned int rotation,
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002203 unsigned int pitch,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002204 u32 old_offset, u32 new_offset)
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002205{
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002206 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002207 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002208
2209 WARN_ON(new_offset > old_offset);
2210
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002211 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002212 unsigned int tile_size, tile_width, tile_height;
2213 unsigned int pitch_tiles;
2214
2215 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002216 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002217
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002218 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002219 pitch_tiles = pitch / tile_height;
2220 swap(tile_width, tile_height);
2221 } else {
2222 pitch_tiles = pitch / (tile_width * cpp);
2223 }
2224
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002225 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2226 tile_size, pitch_tiles,
2227 old_offset, new_offset);
Ville Syrjälä66a2d922016-02-05 18:44:05 +02002228 } else {
2229 old_offset += *y * pitch + *x * cpp;
2230
2231 *y = (old_offset - new_offset) / pitch;
2232 *x = ((old_offset - new_offset) - *y * pitch) / cpp;
2233 }
2234
2235 return new_offset;
2236}
2237
2238/*
Ville Syrjälä303ba692017-08-24 22:10:49 +03002239 * Adjust the tile offset by moving the difference into
2240 * the x/y offsets.
2241 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002242static u32 intel_plane_adjust_aligned_offset(int *x, int *y,
2243 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002244 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002245 u32 old_offset, u32 new_offset)
Ville Syrjälä303ba692017-08-24 22:10:49 +03002246{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002247 return intel_adjust_aligned_offset(x, y, state->base.fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002248 state->base.rotation,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002249 state->color_plane[color_plane].stride,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002250 old_offset, new_offset);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002251}
2252
2253/*
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002254 * Computes the aligned offset to the base tile and adjusts
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002255 * x, y. bytes per pixel is assumed to be a power-of-two.
2256 *
2257 * In the 90/270 rotated case, x and y are assumed
2258 * to be already rotated to match the rotated GTT view, and
2259 * pitch is the tile_height aligned framebuffer height.
Ville Syrjälä6687c902015-09-15 13:16:41 +03002260 *
2261 * This function is used when computing the derived information
2262 * under intel_framebuffer, so using any of that information
2263 * here is not allowed. Anything under drm_framebuffer can be
2264 * used. This is why the user has to pass in the pitch since it
2265 * is specified in the rotated orientation.
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002266 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002267static u32 intel_compute_aligned_offset(struct drm_i915_private *dev_priv,
2268 int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002269 const struct drm_framebuffer *fb,
2270 int color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002271 unsigned int pitch,
2272 unsigned int rotation,
2273 u32 alignment)
Daniel Vetterc2c75132012-07-05 12:17:30 +02002274{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002275 unsigned int cpp = fb->format->cpp[color_plane];
Ville Syrjälä6687c902015-09-15 13:16:41 +03002276 u32 offset, offset_aligned;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002277
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002278 if (alignment)
2279 alignment--;
2280
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002281 if (!is_surface_linear(fb->modifier, color_plane)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002282 unsigned int tile_size, tile_width, tile_height;
2283 unsigned int tile_rows, tiles, pitch_tiles;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002284
Ville Syrjäläd8433102016-01-12 21:08:35 +02002285 tile_size = intel_tile_size(dev_priv);
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002286 intel_tile_dims(fb, color_plane, &tile_width, &tile_height);
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002287
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03002288 if (drm_rotation_90_or_270(rotation)) {
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002289 pitch_tiles = pitch / tile_height;
2290 swap(tile_width, tile_height);
2291 } else {
2292 pitch_tiles = pitch / (tile_width * cpp);
2293 }
Daniel Vetterc2c75132012-07-05 12:17:30 +02002294
Ville Syrjäläd8433102016-01-12 21:08:35 +02002295 tile_rows = *y / tile_height;
2296 *y %= tile_height;
Chris Wilsonbc752862013-02-21 20:04:31 +00002297
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02002298 tiles = *x / tile_width;
2299 *x %= tile_width;
Ville Syrjäläd8433102016-01-12 21:08:35 +02002300
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002301 offset = (tile_rows * pitch_tiles + tiles) * tile_size;
2302 offset_aligned = offset & ~alignment;
Chris Wilsonbc752862013-02-21 20:04:31 +00002303
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002304 intel_adjust_tile_offset(x, y, tile_width, tile_height,
2305 tile_size, pitch_tiles,
2306 offset, offset_aligned);
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002307 } else {
Chris Wilsonbc752862013-02-21 20:04:31 +00002308 offset = *y * pitch + *x * cpp;
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002309 offset_aligned = offset & ~alignment;
2310
Ville Syrjälä4e9a86b2015-06-11 16:31:14 +03002311 *y = (offset & alignment) / pitch;
2312 *x = ((offset & alignment) - *y * pitch) / cpp;
Chris Wilsonbc752862013-02-21 20:04:31 +00002313 }
Ville Syrjälä29cf9492016-02-15 22:54:42 +02002314
2315 return offset_aligned;
Daniel Vetterc2c75132012-07-05 12:17:30 +02002316}
2317
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002318static u32 intel_plane_compute_aligned_offset(int *x, int *y,
2319 const struct intel_plane_state *state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002320 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002321{
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002322 struct intel_plane *intel_plane = to_intel_plane(state->base.plane);
2323 struct drm_i915_private *dev_priv = to_i915(intel_plane->base.dev);
Ville Syrjälä29490562016-01-20 18:02:50 +02002324 const struct drm_framebuffer *fb = state->base.fb;
2325 unsigned int rotation = state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002326 int pitch = state->color_plane[color_plane].stride;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03002327 u32 alignment;
2328
2329 if (intel_plane->id == PLANE_CURSOR)
2330 alignment = intel_cursor_alignment(dev_priv);
2331 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002332 alignment = intel_surf_alignment(fb, color_plane);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002333
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002334 return intel_compute_aligned_offset(dev_priv, x, y, fb, color_plane,
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002335 pitch, rotation, alignment);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002336}
2337
Ville Syrjälä303ba692017-08-24 22:10:49 +03002338/* Convert the fb->offset[] into x/y offsets */
2339static int intel_fb_offset_to_xy(int *x, int *y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002340 const struct drm_framebuffer *fb,
2341 int color_plane)
Ville Syrjälä6687c902015-09-15 13:16:41 +03002342{
Ville Syrjälä303ba692017-08-24 22:10:49 +03002343 struct drm_i915_private *dev_priv = to_i915(fb->dev);
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002344 unsigned int height;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002345
Ville Syrjälä303ba692017-08-24 22:10:49 +03002346 if (fb->modifier != DRM_FORMAT_MOD_LINEAR &&
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002347 fb->offsets[color_plane] % intel_tile_size(dev_priv)) {
2348 DRM_DEBUG_KMS("Misaligned offset 0x%08x for color plane %d\n",
2349 fb->offsets[color_plane], color_plane);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002350 return -EINVAL;
Ville Syrjälä70bbe532018-10-23 19:02:01 +03002351 }
2352
2353 height = drm_framebuffer_plane_height(fb->height, fb, color_plane);
2354 height = ALIGN(height, intel_tile_height(fb, color_plane));
2355
2356 /* Catch potential overflows early */
2357 if (add_overflows_t(u32, mul_u32_u32(height, fb->pitches[color_plane]),
2358 fb->offsets[color_plane])) {
2359 DRM_DEBUG_KMS("Bad offset 0x%08x or pitch %d for color plane %d\n",
2360 fb->offsets[color_plane], fb->pitches[color_plane],
2361 color_plane);
2362 return -ERANGE;
2363 }
Ville Syrjälä303ba692017-08-24 22:10:49 +03002364
2365 *x = 0;
2366 *y = 0;
2367
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002368 intel_adjust_aligned_offset(x, y,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002369 fb, color_plane, DRM_MODE_ROTATE_0,
2370 fb->pitches[color_plane],
2371 fb->offsets[color_plane], 0);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002372
2373 return 0;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002374}
2375
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002376static unsigned int intel_fb_modifier_to_tiling(uint64_t fb_modifier)
2377{
2378 switch (fb_modifier) {
2379 case I915_FORMAT_MOD_X_TILED:
2380 return I915_TILING_X;
2381 case I915_FORMAT_MOD_Y_TILED:
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002382 case I915_FORMAT_MOD_Y_TILED_CCS:
Ville Syrjälä72618eb2016-02-04 20:38:20 +02002383 return I915_TILING_Y;
2384 default:
2385 return I915_TILING_NONE;
2386 }
2387}
2388
Ville Syrjälä16af25f2018-01-19 16:41:52 +02002389/*
2390 * From the Sky Lake PRM:
2391 * "The Color Control Surface (CCS) contains the compression status of
2392 * the cache-line pairs. The compression state of the cache-line pair
2393 * is specified by 2 bits in the CCS. Each CCS cache-line represents
2394 * an area on the main surface of 16 x16 sets of 128 byte Y-tiled
2395 * cache-line-pairs. CCS is always Y tiled."
2396 *
2397 * Since cache line pairs refers to horizontally adjacent cache lines,
2398 * each cache line in the CCS corresponds to an area of 32x16 cache
2399 * lines on the main surface. Since each pixel is 4 bytes, this gives
2400 * us a ratio of one byte in the CCS for each 8x16 pixels in the
2401 * main surface.
2402 */
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -07002403static const struct drm_format_info ccs_formats[] = {
2404 { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2405 { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2406 { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2407 { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, },
2408};
2409
2410static const struct drm_format_info *
2411lookup_format_info(const struct drm_format_info formats[],
2412 int num_formats, u32 format)
2413{
2414 int i;
2415
2416 for (i = 0; i < num_formats; i++) {
2417 if (formats[i].format == format)
2418 return &formats[i];
2419 }
2420
2421 return NULL;
2422}
2423
2424static const struct drm_format_info *
2425intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd)
2426{
2427 switch (cmd->modifier[0]) {
2428 case I915_FORMAT_MOD_Y_TILED_CCS:
2429 case I915_FORMAT_MOD_Yf_TILED_CCS:
2430 return lookup_format_info(ccs_formats,
2431 ARRAY_SIZE(ccs_formats),
2432 cmd->pixel_format);
2433 default:
2434 return NULL;
2435 }
2436}
2437
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002438bool is_ccs_modifier(u64 modifier)
2439{
2440 return modifier == I915_FORMAT_MOD_Y_TILED_CCS ||
2441 modifier == I915_FORMAT_MOD_Yf_TILED_CCS;
2442}
2443
Ville Syrjälä6687c902015-09-15 13:16:41 +03002444static int
2445intel_fill_fb_info(struct drm_i915_private *dev_priv,
2446 struct drm_framebuffer *fb)
2447{
2448 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
2449 struct intel_rotation_info *rot_info = &intel_fb->rot_info;
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002450 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002451 u32 gtt_offset_rotated = 0;
2452 unsigned int max_size = 0;
Ville Syrjäläbcb0b462016-12-14 23:30:22 +02002453 int i, num_planes = fb->format->num_planes;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002454 unsigned int tile_size = intel_tile_size(dev_priv);
2455
2456 for (i = 0; i < num_planes; i++) {
2457 unsigned int width, height;
2458 unsigned int cpp, size;
2459 u32 offset;
2460 int x, y;
Ville Syrjälä303ba692017-08-24 22:10:49 +03002461 int ret;
Ville Syrjälä6687c902015-09-15 13:16:41 +03002462
Ville Syrjälä353c8592016-12-14 23:30:57 +02002463 cpp = fb->format->cpp[i];
Ville Syrjälä145fcb12016-11-18 21:53:06 +02002464 width = drm_framebuffer_plane_width(fb->width, fb, i);
2465 height = drm_framebuffer_plane_height(fb->height, fb, i);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002466
Ville Syrjälä303ba692017-08-24 22:10:49 +03002467 ret = intel_fb_offset_to_xy(&x, &y, fb, i);
2468 if (ret) {
2469 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2470 i, fb->offsets[i]);
2471 return ret;
2472 }
Ville Syrjälä6687c902015-09-15 13:16:41 +03002473
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07002474 if (is_ccs_modifier(fb->modifier) && i == 1) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002475 int hsub = fb->format->hsub;
2476 int vsub = fb->format->vsub;
2477 int tile_width, tile_height;
2478 int main_x, main_y;
2479 int ccs_x, ccs_y;
2480
2481 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä303ba692017-08-24 22:10:49 +03002482 tile_width *= hsub;
2483 tile_height *= vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002484
Ville Syrjälä303ba692017-08-24 22:10:49 +03002485 ccs_x = (x * hsub) % tile_width;
2486 ccs_y = (y * vsub) % tile_height;
2487 main_x = intel_fb->normal[0].x % tile_width;
2488 main_y = intel_fb->normal[0].y % tile_height;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002489
2490 /*
2491 * CCS doesn't have its own x/y offset register, so the intra CCS tile
2492 * x/y offsets must match between CCS and the main surface.
2493 */
2494 if (main_x != ccs_x || main_y != ccs_y) {
2495 DRM_DEBUG_KMS("Bad CCS x/y (main %d,%d ccs %d,%d) full (main %d,%d ccs %d,%d)\n",
2496 main_x, main_y,
2497 ccs_x, ccs_y,
2498 intel_fb->normal[0].x,
2499 intel_fb->normal[0].y,
2500 x, y);
2501 return -EINVAL;
2502 }
2503 }
2504
Ville Syrjälä6687c902015-09-15 13:16:41 +03002505 /*
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002506 * The fence (if used) is aligned to the start of the object
2507 * so having the framebuffer wrap around across the edge of the
2508 * fenced region doesn't really work. We have no API to configure
2509 * the fence start offset within the object (nor could we probably
2510 * on gen2/3). So it's just easier if we just require that the
2511 * fb layout agrees with the fence layout. We already check that the
2512 * fb stride matches the fence stride elsewhere.
2513 */
Daniel Stonea5ff7a42018-05-18 15:30:07 +01002514 if (i == 0 && i915_gem_object_is_tiled(obj) &&
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002515 (x + width) * cpp > fb->pitches[i]) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +02002516 DRM_DEBUG_KMS("bad fb plane %d offset: 0x%x\n",
2517 i, fb->offsets[i]);
Ville Syrjälä60d5f2a2016-01-22 18:41:24 +02002518 return -EINVAL;
2519 }
2520
2521 /*
Ville Syrjälä6687c902015-09-15 13:16:41 +03002522 * First pixel of the framebuffer from
2523 * the start of the normal gtt mapping.
2524 */
2525 intel_fb->normal[i].x = x;
2526 intel_fb->normal[i].y = y;
2527
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002528 offset = intel_compute_aligned_offset(dev_priv, &x, &y, fb, i,
2529 fb->pitches[i],
2530 DRM_MODE_ROTATE_0,
2531 tile_size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002532 offset /= tile_size;
2533
Dhinakaran Pandiyan2a11b1b2018-10-26 12:38:04 -07002534 if (!is_surface_linear(fb->modifier, i)) {
Ville Syrjälä6687c902015-09-15 13:16:41 +03002535 unsigned int tile_width, tile_height;
2536 unsigned int pitch_tiles;
2537 struct drm_rect r;
2538
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02002539 intel_tile_dims(fb, i, &tile_width, &tile_height);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002540
2541 rot_info->plane[i].offset = offset;
2542 rot_info->plane[i].stride = DIV_ROUND_UP(fb->pitches[i], tile_width * cpp);
2543 rot_info->plane[i].width = DIV_ROUND_UP(x + width, tile_width);
2544 rot_info->plane[i].height = DIV_ROUND_UP(y + height, tile_height);
2545
2546 intel_fb->rotated[i].pitch =
2547 rot_info->plane[i].height * tile_height;
2548
2549 /* how many tiles does this plane need */
2550 size = rot_info->plane[i].stride * rot_info->plane[i].height;
2551 /*
2552 * If the plane isn't horizontally tile aligned,
2553 * we need one more tile.
2554 */
2555 if (x != 0)
2556 size++;
2557
2558 /* rotate the x/y offsets to match the GTT view */
2559 r.x1 = x;
2560 r.y1 = y;
2561 r.x2 = x + width;
2562 r.y2 = y + height;
2563 drm_rect_rotate(&r,
2564 rot_info->plane[i].width * tile_width,
2565 rot_info->plane[i].height * tile_height,
Robert Fossc2c446a2017-05-19 16:50:17 -04002566 DRM_MODE_ROTATE_270);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002567 x = r.x1;
2568 y = r.y1;
2569
2570 /* rotate the tile dimensions to match the GTT view */
2571 pitch_tiles = intel_fb->rotated[i].pitch / tile_height;
2572 swap(tile_width, tile_height);
2573
2574 /*
2575 * We only keep the x/y offsets, so push all of the
2576 * gtt offset into the x/y offsets.
2577 */
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002578 intel_adjust_tile_offset(&x, &y,
2579 tile_width, tile_height,
2580 tile_size, pitch_tiles,
2581 gtt_offset_rotated * tile_size, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002582
2583 gtt_offset_rotated += rot_info->plane[i].width * rot_info->plane[i].height;
2584
2585 /*
2586 * First pixel of the framebuffer from
2587 * the start of the rotated gtt mapping.
2588 */
2589 intel_fb->rotated[i].x = x;
2590 intel_fb->rotated[i].y = y;
2591 } else {
2592 size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
2593 x * cpp, tile_size);
2594 }
2595
2596 /* how many tiles in total needed in the bo */
2597 max_size = max(max_size, offset + size);
2598 }
2599
Ville Syrjälä4e050472018-09-12 21:04:43 +03002600 if (mul_u32_u32(max_size, tile_size) > obj->base.size) {
2601 DRM_DEBUG_KMS("fb too big for bo (need %llu bytes, have %zu bytes)\n",
2602 mul_u32_u32(max_size, tile_size), obj->base.size);
Ville Syrjälä6687c902015-09-15 13:16:41 +03002603 return -EINVAL;
2604 }
2605
2606 return 0;
2607}
2608
Damien Lespiaub35d63f2015-01-20 12:51:50 +00002609static int i9xx_format_to_fourcc(int format)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002610{
2611 switch (format) {
2612 case DISPPLANE_8BPP:
2613 return DRM_FORMAT_C8;
2614 case DISPPLANE_BGRX555:
2615 return DRM_FORMAT_XRGB1555;
2616 case DISPPLANE_BGRX565:
2617 return DRM_FORMAT_RGB565;
2618 default:
2619 case DISPPLANE_BGRX888:
2620 return DRM_FORMAT_XRGB8888;
2621 case DISPPLANE_RGBX888:
2622 return DRM_FORMAT_XBGR8888;
2623 case DISPPLANE_BGRX101010:
2624 return DRM_FORMAT_XRGB2101010;
2625 case DISPPLANE_RGBX101010:
2626 return DRM_FORMAT_XBGR2101010;
2627 }
2628}
2629
Mahesh Kumarddf34312018-04-09 09:11:03 +05302630int skl_format_to_fourcc(int format, bool rgb_order, bool alpha)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002631{
2632 switch (format) {
2633 case PLANE_CTL_FORMAT_RGB_565:
2634 return DRM_FORMAT_RGB565;
Mahesh Kumarf34a2912018-04-09 09:11:02 +05302635 case PLANE_CTL_FORMAT_NV12:
2636 return DRM_FORMAT_NV12;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00002637 default:
2638 case PLANE_CTL_FORMAT_XRGB_8888:
2639 if (rgb_order) {
2640 if (alpha)
2641 return DRM_FORMAT_ABGR8888;
2642 else
2643 return DRM_FORMAT_XBGR8888;
2644 } else {
2645 if (alpha)
2646 return DRM_FORMAT_ARGB8888;
2647 else
2648 return DRM_FORMAT_XRGB8888;
2649 }
2650 case PLANE_CTL_FORMAT_XRGB_2101010:
2651 if (rgb_order)
2652 return DRM_FORMAT_XBGR2101010;
2653 else
2654 return DRM_FORMAT_XRGB2101010;
2655 }
2656}
2657
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002658static bool
Daniel Vetterf6936e22015-03-26 12:17:05 +01002659intel_alloc_initial_plane_obj(struct intel_crtc *crtc,
2660 struct intel_initial_plane_config *plane_config)
Jesse Barnes46f297f2014-03-07 08:57:48 -08002661{
2662 struct drm_device *dev = crtc->base.dev;
Paulo Zanoni3badb492015-09-23 12:52:23 -03002663 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002664 struct drm_i915_gem_object *obj = NULL;
2665 struct drm_mode_fb_cmd2 mode_cmd = { 0 };
Damien Lespiau2d140302015-02-05 17:22:18 +00002666 struct drm_framebuffer *fb = &plane_config->fb->base;
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002667 u32 base_aligned = round_down(plane_config->base, PAGE_SIZE);
2668 u32 size_aligned = round_up(plane_config->base + plane_config->size,
2669 PAGE_SIZE);
2670
2671 size_aligned -= base_aligned;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002672
Chris Wilsonff2652e2014-03-10 08:07:02 +00002673 if (plane_config->size == 0)
2674 return false;
2675
Paulo Zanoni3badb492015-09-23 12:52:23 -03002676 /* If the FB is too big, just don't use it since fbdev is not very
2677 * important and we should probably use that space with FBC or other
2678 * features. */
Matthew Auldb1ace602017-12-11 15:18:21 +00002679 if (size_aligned * 2 > dev_priv->stolen_usable_size)
Paulo Zanoni3badb492015-09-23 12:52:23 -03002680 return false;
2681
Imre Deak914a4fd2018-10-16 19:00:11 +03002682 switch (fb->modifier) {
2683 case DRM_FORMAT_MOD_LINEAR:
2684 case I915_FORMAT_MOD_X_TILED:
2685 case I915_FORMAT_MOD_Y_TILED:
2686 break;
2687 default:
2688 DRM_DEBUG_DRIVER("Unsupported modifier for initial FB: 0x%llx\n",
2689 fb->modifier);
2690 return false;
2691 }
2692
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002693 mutex_lock(&dev->struct_mutex);
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00002694 obj = i915_gem_object_create_stolen_for_preallocated(dev_priv,
Daniel Vetterf37b5c22015-02-10 23:12:27 +01002695 base_aligned,
2696 base_aligned,
2697 size_aligned);
Chris Wilson24dbf512017-02-15 10:59:18 +00002698 mutex_unlock(&dev->struct_mutex);
2699 if (!obj)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002700 return false;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002701
Imre Deak914a4fd2018-10-16 19:00:11 +03002702 switch (plane_config->tiling) {
2703 case I915_TILING_NONE:
2704 break;
2705 case I915_TILING_X:
2706 case I915_TILING_Y:
2707 obj->tiling_and_stride = fb->pitches[0] | plane_config->tiling;
2708 break;
2709 default:
2710 MISSING_CASE(plane_config->tiling);
2711 return false;
2712 }
Jesse Barnes46f297f2014-03-07 08:57:48 -08002713
Ville Syrjälä438b74a2016-12-14 23:32:55 +02002714 mode_cmd.pixel_format = fb->format->format;
Damien Lespiau6bf129d2015-02-05 17:22:16 +00002715 mode_cmd.width = fb->width;
2716 mode_cmd.height = fb->height;
2717 mode_cmd.pitches[0] = fb->pitches[0];
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002718 mode_cmd.modifier[0] = fb->modifier;
Daniel Vetter18c52472015-02-10 17:16:09 +00002719 mode_cmd.flags = DRM_MODE_FB_MODIFIERS;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002720
Chris Wilson24dbf512017-02-15 10:59:18 +00002721 if (intel_framebuffer_init(to_intel_framebuffer(fb), obj, &mode_cmd)) {
Jesse Barnes46f297f2014-03-07 08:57:48 -08002722 DRM_DEBUG_KMS("intel fb init failed\n");
2723 goto out_unref_obj;
2724 }
Tvrtko Ursulin12c83d92016-02-11 10:27:29 +00002725
Jesse Barnes484b41d2014-03-07 08:57:55 -08002726
Daniel Vetterf6936e22015-03-26 12:17:05 +01002727 DRM_DEBUG_KMS("initial plane fb obj %p\n", obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002728 return true;
Jesse Barnes46f297f2014-03-07 08:57:48 -08002729
2730out_unref_obj:
Chris Wilsonf8c417c2016-07-20 13:31:53 +01002731 i915_gem_object_put(obj);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002732 return false;
2733}
2734
Damien Lespiau5724dbd2015-01-20 12:51:52 +00002735static void
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002736intel_set_plane_visible(struct intel_crtc_state *crtc_state,
2737 struct intel_plane_state *plane_state,
2738 bool visible)
2739{
2740 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
2741
2742 plane_state->base.visible = visible;
2743
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002744 if (visible)
Ville Syrjälä40560e22018-06-26 22:47:11 +03002745 crtc_state->base.plane_mask |= drm_plane_mask(&plane->base);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002746 else
Ville Syrjälä40560e22018-06-26 22:47:11 +03002747 crtc_state->base.plane_mask &= ~drm_plane_mask(&plane->base);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002748}
2749
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002750static void fixup_active_planes(struct intel_crtc_state *crtc_state)
2751{
2752 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
2753 struct drm_plane *plane;
2754
2755 /*
2756 * Active_planes aliases if multiple "primary" or cursor planes
2757 * have been used on the same (or wrong) pipe. plane_mask uses
2758 * unique ids, hence we can use that to reconstruct active_planes.
2759 */
2760 crtc_state->active_planes = 0;
2761
2762 drm_for_each_plane_mask(plane, &dev_priv->drm,
2763 crtc_state->base.plane_mask)
2764 crtc_state->active_planes |= BIT(to_intel_plane(plane)->id);
2765}
2766
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002767static void intel_plane_disable_noatomic(struct intel_crtc *crtc,
2768 struct intel_plane *plane)
2769{
2770 struct intel_crtc_state *crtc_state =
2771 to_intel_crtc_state(crtc->base.state);
2772 struct intel_plane_state *plane_state =
2773 to_intel_plane_state(plane->base.state);
2774
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +03002775 DRM_DEBUG_KMS("Disabling [PLANE:%d:%s] on [CRTC:%d:%s]\n",
2776 plane->base.base.id, plane->base.name,
2777 crtc->base.base.id, crtc->base.name);
2778
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002779 intel_set_plane_visible(crtc_state, plane_state, false);
Ville Syrjälä62358aa2018-10-03 17:50:17 +03002780 fixup_active_planes(crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002781
2782 if (plane->id == PLANE_PRIMARY)
2783 intel_pre_disable_primary_noatomic(&crtc->base);
2784
2785 trace_intel_disable_plane(&plane->base, crtc);
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02002786 plane->disable_plane(plane, crtc_state);
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002787}
2788
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002789static void
Daniel Vetterf6936e22015-03-26 12:17:05 +01002790intel_find_initial_plane_obj(struct intel_crtc *intel_crtc,
2791 struct intel_initial_plane_config *plane_config)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002792{
2793 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002794 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002795 struct drm_crtc *c;
Matt Roper2ff8fde2014-07-08 07:50:07 -07002796 struct drm_i915_gem_object *obj;
Daniel Vetter88595ac2015-03-26 12:42:24 +01002797 struct drm_plane *primary = intel_crtc->base.primary;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002798 struct drm_plane_state *plane_state = primary->state;
Matt Roper200757f2015-12-03 11:37:36 -08002799 struct intel_plane *intel_plane = to_intel_plane(primary);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002800 struct intel_plane_state *intel_state =
2801 to_intel_plane_state(plane_state);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002802 struct drm_framebuffer *fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002803
Damien Lespiau2d140302015-02-05 17:22:18 +00002804 if (!plane_config->fb)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002805 return;
2806
Daniel Vetterf6936e22015-03-26 12:17:05 +01002807 if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) {
Daniel Vetter88595ac2015-03-26 12:42:24 +01002808 fb = &plane_config->fb->base;
2809 goto valid_fb;
Damien Lespiauf55548b2015-02-05 18:30:20 +00002810 }
Jesse Barnes484b41d2014-03-07 08:57:55 -08002811
Damien Lespiau2d140302015-02-05 17:22:18 +00002812 kfree(plane_config->fb);
Jesse Barnes484b41d2014-03-07 08:57:55 -08002813
2814 /*
2815 * Failed to alloc the obj, check to see if we should share
2816 * an fb with another CRTC instead
2817 */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +01002818 for_each_crtc(dev, c) {
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002819 struct intel_plane_state *state;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002820
2821 if (c == &intel_crtc->base)
2822 continue;
2823
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002824 if (!to_intel_crtc(c)->active)
Jesse Barnes484b41d2014-03-07 08:57:55 -08002825 continue;
2826
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002827 state = to_intel_plane_state(c->primary->state);
2828 if (!state->vma)
Matt Roper2ff8fde2014-07-08 07:50:07 -07002829 continue;
2830
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002831 if (intel_plane_ggtt_offset(state) == plane_config->base) {
Ville Syrjälä8bc20f62018-03-22 17:22:59 +02002832 fb = state->base.fb;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302833 drm_framebuffer_get(fb);
Daniel Vetter88595ac2015-03-26 12:42:24 +01002834 goto valid_fb;
Jesse Barnes484b41d2014-03-07 08:57:55 -08002835 }
2836 }
Daniel Vetter88595ac2015-03-26 12:42:24 +01002837
Matt Roper200757f2015-12-03 11:37:36 -08002838 /*
2839 * We've failed to reconstruct the BIOS FB. Current display state
2840 * indicates that the primary plane is visible, but has a NULL FB,
2841 * which will lead to problems later if we don't fix it up. The
2842 * simplest solution is to just disable the primary plane now and
2843 * pretend the BIOS never had it enabled.
2844 */
Ville Syrjäläb1e01592017-11-17 21:19:09 +02002845 intel_plane_disable_noatomic(intel_crtc, intel_plane);
Matt Roper200757f2015-12-03 11:37:36 -08002846
Daniel Vetter88595ac2015-03-26 12:42:24 +01002847 return;
2848
2849valid_fb:
Ville Syrjäläf43348a2018-11-20 15:54:50 +02002850 intel_state->base.rotation = plane_config->rotation;
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002851 intel_fill_fb_ggtt_view(&intel_state->view, fb,
2852 intel_state->base.rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03002853 intel_state->color_plane[0].stride =
2854 intel_fb_pitch(fb, 0, intel_state->base.rotation);
2855
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002856 mutex_lock(&dev->struct_mutex);
2857 intel_state->vma =
Chris Wilson59354852018-02-20 13:42:06 +00002858 intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +03002859 &intel_state->view,
Ville Syrjäläf7a02ad2018-02-21 20:48:07 +02002860 intel_plane_uses_fence(intel_state),
Chris Wilson59354852018-02-20 13:42:06 +00002861 &intel_state->flags);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002862 mutex_unlock(&dev->struct_mutex);
2863 if (IS_ERR(intel_state->vma)) {
2864 DRM_ERROR("failed to pin boot fb on pipe %d: %li\n",
2865 intel_crtc->pipe, PTR_ERR(intel_state->vma));
2866
2867 intel_state->vma = NULL;
Harsha Sharmac3ed1102017-10-09 17:36:43 +05302868 drm_framebuffer_put(fb);
Chris Wilsonbe1e3412017-01-16 15:21:27 +00002869 return;
2870 }
2871
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -08002872 obj = intel_fb_obj(fb);
2873 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
2874
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002875 plane_state->src_x = 0;
2876 plane_state->src_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002877 plane_state->src_w = fb->width << 16;
2878 plane_state->src_h = fb->height << 16;
2879
Ville Syrjäläf44e2652015-11-13 19:16:13 +02002880 plane_state->crtc_x = 0;
2881 plane_state->crtc_y = 0;
Maarten Lankhorstbe5651f2015-07-13 16:30:18 +02002882 plane_state->crtc_w = fb->width;
2883 plane_state->crtc_h = fb->height;
2884
Rob Clark1638d302016-11-05 11:08:08 -04002885 intel_state->base.src = drm_plane_state_src(plane_state);
2886 intel_state->base.dst = drm_plane_state_dest(plane_state);
Matt Roper0a8d8a82015-12-03 11:37:38 -08002887
Chris Wilson3e510a82016-08-05 10:14:23 +01002888 if (i915_gem_object_is_tiled(obj))
Daniel Vetter88595ac2015-03-26 12:42:24 +01002889 dev_priv->preserve_bios_swizzle = true;
2890
Ville Syrjäläcd30fbc2018-05-25 21:50:40 +03002891 plane_state->fb = fb;
2892 plane_state->crtc = &intel_crtc->base;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +02002893
Chris Wilsonfaf5bf02016-08-04 16:32:37 +01002894 atomic_or(to_intel_plane(primary)->frontbuffer_bit,
2895 &obj->frontbuffer_bits);
Jesse Barnes46f297f2014-03-07 08:57:48 -08002896}
2897
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002898static int skl_max_plane_width(const struct drm_framebuffer *fb,
2899 int color_plane,
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002900 unsigned int rotation)
2901{
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03002902 int cpp = fb->format->cpp[color_plane];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002903
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002904 switch (fb->modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07002905 case DRM_FORMAT_MOD_LINEAR:
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002906 case I915_FORMAT_MOD_X_TILED:
2907 switch (cpp) {
2908 case 8:
2909 return 4096;
2910 case 4:
2911 case 2:
2912 case 1:
2913 return 8192;
2914 default:
2915 MISSING_CASE(cpp);
2916 break;
2917 }
2918 break;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002919 case I915_FORMAT_MOD_Y_TILED_CCS:
2920 case I915_FORMAT_MOD_Yf_TILED_CCS:
2921 /* FIXME AUX plane? */
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002922 case I915_FORMAT_MOD_Y_TILED:
2923 case I915_FORMAT_MOD_Yf_TILED:
2924 switch (cpp) {
2925 case 8:
2926 return 2048;
2927 case 4:
2928 return 4096;
2929 case 2:
2930 case 1:
2931 return 8192;
2932 default:
2933 MISSING_CASE(cpp);
2934 break;
2935 }
2936 break;
2937 default:
Ville Syrjäläbae781b2016-11-16 13:33:16 +02002938 MISSING_CASE(fb->modifier);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002939 }
2940
2941 return 2048;
2942}
2943
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002944static bool skl_check_main_ccs_coordinates(struct intel_plane_state *plane_state,
2945 int main_x, int main_y, u32 main_offset)
2946{
2947 const struct drm_framebuffer *fb = plane_state->base.fb;
2948 int hsub = fb->format->hsub;
2949 int vsub = fb->format->vsub;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002950 int aux_x = plane_state->color_plane[1].x;
2951 int aux_y = plane_state->color_plane[1].y;
2952 u32 aux_offset = plane_state->color_plane[1].offset;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002953 u32 alignment = intel_surf_alignment(fb, 1);
2954
2955 while (aux_offset >= main_offset && aux_y <= main_y) {
2956 int x, y;
2957
2958 if (aux_x == main_x && aux_y == main_y)
2959 break;
2960
2961 if (aux_offset == 0)
2962 break;
2963
2964 x = aux_x / hsub;
2965 y = aux_y / vsub;
Ville Syrjälä6d19a442018-09-07 18:24:01 +03002966 aux_offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 1,
2967 aux_offset, aux_offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002968 aux_x = x * hsub + aux_x % hsub;
2969 aux_y = y * vsub + aux_y % vsub;
2970 }
2971
2972 if (aux_x != main_x || aux_y != main_y)
2973 return false;
2974
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002975 plane_state->color_plane[1].offset = aux_offset;
2976 plane_state->color_plane[1].x = aux_x;
2977 plane_state->color_plane[1].y = aux_y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07002978
2979 return true;
2980}
2981
Ville Syrjälä73266592018-09-07 18:24:11 +03002982static int skl_check_main_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002983{
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002984 const struct drm_framebuffer *fb = plane_state->base.fb;
2985 unsigned int rotation = plane_state->base.rotation;
Daniel Vettercc926382016-08-15 10:41:47 +02002986 int x = plane_state->base.src.x1 >> 16;
2987 int y = plane_state->base.src.y1 >> 16;
2988 int w = drm_rect_width(&plane_state->base.src) >> 16;
2989 int h = drm_rect_height(&plane_state->base.src) >> 16;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002990 int max_width = skl_max_plane_width(fb, 0, rotation);
2991 int max_height = 4096;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03002992 u32 alignment, offset, aux_offset = plane_state->color_plane[1].offset;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02002993
2994 if (w > max_width || h > max_height) {
2995 DRM_DEBUG_KMS("requested Y/RGB source size %dx%d too big (limit %dx%d)\n",
2996 w, h, max_width, max_height);
2997 return -EINVAL;
2998 }
2999
3000 intel_add_fb_offsets(&x, &y, plane_state, 0);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003001 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 0);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003002 alignment = intel_surf_alignment(fb, 0);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003003
3004 /*
Ville Syrjälä8d970652016-01-28 16:30:28 +02003005 * AUX surface offset is specified as the distance from the
3006 * main surface offset, and it must be non-negative. Make
3007 * sure that is what we will get.
3008 */
3009 if (offset > aux_offset)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003010 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3011 offset, aux_offset & ~(alignment - 1));
Ville Syrjälä8d970652016-01-28 16:30:28 +02003012
3013 /*
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003014 * When using an X-tiled surface, the plane blows up
3015 * if the x offset + width exceed the stride.
3016 *
3017 * TODO: linear and Y-tiled seem fine, Yf untested,
3018 */
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003019 if (fb->modifier == I915_FORMAT_MOD_X_TILED) {
Ville Syrjälä353c8592016-12-14 23:30:57 +02003020 int cpp = fb->format->cpp[0];
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003021
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003022 while ((x + w) * cpp > plane_state->color_plane[0].stride) {
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003023 if (offset == 0) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003024 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to X-tiling\n");
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003025 return -EINVAL;
3026 }
3027
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003028 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3029 offset, offset - alignment);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003030 }
3031 }
3032
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003033 /*
3034 * CCS AUX surface doesn't have its own x/y offsets, we must make sure
3035 * they match with the main surface x/y offsets.
3036 */
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003037 if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003038 while (!skl_check_main_ccs_coordinates(plane_state, x, y, offset)) {
3039 if (offset == 0)
3040 break;
3041
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003042 offset = intel_plane_adjust_aligned_offset(&x, &y, plane_state, 0,
3043 offset, offset - alignment);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003044 }
3045
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003046 if (x != plane_state->color_plane[1].x || y != plane_state->color_plane[1].y) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003047 DRM_DEBUG_KMS("Unable to find suitable display surface offset due to CCS\n");
3048 return -EINVAL;
3049 }
3050 }
3051
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003052 plane_state->color_plane[0].offset = offset;
3053 plane_state->color_plane[0].x = x;
3054 plane_state->color_plane[0].y = y;
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003055
3056 return 0;
3057}
3058
Ville Syrjälä8d970652016-01-28 16:30:28 +02003059static int skl_check_nv12_aux_surface(struct intel_plane_state *plane_state)
3060{
3061 const struct drm_framebuffer *fb = plane_state->base.fb;
3062 unsigned int rotation = plane_state->base.rotation;
3063 int max_width = skl_max_plane_width(fb, 1, rotation);
3064 int max_height = 4096;
Daniel Vettercc926382016-08-15 10:41:47 +02003065 int x = plane_state->base.src.x1 >> 17;
3066 int y = plane_state->base.src.y1 >> 17;
3067 int w = drm_rect_width(&plane_state->base.src) >> 17;
3068 int h = drm_rect_height(&plane_state->base.src) >> 17;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003069 u32 offset;
3070
3071 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003072 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä8d970652016-01-28 16:30:28 +02003073
3074 /* FIXME not quite sure how/if these apply to the chroma plane */
3075 if (w > max_width || h > max_height) {
3076 DRM_DEBUG_KMS("CbCr source size %dx%d too big (limit %dx%d)\n",
3077 w, h, max_width, max_height);
3078 return -EINVAL;
3079 }
3080
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003081 plane_state->color_plane[1].offset = offset;
3082 plane_state->color_plane[1].x = x;
3083 plane_state->color_plane[1].y = y;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003084
3085 return 0;
3086}
3087
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003088static int skl_check_ccs_aux_surface(struct intel_plane_state *plane_state)
3089{
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003090 const struct drm_framebuffer *fb = plane_state->base.fb;
3091 int src_x = plane_state->base.src.x1 >> 16;
3092 int src_y = plane_state->base.src.y1 >> 16;
3093 int hsub = fb->format->hsub;
3094 int vsub = fb->format->vsub;
3095 int x = src_x / hsub;
3096 int y = src_y / vsub;
3097 u32 offset;
3098
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003099 intel_add_fb_offsets(&x, &y, plane_state, 1);
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003100 offset = intel_plane_compute_aligned_offset(&x, &y, plane_state, 1);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003101
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003102 plane_state->color_plane[1].offset = offset;
3103 plane_state->color_plane[1].x = x * hsub + src_x % hsub;
3104 plane_state->color_plane[1].y = y * vsub + src_y % vsub;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003105
3106 return 0;
3107}
3108
Ville Syrjälä73266592018-09-07 18:24:11 +03003109int skl_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003110{
3111 const struct drm_framebuffer *fb = plane_state->base.fb;
3112 unsigned int rotation = plane_state->base.rotation;
3113 int ret;
3114
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003115 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003116 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3117 plane_state->color_plane[1].stride = intel_fb_pitch(fb, 1, rotation);
3118
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003119 ret = intel_plane_check_stride(plane_state);
3120 if (ret)
3121 return ret;
3122
Ville Syrjäläa5e4c7d2016-11-07 22:20:54 +02003123 if (!plane_state->base.visible)
3124 return 0;
3125
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003126 /* Rotate src coordinates to match rotated GTT view */
Ville Syrjäläbd2ef252016-09-26 19:30:46 +03003127 if (drm_rotation_90_or_270(rotation))
Daniel Vettercc926382016-08-15 10:41:47 +02003128 drm_rect_rotate(&plane_state->base.src,
Ville Syrjäläda064b42016-10-24 19:13:04 +03003129 fb->width << 16, fb->height << 16,
Robert Fossc2c446a2017-05-19 16:50:17 -04003130 DRM_MODE_ROTATE_270);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003131
Ville Syrjälä8d970652016-01-28 16:30:28 +02003132 /*
3133 * Handle the AUX surface first since
3134 * the main surface setup depends on it.
3135 */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003136 if (fb->format->format == DRM_FORMAT_NV12) {
Ville Syrjälä8d970652016-01-28 16:30:28 +02003137 ret = skl_check_nv12_aux_surface(plane_state);
3138 if (ret)
3139 return ret;
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -07003140 } else if (is_ccs_modifier(fb->modifier)) {
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003141 ret = skl_check_ccs_aux_surface(plane_state);
3142 if (ret)
3143 return ret;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003144 } else {
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003145 plane_state->color_plane[1].offset = ~0xfff;
3146 plane_state->color_plane[1].x = 0;
3147 plane_state->color_plane[1].y = 0;
Ville Syrjälä8d970652016-01-28 16:30:28 +02003148 }
3149
Ville Syrjälä73266592018-09-07 18:24:11 +03003150 ret = skl_check_main_surface(plane_state);
Ville Syrjäläb63a16f2016-01-28 16:53:54 +02003151 if (ret)
3152 return ret;
3153
3154 return 0;
3155}
3156
Ville Syrjäläddd57132018-09-07 18:24:02 +03003157unsigned int
3158i9xx_plane_max_stride(struct intel_plane *plane,
3159 u32 pixel_format, u64 modifier,
3160 unsigned int rotation)
3161{
3162 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3163
3164 if (!HAS_GMCH_DISPLAY(dev_priv)) {
3165 return 32*1024;
3166 } else if (INTEL_GEN(dev_priv) >= 4) {
3167 if (modifier == I915_FORMAT_MOD_X_TILED)
3168 return 16*1024;
3169 else
3170 return 32*1024;
3171 } else if (INTEL_GEN(dev_priv) >= 3) {
3172 if (modifier == I915_FORMAT_MOD_X_TILED)
3173 return 8*1024;
3174 else
3175 return 16*1024;
3176 } else {
3177 if (plane->i9xx_plane == PLANE_C)
3178 return 4*1024;
3179 else
3180 return 8*1024;
3181 }
3182}
3183
Ville Syrjälä7145f602017-03-23 21:27:07 +02003184static u32 i9xx_plane_ctl(const struct intel_crtc_state *crtc_state,
3185 const struct intel_plane_state *plane_state)
Jesse Barnes81255562010-08-02 12:07:50 -07003186{
Ville Syrjälä7145f602017-03-23 21:27:07 +02003187 struct drm_i915_private *dev_priv =
3188 to_i915(plane_state->base.plane->dev);
3189 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
3190 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä8d0deca2016-02-15 22:54:41 +02003191 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003192 u32 dspcntr;
Ville Syrjäläc9ba6fa2014-08-27 17:48:41 +03003193
Ville Syrjälä7145f602017-03-23 21:27:07 +02003194 dspcntr = DISPLAY_PLANE_ENABLE | DISPPLANE_GAMMA_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003195
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003196 if (IS_G4X(dev_priv) || IS_GEN(dev_priv, 5) ||
3197 IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjälä7145f602017-03-23 21:27:07 +02003198 dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003199
Ville Syrjälä6a4407a2017-03-23 21:27:08 +02003200 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
3201 dspcntr |= DISPPLANE_PIPE_CSC_ENABLE;
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003202
Ville Syrjäläc154d1e2018-01-30 22:38:02 +02003203 if (INTEL_GEN(dev_priv) < 5)
Ville Syrjäläd509e282017-03-27 21:55:32 +03003204 dspcntr |= DISPPLANE_SEL_PIPE(crtc->pipe);
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003205
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003206 switch (fb->format->format) {
Ville Syrjälä57779d02012-10-31 17:50:14 +02003207 case DRM_FORMAT_C8:
Jesse Barnes81255562010-08-02 12:07:50 -07003208 dspcntr |= DISPPLANE_8BPP;
3209 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003210 case DRM_FORMAT_XRGB1555:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003211 dspcntr |= DISPPLANE_BGRX555;
Jesse Barnes81255562010-08-02 12:07:50 -07003212 break;
Ville Syrjälä57779d02012-10-31 17:50:14 +02003213 case DRM_FORMAT_RGB565:
3214 dspcntr |= DISPPLANE_BGRX565;
3215 break;
3216 case DRM_FORMAT_XRGB8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003217 dspcntr |= DISPPLANE_BGRX888;
3218 break;
3219 case DRM_FORMAT_XBGR8888:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003220 dspcntr |= DISPPLANE_RGBX888;
3221 break;
3222 case DRM_FORMAT_XRGB2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003223 dspcntr |= DISPPLANE_BGRX101010;
3224 break;
3225 case DRM_FORMAT_XBGR2101010:
Ville Syrjälä57779d02012-10-31 17:50:14 +02003226 dspcntr |= DISPPLANE_RGBX101010;
Jesse Barnes81255562010-08-02 12:07:50 -07003227 break;
3228 default:
Ville Syrjälä7145f602017-03-23 21:27:07 +02003229 MISSING_CASE(fb->format->format);
3230 return 0;
Jesse Barnes81255562010-08-02 12:07:50 -07003231 }
Ville Syrjälä57779d02012-10-31 17:50:14 +02003232
Ville Syrjälä72618eb2016-02-04 20:38:20 +02003233 if (INTEL_GEN(dev_priv) >= 4 &&
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003234 fb->modifier == I915_FORMAT_MOD_X_TILED)
Ville Syrjäläf45651b2014-08-08 21:51:10 +03003235 dspcntr |= DISPPLANE_TILED;
Jesse Barnes81255562010-08-02 12:07:50 -07003236
Robert Fossc2c446a2017-05-19 16:50:17 -04003237 if (rotation & DRM_MODE_ROTATE_180)
Ville Syrjälädf0cd452016-11-14 18:53:59 +02003238 dspcntr |= DISPPLANE_ROTATE_180;
3239
Robert Fossc2c446a2017-05-19 16:50:17 -04003240 if (rotation & DRM_MODE_REFLECT_X)
Ville Syrjälä4ea7be22016-11-14 18:54:00 +02003241 dspcntr |= DISPPLANE_MIRROR;
3242
Ville Syrjälä7145f602017-03-23 21:27:07 +02003243 return dspcntr;
3244}
Ville Syrjäläde1aa622013-06-07 10:47:01 +03003245
Ville Syrjäläf9407ae2017-03-23 21:27:12 +02003246int i9xx_check_plane_surface(struct intel_plane_state *plane_state)
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003247{
3248 struct drm_i915_private *dev_priv =
3249 to_i915(plane_state->base.plane->dev);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003250 const struct drm_framebuffer *fb = plane_state->base.fb;
3251 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003252 int src_x = plane_state->base.src.x1 >> 16;
3253 int src_y = plane_state->base.src.y1 >> 16;
3254 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003255 int ret;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003256
Ville Syrjäläf5929c52018-09-07 18:24:06 +03003257 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003258 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
3259
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03003260 ret = intel_plane_check_stride(plane_state);
3261 if (ret)
3262 return ret;
3263
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003264 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
Jesse Barnes81255562010-08-02 12:07:50 -07003265
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003266 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä6d19a442018-09-07 18:24:01 +03003267 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
3268 plane_state, 0);
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003269 else
3270 offset = 0;
Daniel Vettere506a0c2012-07-05 12:17:29 +02003271
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003272 /* HSW/BDW do this automagically in hardware */
3273 if (!IS_HASWELL(dev_priv) && !IS_BROADWELL(dev_priv)) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003274 int src_w = drm_rect_width(&plane_state->base.src) >> 16;
3275 int src_h = drm_rect_height(&plane_state->base.src) >> 16;
3276
Robert Fossc2c446a2017-05-19 16:50:17 -04003277 if (rotation & DRM_MODE_ROTATE_180) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003278 src_x += src_w - 1;
3279 src_y += src_h - 1;
Robert Fossc2c446a2017-05-19 16:50:17 -04003280 } else if (rotation & DRM_MODE_REFLECT_X) {
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003281 src_x += src_w - 1;
3282 }
Sonika Jindal48404c12014-08-22 14:06:04 +05303283 }
3284
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003285 plane_state->color_plane[0].offset = offset;
3286 plane_state->color_plane[0].x = src_x;
3287 plane_state->color_plane[0].y = src_y;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003288
3289 return 0;
3290}
3291
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003292static int
3293i9xx_plane_check(struct intel_crtc_state *crtc_state,
3294 struct intel_plane_state *plane_state)
3295{
3296 int ret;
3297
Ville Syrjälä25721f82018-09-07 18:24:12 +03003298 ret = chv_plane_check_rotation(plane_state);
3299 if (ret)
3300 return ret;
3301
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03003302 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
3303 &crtc_state->base,
3304 DRM_PLANE_HELPER_NO_SCALING,
3305 DRM_PLANE_HELPER_NO_SCALING,
3306 false, true);
3307 if (ret)
3308 return ret;
3309
3310 if (!plane_state->base.visible)
3311 return 0;
3312
3313 ret = intel_plane_check_src_coordinates(plane_state);
3314 if (ret)
3315 return ret;
3316
3317 ret = i9xx_check_plane_surface(plane_state);
3318 if (ret)
3319 return ret;
3320
3321 plane_state->ctl = i9xx_plane_ctl(crtc_state, plane_state);
3322
3323 return 0;
3324}
3325
Ville Syrjäläed150302017-11-17 21:19:10 +02003326static void i9xx_update_plane(struct intel_plane *plane,
3327 const struct intel_crtc_state *crtc_state,
3328 const struct intel_plane_state *plane_state)
Ville Syrjälä7145f602017-03-23 21:27:07 +02003329{
Ville Syrjäläed150302017-11-17 21:19:10 +02003330 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläed150302017-11-17 21:19:10 +02003331 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003332 u32 linear_offset;
Ville Syrjäläa0864d52017-03-23 21:27:09 +02003333 u32 dspcntr = plane_state->ctl;
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003334 int x = plane_state->color_plane[0].x;
3335 int y = plane_state->color_plane[0].y;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003336 unsigned long irqflags;
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003337 u32 dspaddr_offset;
Ville Syrjälä7145f602017-03-23 21:27:07 +02003338
Ville Syrjälä29490562016-01-20 18:02:50 +02003339 linear_offset = intel_fb_xy_to_linear(x, y, plane_state, 0);
Ville Syrjälä6687c902015-09-15 13:16:41 +03003340
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003341 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläc11ada02018-09-07 18:24:04 +03003342 dspaddr_offset = plane_state->color_plane[0].offset;
Ville Syrjälä5b7fcc42017-03-23 21:27:10 +02003343 else
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003344 dspaddr_offset = linear_offset;
Ville Syrjälä6687c902015-09-15 13:16:41 +03003345
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003346 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3347
Ville Syrjälä83234d12018-11-14 23:07:17 +02003348 I915_WRITE_FW(DSPSTRIDE(i9xx_plane), plane_state->color_plane[0].stride);
3349
Ville Syrjälä78587de2017-03-09 17:44:32 +02003350 if (INTEL_GEN(dev_priv) < 4) {
3351 /* pipesrc and dspsize control the size that is scaled from,
3352 * which should always be the user's requested size.
3353 */
Ville Syrjälä83234d12018-11-14 23:07:17 +02003354 I915_WRITE_FW(DSPPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003355 I915_WRITE_FW(DSPSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003356 ((crtc_state->pipe_src_h - 1) << 16) |
3357 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003358 } else if (IS_CHERRYVIEW(dev_priv) && i9xx_plane == PLANE_B) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003359 I915_WRITE_FW(PRIMPOS(i9xx_plane), 0);
Ville Syrjäläed150302017-11-17 21:19:10 +02003360 I915_WRITE_FW(PRIMSIZE(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003361 ((crtc_state->pipe_src_h - 1) << 16) |
3362 (crtc_state->pipe_src_w - 1));
Ville Syrjäläed150302017-11-17 21:19:10 +02003363 I915_WRITE_FW(PRIMCNSTALPHA(i9xx_plane), 0);
Ville Syrjälä78587de2017-03-09 17:44:32 +02003364 }
3365
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003366 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Ville Syrjäläed150302017-11-17 21:19:10 +02003367 I915_WRITE_FW(DSPOFFSET(i9xx_plane), (y << 16) | x);
Ville Syrjälä3ba35e52017-03-23 21:27:11 +02003368 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä83234d12018-11-14 23:07:17 +02003369 I915_WRITE_FW(DSPLINOFF(i9xx_plane), linear_offset);
3370 I915_WRITE_FW(DSPTILEOFF(i9xx_plane), (y << 16) | x);
3371 }
3372
3373 /*
3374 * The control register self-arms if the plane was previously
3375 * disabled. Try to make the plane enable atomic by writing
3376 * the control register just before the surface register.
3377 */
3378 I915_WRITE_FW(DSPCNTR(i9xx_plane), dspcntr);
3379 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjäläed150302017-11-17 21:19:10 +02003380 I915_WRITE_FW(DSPSURF(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003381 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003382 dspaddr_offset);
Ville Syrjälä83234d12018-11-14 23:07:17 +02003383 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003384 I915_WRITE_FW(DSPADDR(i9xx_plane),
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003385 intel_plane_ggtt_offset(plane_state) +
Juha-Pekka Heikkilae2888812017-10-17 23:08:08 +03003386 dspaddr_offset);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003387
3388 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes17638cd2011-06-24 12:19:23 -07003389}
3390
Ville Syrjäläed150302017-11-17 21:19:10 +02003391static void i9xx_disable_plane(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02003392 const struct intel_crtc_state *crtc_state)
Jesse Barnes17638cd2011-06-24 12:19:23 -07003393{
Ville Syrjäläed150302017-11-17 21:19:10 +02003394 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
3395 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003396 unsigned long irqflags;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003397
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003398 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
3399
Ville Syrjäläed150302017-11-17 21:19:10 +02003400 I915_WRITE_FW(DSPCNTR(i9xx_plane), 0);
3401 if (INTEL_GEN(dev_priv) >= 4)
3402 I915_WRITE_FW(DSPSURF(i9xx_plane), 0);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003403 else
Ville Syrjäläed150302017-11-17 21:19:10 +02003404 I915_WRITE_FW(DSPADDR(i9xx_plane), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02003405
3406 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003407}
3408
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003409static bool i9xx_plane_get_hw_state(struct intel_plane *plane,
3410 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003411{
Ville Syrjäläed150302017-11-17 21:19:10 +02003412 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003413 enum intel_display_power_domain power_domain;
Ville Syrjäläed150302017-11-17 21:19:10 +02003414 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003415 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003416 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003417
3418 /*
3419 * Not 100% correct for planes that can move between pipes,
3420 * but that's only the case for gen2-4 which don't have any
3421 * display power wells.
3422 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003423 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003424 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
3425 return false;
3426
Ville Syrjäläeade6c82018-01-30 22:38:03 +02003427 val = I915_READ(DSPCNTR(i9xx_plane));
3428
3429 ret = val & DISPLAY_PLANE_ENABLE;
3430
3431 if (INTEL_GEN(dev_priv) >= 5)
3432 *pipe = plane->pipe;
3433 else
3434 *pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
3435 DISPPLANE_SEL_PIPE_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02003436
3437 intel_display_power_put(dev_priv, power_domain);
3438
3439 return ret;
3440}
3441
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003442static u32
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003443intel_fb_stride_alignment(const struct drm_framebuffer *fb, int color_plane)
Damien Lespiaub3218032015-02-27 11:15:18 +00003444{
Ben Widawsky2f075562017-03-24 14:29:48 -07003445 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
Ville Syrjälä7b49f942016-01-12 21:08:32 +02003446 return 64;
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02003447 else
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003448 return intel_tile_width_bytes(fb, color_plane);
Damien Lespiaub3218032015-02-27 11:15:18 +00003449}
3450
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003451static void skl_detach_scaler(struct intel_crtc *intel_crtc, int id)
3452{
3453 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003454 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003455
3456 I915_WRITE(SKL_PS_CTRL(intel_crtc->pipe, id), 0);
3457 I915_WRITE(SKL_PS_WIN_POS(intel_crtc->pipe, id), 0);
3458 I915_WRITE(SKL_PS_WIN_SZ(intel_crtc->pipe, id), 0);
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003459}
3460
Chandra Kondurua1b22782015-04-07 15:28:45 -07003461/*
3462 * This function detaches (aka. unbinds) unused scalers in hardware
3463 */
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003464static void skl_detach_scalers(const struct intel_crtc_state *crtc_state)
Chandra Kondurua1b22782015-04-07 15:28:45 -07003465{
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003466 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
3467 const struct intel_crtc_scaler_state *scaler_state =
3468 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07003469 int i;
3470
Chandra Kondurua1b22782015-04-07 15:28:45 -07003471 /* loop through and disable scalers that aren't in use */
3472 for (i = 0; i < intel_crtc->num_scalers; i++) {
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02003473 if (!scaler_state->scalers[i].in_use)
3474 skl_detach_scaler(intel_crtc, i);
Chandra Kondurua1b22782015-04-07 15:28:45 -07003475 }
3476}
3477
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003478static unsigned int skl_plane_stride_mult(const struct drm_framebuffer *fb,
3479 int color_plane, unsigned int rotation)
3480{
3481 /*
3482 * The stride is either expressed as a multiple of 64 bytes chunks for
3483 * linear buffers or in number of tiles for tiled buffers.
3484 */
3485 if (fb->modifier == DRM_FORMAT_MOD_LINEAR)
3486 return 64;
3487 else if (drm_rotation_90_or_270(rotation))
3488 return intel_tile_height(fb, color_plane);
3489 else
3490 return intel_tile_width_bytes(fb, color_plane);
3491}
3492
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003493u32 skl_plane_stride(const struct intel_plane_state *plane_state,
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003494 int color_plane)
Ville Syrjäläd2196772016-01-28 18:33:11 +02003495{
Ville Syrjälädf79cf42018-09-11 18:01:39 +03003496 const struct drm_framebuffer *fb = plane_state->base.fb;
3497 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003498 u32 stride = plane_state->color_plane[color_plane].stride;
Ville Syrjälä1b500532017-03-07 21:42:08 +02003499
Ville Syrjälä5d2a1952018-09-07 18:24:07 +03003500 if (color_plane >= fb->format->num_planes)
Ville Syrjälä1b500532017-03-07 21:42:08 +02003501 return 0;
3502
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03003503 return stride / skl_plane_stride_mult(fb, color_plane, rotation);
Ville Syrjäläd2196772016-01-28 18:33:11 +02003504}
3505
Ville Syrjälä2e881262017-03-17 23:17:56 +02003506static u32 skl_plane_ctl_format(uint32_t pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -07003507{
Chandra Konduru6156a452015-04-27 13:48:39 -07003508 switch (pixel_format) {
Damien Lespiaud161cf72015-05-12 16:13:17 +01003509 case DRM_FORMAT_C8:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003510 return PLANE_CTL_FORMAT_INDEXED;
Chandra Konduru6156a452015-04-27 13:48:39 -07003511 case DRM_FORMAT_RGB565:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003512 return PLANE_CTL_FORMAT_RGB_565;
Chandra Konduru6156a452015-04-27 13:48:39 -07003513 case DRM_FORMAT_XBGR8888:
James Ausmus4036c782017-11-13 10:11:28 -08003514 case DRM_FORMAT_ABGR8888:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003515 return PLANE_CTL_FORMAT_XRGB_8888 | PLANE_CTL_ORDER_RGBX;
Chandra Konduru6156a452015-04-27 13:48:39 -07003516 case DRM_FORMAT_XRGB8888:
Chandra Konduru6156a452015-04-27 13:48:39 -07003517 case DRM_FORMAT_ARGB8888:
James Ausmus4036c782017-11-13 10:11:28 -08003518 return PLANE_CTL_FORMAT_XRGB_8888;
Chandra Konduru6156a452015-04-27 13:48:39 -07003519 case DRM_FORMAT_XRGB2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003520 return PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003521 case DRM_FORMAT_XBGR2101010:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003522 return PLANE_CTL_ORDER_RGBX | PLANE_CTL_FORMAT_XRGB_2101010;
Chandra Konduru6156a452015-04-27 13:48:39 -07003523 case DRM_FORMAT_YUYV:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003524 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YUYV;
Chandra Konduru6156a452015-04-27 13:48:39 -07003525 case DRM_FORMAT_YVYU:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003526 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_YVYU;
Chandra Konduru6156a452015-04-27 13:48:39 -07003527 case DRM_FORMAT_UYVY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003528 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_UYVY;
Chandra Konduru6156a452015-04-27 13:48:39 -07003529 case DRM_FORMAT_VYUY:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003530 return PLANE_CTL_FORMAT_YUV422 | PLANE_CTL_YUV422_VYUY;
Chandra Konduru77224cd2018-04-09 09:11:13 +05303531 case DRM_FORMAT_NV12:
3532 return PLANE_CTL_FORMAT_NV12;
Chandra Konduru6156a452015-04-27 13:48:39 -07003533 default:
Damien Lespiau4249eee2015-05-12 16:13:16 +01003534 MISSING_CASE(pixel_format);
Chandra Konduru6156a452015-04-27 13:48:39 -07003535 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003536
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003537 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003538}
3539
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003540static u32 skl_plane_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003541{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003542 if (!plane_state->base.fb->format->has_alpha)
3543 return PLANE_CTL_ALPHA_DISABLE;
3544
3545 switch (plane_state->base.pixel_blend_mode) {
3546 case DRM_MODE_BLEND_PIXEL_NONE:
3547 return PLANE_CTL_ALPHA_DISABLE;
3548 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003549 return PLANE_CTL_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003550 case DRM_MODE_BLEND_COVERAGE:
3551 return PLANE_CTL_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003552 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003553 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003554 return PLANE_CTL_ALPHA_DISABLE;
3555 }
3556}
3557
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003558static u32 glk_plane_color_ctl_alpha(const struct intel_plane_state *plane_state)
James Ausmus4036c782017-11-13 10:11:28 -08003559{
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003560 if (!plane_state->base.fb->format->has_alpha)
3561 return PLANE_COLOR_ALPHA_DISABLE;
3562
3563 switch (plane_state->base.pixel_blend_mode) {
3564 case DRM_MODE_BLEND_PIXEL_NONE:
3565 return PLANE_COLOR_ALPHA_DISABLE;
3566 case DRM_MODE_BLEND_PREMULTI:
James Ausmus4036c782017-11-13 10:11:28 -08003567 return PLANE_COLOR_ALPHA_SW_PREMULTIPLY;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003568 case DRM_MODE_BLEND_COVERAGE:
3569 return PLANE_COLOR_ALPHA_HW_PREMULTIPLY;
James Ausmus4036c782017-11-13 10:11:28 -08003570 default:
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003571 MISSING_CASE(plane_state->base.pixel_blend_mode);
James Ausmus4036c782017-11-13 10:11:28 -08003572 return PLANE_COLOR_ALPHA_DISABLE;
3573 }
3574}
3575
Ville Syrjälä2e881262017-03-17 23:17:56 +02003576static u32 skl_plane_ctl_tiling(uint64_t fb_modifier)
Chandra Konduru6156a452015-04-27 13:48:39 -07003577{
Chandra Konduru6156a452015-04-27 13:48:39 -07003578 switch (fb_modifier) {
Ben Widawsky2f075562017-03-24 14:29:48 -07003579 case DRM_FORMAT_MOD_LINEAR:
Chandra Konduru6156a452015-04-27 13:48:39 -07003580 break;
3581 case I915_FORMAT_MOD_X_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003582 return PLANE_CTL_TILED_X;
Chandra Konduru6156a452015-04-27 13:48:39 -07003583 case I915_FORMAT_MOD_Y_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003584 return PLANE_CTL_TILED_Y;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003585 case I915_FORMAT_MOD_Y_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003586 return PLANE_CTL_TILED_Y | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003587 case I915_FORMAT_MOD_Yf_TILED:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003588 return PLANE_CTL_TILED_YF;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07003589 case I915_FORMAT_MOD_Yf_TILED_CCS:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07003590 return PLANE_CTL_TILED_YF | PLANE_CTL_RENDER_DECOMPRESSION_ENABLE;
Chandra Konduru6156a452015-04-27 13:48:39 -07003591 default:
3592 MISSING_CASE(fb_modifier);
3593 }
Damien Lespiau8cfcba42015-05-12 16:13:14 +01003594
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003595 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003596}
3597
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003598static u32 skl_plane_ctl_rotate(unsigned int rotate)
Chandra Konduru6156a452015-04-27 13:48:39 -07003599{
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003600 switch (rotate) {
Robert Fossc2c446a2017-05-19 16:50:17 -04003601 case DRM_MODE_ROTATE_0:
Chandra Konduru6156a452015-04-27 13:48:39 -07003602 break;
Sonika Jindal1e8df162015-05-20 13:40:48 +05303603 /*
Robert Fossc2c446a2017-05-19 16:50:17 -04003604 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
Sonika Jindal1e8df162015-05-20 13:40:48 +05303605 * while i915 HW rotation is clockwise, thats why this swapping.
3606 */
Robert Fossc2c446a2017-05-19 16:50:17 -04003607 case DRM_MODE_ROTATE_90:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303608 return PLANE_CTL_ROTATE_270;
Robert Fossc2c446a2017-05-19 16:50:17 -04003609 case DRM_MODE_ROTATE_180:
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003610 return PLANE_CTL_ROTATE_180;
Robert Fossc2c446a2017-05-19 16:50:17 -04003611 case DRM_MODE_ROTATE_270:
Sonika Jindal1e8df162015-05-20 13:40:48 +05303612 return PLANE_CTL_ROTATE_90;
Chandra Konduru6156a452015-04-27 13:48:39 -07003613 default:
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003614 MISSING_CASE(rotate);
3615 }
3616
3617 return 0;
3618}
3619
3620static u32 cnl_plane_ctl_flip(unsigned int reflect)
3621{
3622 switch (reflect) {
3623 case 0:
3624 break;
3625 case DRM_MODE_REFLECT_X:
3626 return PLANE_CTL_FLIP_HORIZONTAL;
3627 case DRM_MODE_REFLECT_Y:
3628 default:
3629 MISSING_CASE(reflect);
Chandra Konduru6156a452015-04-27 13:48:39 -07003630 }
3631
Damien Lespiauc34ce3d2015-05-15 15:07:02 +01003632 return 0;
Chandra Konduru6156a452015-04-27 13:48:39 -07003633}
3634
Ville Syrjälä2e881262017-03-17 23:17:56 +02003635u32 skl_plane_ctl(const struct intel_crtc_state *crtc_state,
3636 const struct intel_plane_state *plane_state)
Damien Lespiau70d21f02013-07-03 21:06:04 +01003637{
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003638 struct drm_i915_private *dev_priv =
3639 to_i915(plane_state->base.plane->dev);
3640 const struct drm_framebuffer *fb = plane_state->base.fb;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +01003641 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä2e881262017-03-17 23:17:56 +02003642 const struct drm_intel_sprite_colorkey *key = &plane_state->ckey;
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003643 u32 plane_ctl;
Damien Lespiau70d21f02013-07-03 21:06:04 +01003644
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003645 plane_ctl = PLANE_CTL_ENABLE;
3646
James Ausmus4036c782017-11-13 10:11:28 -08003647 if (INTEL_GEN(dev_priv) < 10 && !IS_GEMINILAKE(dev_priv)) {
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003648 plane_ctl |= skl_plane_ctl_alpha(plane_state);
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003649 plane_ctl |=
3650 PLANE_CTL_PIPE_GAMMA_ENABLE |
3651 PLANE_CTL_PIPE_CSC_ENABLE |
3652 PLANE_CTL_PLANE_GAMMA_DISABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003653
3654 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3655 plane_ctl |= PLANE_CTL_YUV_TO_RGB_CSC_FORMAT_BT709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003656
3657 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3658 plane_ctl |= PLANE_CTL_YUV_RANGE_CORRECTION_DISABLE;
Ander Conselvan de Oliveira47f9ea82017-01-26 13:24:22 +02003659 }
Damien Lespiau70d21f02013-07-03 21:06:04 +01003660
Ville Syrjälä438b74a2016-12-14 23:32:55 +02003661 plane_ctl |= skl_plane_ctl_format(fb->format->format);
Ville Syrjäläbae781b2016-11-16 13:33:16 +02003662 plane_ctl |= skl_plane_ctl_tiling(fb->modifier);
Joonas Lahtinen5f8e3f52017-12-15 13:38:00 -08003663 plane_ctl |= skl_plane_ctl_rotate(rotation & DRM_MODE_ROTATE_MASK);
3664
3665 if (INTEL_GEN(dev_priv) >= 10)
3666 plane_ctl |= cnl_plane_ctl_flip(rotation &
3667 DRM_MODE_REFLECT_MASK);
Damien Lespiau70d21f02013-07-03 21:06:04 +01003668
Ville Syrjälä2e881262017-03-17 23:17:56 +02003669 if (key->flags & I915_SET_COLORKEY_DESTINATION)
3670 plane_ctl |= PLANE_CTL_KEY_ENABLE_DESTINATION;
3671 else if (key->flags & I915_SET_COLORKEY_SOURCE)
3672 plane_ctl |= PLANE_CTL_KEY_ENABLE_SOURCE;
3673
Ville Syrjälä46f788b2017-03-17 23:17:55 +02003674 return plane_ctl;
3675}
3676
James Ausmus4036c782017-11-13 10:11:28 -08003677u32 glk_plane_color_ctl(const struct intel_crtc_state *crtc_state,
3678 const struct intel_plane_state *plane_state)
3679{
James Ausmus077ef1f2018-03-28 14:57:56 -07003680 struct drm_i915_private *dev_priv =
3681 to_i915(plane_state->base.plane->dev);
James Ausmus4036c782017-11-13 10:11:28 -08003682 const struct drm_framebuffer *fb = plane_state->base.fb;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303683 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
James Ausmus4036c782017-11-13 10:11:28 -08003684 u32 plane_color_ctl = 0;
3685
James Ausmus077ef1f2018-03-28 14:57:56 -07003686 if (INTEL_GEN(dev_priv) < 11) {
3687 plane_color_ctl |= PLANE_COLOR_PIPE_GAMMA_ENABLE;
3688 plane_color_ctl |= PLANE_COLOR_PIPE_CSC_ENABLE;
3689 }
James Ausmus4036c782017-11-13 10:11:28 -08003690 plane_color_ctl |= PLANE_COLOR_PLANE_GAMMA_DISABLE;
Maarten Lankhorstb2081522018-08-15 12:34:05 +02003691 plane_color_ctl |= glk_plane_color_ctl_alpha(plane_state);
James Ausmus4036c782017-11-13 10:11:28 -08003692
Uma Shankarbfe60a02018-11-02 00:40:20 +05303693 if (fb->format->is_yuv && !icl_is_hdr_plane(plane)) {
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003694 if (plane_state->base.color_encoding == DRM_COLOR_YCBCR_BT709)
3695 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV709_TO_RGB709;
3696 else
3697 plane_color_ctl |= PLANE_COLOR_CSC_MODE_YUV601_TO_RGB709;
Ville Syrjäläc8624ed2018-02-14 21:23:27 +02003698
3699 if (plane_state->base.color_range == DRM_COLOR_YCBCR_FULL_RANGE)
3700 plane_color_ctl |= PLANE_COLOR_YUV_RANGE_CORRECTION_DISABLE;
Uma Shankarbfe60a02018-11-02 00:40:20 +05303701 } else if (fb->format->is_yuv) {
3702 plane_color_ctl |= PLANE_COLOR_INPUT_CSC_ENABLE;
Ville Syrjäläb0f5c0b2018-02-14 21:23:25 +02003703 }
Ville Syrjälä012d79e2018-05-21 21:56:12 +03003704
James Ausmus4036c782017-11-13 10:11:28 -08003705 return plane_color_ctl;
3706}
3707
Maarten Lankhorst73974892016-08-05 23:28:27 +03003708static int
3709__intel_display_resume(struct drm_device *dev,
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003710 struct drm_atomic_state *state,
3711 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorst73974892016-08-05 23:28:27 +03003712{
3713 struct drm_crtc_state *crtc_state;
3714 struct drm_crtc *crtc;
3715 int i, ret;
3716
Ville Syrjäläaecd36b2017-06-01 17:36:13 +03003717 intel_modeset_setup_hw_state(dev, ctx);
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +00003718 i915_redisable_vga(to_i915(dev));
Maarten Lankhorst73974892016-08-05 23:28:27 +03003719
3720 if (!state)
3721 return 0;
3722
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01003723 /*
3724 * We've duplicated the state, pointers to the old state are invalid.
3725 *
3726 * Don't attempt to use the old state until we commit the duplicated state.
3727 */
3728 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst73974892016-08-05 23:28:27 +03003729 /*
3730 * Force recalculation even if we restore
3731 * current state. With fast modeset this may not result
3732 * in a modeset when the state is compatible.
3733 */
3734 crtc_state->mode_changed = true;
3735 }
3736
3737 /* ignore any reset values/BIOS leftovers in the WM registers */
Ville Syrjälä602ae832017-03-02 19:15:02 +02003738 if (!HAS_GMCH_DISPLAY(to_i915(dev)))
3739 to_intel_atomic_state(state)->skip_intermediate_wm = true;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003740
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003741 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003742
3743 WARN_ON(ret == -EDEADLK);
3744 return ret;
3745}
3746
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003747static bool gpu_reset_clobbers_display(struct drm_i915_private *dev_priv)
3748{
Ville Syrjäläae981042016-08-05 23:28:30 +03003749 return intel_has_gpu_reset(dev_priv) &&
3750 INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv);
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003751}
3752
Chris Wilsonc0336662016-05-06 15:40:21 +01003753void intel_prepare_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003754{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003755 struct drm_device *dev = &dev_priv->drm;
3756 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
3757 struct drm_atomic_state *state;
3758 int ret;
3759
Daniel Vetterce87ea12017-07-19 14:54:55 +02003760 /* reset doesn't touch the display */
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00003761 if (!i915_modparams.force_reset_modeset_test &&
Daniel Vetterce87ea12017-07-19 14:54:55 +02003762 !gpu_reset_clobbers_display(dev_priv))
3763 return;
3764
Daniel Vetter9db529a2017-08-08 10:08:28 +02003765 /* We have a modeset vs reset deadlock, defensively unbreak it. */
3766 set_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
3767 wake_up_all(&dev_priv->gpu_error.wait_queue);
3768
3769 if (atomic_read(&dev_priv->gpu_error.pending_fb_pin)) {
3770 DRM_DEBUG_KMS("Modeset potentially stuck, unbreaking through wedging\n");
3771 i915_gem_set_wedged(dev_priv);
3772 }
Daniel Vetter97154ec2017-08-08 10:08:26 +02003773
Maarten Lankhorst73974892016-08-05 23:28:27 +03003774 /*
3775 * Need mode_config.mutex so that we don't
3776 * trample ongoing ->detect() and whatnot.
3777 */
3778 mutex_lock(&dev->mode_config.mutex);
3779 drm_modeset_acquire_init(ctx, 0);
3780 while (1) {
3781 ret = drm_modeset_lock_all_ctx(dev, ctx);
3782 if (ret != -EDEADLK)
3783 break;
3784
3785 drm_modeset_backoff(ctx);
3786 }
Ville Syrjäläf98ce922014-11-21 21:54:30 +02003787 /*
3788 * Disabling the crtcs gracefully seems nicer. Also the
3789 * g33 docs say we should at least disable all the planes.
3790 */
Maarten Lankhorst73974892016-08-05 23:28:27 +03003791 state = drm_atomic_helper_duplicate_state(dev, ctx);
3792 if (IS_ERR(state)) {
3793 ret = PTR_ERR(state);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003794 DRM_ERROR("Duplicating state failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003795 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003796 }
3797
3798 ret = drm_atomic_helper_disable_all(dev, ctx);
3799 if (ret) {
3800 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Ander Conselvan de Oliveira1e5a15d2017-01-18 14:34:28 +02003801 drm_atomic_state_put(state);
3802 return;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003803 }
3804
3805 dev_priv->modeset_restore_state = state;
3806 state->acquire_ctx = ctx;
Ville Syrjälä75147472014-11-24 18:28:11 +02003807}
3808
Chris Wilsonc0336662016-05-06 15:40:21 +01003809void intel_finish_reset(struct drm_i915_private *dev_priv)
Ville Syrjälä75147472014-11-24 18:28:11 +02003810{
Maarten Lankhorst73974892016-08-05 23:28:27 +03003811 struct drm_device *dev = &dev_priv->drm;
3812 struct drm_modeset_acquire_ctx *ctx = &dev_priv->reset_ctx;
Chris Wilson40da1d32018-04-05 13:37:14 +01003813 struct drm_atomic_state *state;
Maarten Lankhorst73974892016-08-05 23:28:27 +03003814 int ret;
3815
Daniel Vetterce87ea12017-07-19 14:54:55 +02003816 /* reset doesn't touch the display */
Chris Wilson40da1d32018-04-05 13:37:14 +01003817 if (!test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
Daniel Vetterce87ea12017-07-19 14:54:55 +02003818 return;
3819
Chris Wilson40da1d32018-04-05 13:37:14 +01003820 state = fetch_and_zero(&dev_priv->modeset_restore_state);
Daniel Vetterce87ea12017-07-19 14:54:55 +02003821 if (!state)
3822 goto unlock;
3823
Ville Syrjälä75147472014-11-24 18:28:11 +02003824 /* reset doesn't touch the display */
Ville Syrjälä4ac2ba22016-08-05 23:28:29 +03003825 if (!gpu_reset_clobbers_display(dev_priv)) {
Daniel Vetterce87ea12017-07-19 14:54:55 +02003826 /* for testing only restore the display */
3827 ret = __intel_display_resume(dev, state, ctx);
Chris Wilson942d5d02017-08-28 11:46:04 +01003828 if (ret)
3829 DRM_ERROR("Restoring old state failed with %i\n", ret);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003830 } else {
3831 /*
3832 * The display has been reset as well,
3833 * so need a full re-initialization.
3834 */
3835 intel_runtime_pm_disable_interrupts(dev_priv);
3836 intel_runtime_pm_enable_interrupts(dev_priv);
3837
Imre Deak51f59202016-09-14 13:04:13 +03003838 intel_pps_unlock_regs_wa(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003839 intel_modeset_init_hw(dev);
Ville Syrjäläf72b84c2017-11-08 15:35:55 +02003840 intel_init_clock_gating(dev_priv);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003841
3842 spin_lock_irq(&dev_priv->irq_lock);
3843 if (dev_priv->display.hpd_irq_setup)
3844 dev_priv->display.hpd_irq_setup(dev_priv);
3845 spin_unlock_irq(&dev_priv->irq_lock);
3846
Maarten Lankhorst581e49f2017-01-16 10:37:38 +01003847 ret = __intel_display_resume(dev, state, ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +03003848 if (ret)
3849 DRM_ERROR("Restoring old state failed with %i\n", ret);
3850
3851 intel_hpd_init(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003852 }
3853
Daniel Vetterce87ea12017-07-19 14:54:55 +02003854 drm_atomic_state_put(state);
3855unlock:
Maarten Lankhorst73974892016-08-05 23:28:27 +03003856 drm_modeset_drop_locks(ctx);
3857 drm_modeset_acquire_fini(ctx);
3858 mutex_unlock(&dev->mode_config.mutex);
Daniel Vetter9db529a2017-08-08 10:08:28 +02003859
3860 clear_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags);
Ville Syrjälä75147472014-11-24 18:28:11 +02003861}
3862
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003863static void intel_update_pipe_config(const struct intel_crtc_state *old_crtc_state,
3864 const struct intel_crtc_state *new_crtc_state)
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003865{
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003866 struct intel_crtc *crtc = to_intel_crtc(new_crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003867 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003868
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003869 /* drm_atomic_helper_update_legacy_modeset_state might not be called. */
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003870 crtc->base.mode = new_crtc_state->base.mode;
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003871
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003872 /*
3873 * Update pipe size and adjust fitter if needed: the reason for this is
3874 * that in compute_mode_changes we check the native mode (not the pfit
3875 * mode) to see if we can flip rather than do a full mode set. In the
3876 * fastboot case, we'll flip, but if we don't update the pipesrc and
3877 * pfit state, we'll end up with a big fb scanned out into the wrong
3878 * sized surface.
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003879 */
3880
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003881 I915_WRITE(PIPESRC(crtc->pipe),
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003882 ((new_crtc_state->pipe_src_w - 1) << 16) |
3883 (new_crtc_state->pipe_src_h - 1));
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003884
3885 /* on skylake this is done by detaching scalers */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00003886 if (INTEL_GEN(dev_priv) >= 9) {
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +02003887 skl_detach_scalers(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003888
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003889 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003890 skylake_pfit_enable(new_crtc_state);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003891 } else if (HAS_PCH_SPLIT(dev_priv)) {
Ville Syrjälä1a15b772017-08-23 18:22:25 +03003892 if (new_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003893 ironlake_pfit_enable(new_crtc_state);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +02003894 else if (old_crtc_state->pch_pfit.enabled)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02003895 ironlake_pfit_disable(old_crtc_state);
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003896 }
Gustavo Padovane30e8f72014-09-10 12:04:17 -03003897}
3898
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003899static void intel_fdi_normal_train(struct intel_crtc *crtc)
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003900{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003901 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003902 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003903 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003904 i915_reg_t reg;
3905 u32 temp;
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003906
3907 /* enable normal train */
3908 reg = FDI_TX_CTL(pipe);
3909 temp = I915_READ(reg);
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003910 if (IS_IVYBRIDGE(dev_priv)) {
Jesse Barnes357555c2011-04-28 15:09:55 -07003911 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
3912 temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
Keith Packard61e499b2011-05-17 16:13:52 -07003913 } else {
3914 temp &= ~FDI_LINK_TRAIN_NONE;
3915 temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
Jesse Barnes357555c2011-04-28 15:09:55 -07003916 }
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003917 I915_WRITE(reg, temp);
3918
3919 reg = FDI_RX_CTL(pipe);
3920 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003921 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003922 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
3923 temp |= FDI_LINK_TRAIN_NORMAL_CPT;
3924 } else {
3925 temp &= ~FDI_LINK_TRAIN_NONE;
3926 temp |= FDI_LINK_TRAIN_NONE;
3927 }
3928 I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
3929
3930 /* wait one idle pattern time */
3931 POSTING_READ(reg);
3932 udelay(1000);
Jesse Barnes357555c2011-04-28 15:09:55 -07003933
3934 /* IVB wants error correction enabled */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01003935 if (IS_IVYBRIDGE(dev_priv))
Jesse Barnes357555c2011-04-28 15:09:55 -07003936 I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
3937 FDI_FE_ERRC_ENABLE);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08003938}
3939
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003940/* The FDI link training functions for ILK/Ibexpeak. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003941static void ironlake_fdi_link_train(struct intel_crtc *crtc,
3942 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003943{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003944 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003945 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02003946 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003947 i915_reg_t reg;
3948 u32 temp, tries;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003949
Ville Syrjälä1c8562f2014-04-25 22:12:07 +03003950 /* FDI needs bits from pipe first */
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003951 assert_pipe_enabled(dev_priv, pipe);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08003952
Adam Jacksone1a44742010-06-25 15:32:14 -04003953 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
3954 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01003955 reg = FDI_RX_IMR(pipe);
3956 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003957 temp &= ~FDI_RX_SYMBOL_LOCK;
3958 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01003959 I915_WRITE(reg, temp);
3960 I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04003961 udelay(150);
3962
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003963 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01003964 reg = FDI_TX_CTL(pipe);
3965 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02003966 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02003967 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003968 temp &= ~FDI_LINK_TRAIN_NONE;
3969 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003970 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003971
Chris Wilson5eddb702010-09-11 13:48:45 +01003972 reg = FDI_RX_CTL(pipe);
3973 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003974 temp &= ~FDI_LINK_TRAIN_NONE;
3975 temp |= FDI_LINK_TRAIN_PATTERN_1;
Chris Wilson5eddb702010-09-11 13:48:45 +01003976 I915_WRITE(reg, temp | FDI_RX_ENABLE);
3977
3978 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003979 udelay(150);
3980
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003981 /* Ironlake workaround, enable clock pointer after FDI enable*/
Daniel Vetter8f5718a2012-10-31 22:52:28 +01003982 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
3983 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
3984 FDI_RX_PHASE_SYNC_POINTER_EN);
Jesse Barnes5b2adf82010-10-07 16:01:15 -07003985
Chris Wilson5eddb702010-09-11 13:48:45 +01003986 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04003987 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01003988 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003989 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
3990
3991 if ((temp & FDI_RX_BIT_LOCK)) {
3992 DRM_DEBUG_KMS("FDI train 1 done.\n");
Chris Wilson5eddb702010-09-11 13:48:45 +01003993 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003994 break;
3995 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003996 }
Adam Jacksone1a44742010-06-25 15:32:14 -04003997 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01003998 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08003999
4000 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004001 reg = FDI_TX_CTL(pipe);
4002 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004003 temp &= ~FDI_LINK_TRAIN_NONE;
4004 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004005 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004006
Chris Wilson5eddb702010-09-11 13:48:45 +01004007 reg = FDI_RX_CTL(pipe);
4008 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004009 temp &= ~FDI_LINK_TRAIN_NONE;
4010 temp |= FDI_LINK_TRAIN_PATTERN_2;
Chris Wilson5eddb702010-09-11 13:48:45 +01004011 I915_WRITE(reg, temp);
4012
4013 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004014 udelay(150);
4015
Chris Wilson5eddb702010-09-11 13:48:45 +01004016 reg = FDI_RX_IIR(pipe);
Adam Jacksone1a44742010-06-25 15:32:14 -04004017 for (tries = 0; tries < 5; tries++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004018 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004019 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4020
4021 if (temp & FDI_RX_SYMBOL_LOCK) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004022 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004023 DRM_DEBUG_KMS("FDI train 2 done.\n");
4024 break;
4025 }
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004026 }
Adam Jacksone1a44742010-06-25 15:32:14 -04004027 if (tries == 5)
Chris Wilson5eddb702010-09-11 13:48:45 +01004028 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004029
4030 DRM_DEBUG_KMS("FDI train done\n");
Jesse Barnes5c5313c2010-10-07 16:01:11 -07004031
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004032}
4033
Akshay Joshi0206e352011-08-16 15:34:10 -04004034static const int snb_b_fdi_train_param[] = {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004035 FDI_LINK_TRAIN_400MV_0DB_SNB_B,
4036 FDI_LINK_TRAIN_400MV_6DB_SNB_B,
4037 FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
4038 FDI_LINK_TRAIN_800MV_0DB_SNB_B,
4039};
4040
4041/* The FDI link training functions for SNB/Cougarpoint. */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004042static void gen6_fdi_link_train(struct intel_crtc *crtc,
4043 const struct intel_crtc_state *crtc_state)
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004044{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004045 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004046 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004047 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004048 i915_reg_t reg;
4049 u32 temp, i, retry;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004050
Adam Jacksone1a44742010-06-25 15:32:14 -04004051 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4052 for train result */
Chris Wilson5eddb702010-09-11 13:48:45 +01004053 reg = FDI_RX_IMR(pipe);
4054 temp = I915_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004055 temp &= ~FDI_RX_SYMBOL_LOCK;
4056 temp &= ~FDI_RX_BIT_LOCK;
Chris Wilson5eddb702010-09-11 13:48:45 +01004057 I915_WRITE(reg, temp);
4058
4059 POSTING_READ(reg);
Adam Jacksone1a44742010-06-25 15:32:14 -04004060 udelay(150);
4061
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004062 /* enable CPU FDI TX and PCH FDI RX */
Chris Wilson5eddb702010-09-11 13:48:45 +01004063 reg = FDI_TX_CTL(pipe);
4064 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004065 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004066 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004067 temp &= ~FDI_LINK_TRAIN_NONE;
4068 temp |= FDI_LINK_TRAIN_PATTERN_1;
4069 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4070 /* SNB-B */
4071 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
Chris Wilson5eddb702010-09-11 13:48:45 +01004072 I915_WRITE(reg, temp | FDI_TX_ENABLE);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004073
Daniel Vetterd74cf322012-10-26 10:58:13 +02004074 I915_WRITE(FDI_RX_MISC(pipe),
4075 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4076
Chris Wilson5eddb702010-09-11 13:48:45 +01004077 reg = FDI_RX_CTL(pipe);
4078 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004079 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004080 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4081 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4082 } else {
4083 temp &= ~FDI_LINK_TRAIN_NONE;
4084 temp |= FDI_LINK_TRAIN_PATTERN_1;
4085 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004086 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4087
4088 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004089 udelay(150);
4090
Akshay Joshi0206e352011-08-16 15:34:10 -04004091 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004092 reg = FDI_TX_CTL(pipe);
4093 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004094 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4095 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004096 I915_WRITE(reg, temp);
4097
4098 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004099 udelay(500);
4100
Sean Paulfa37d392012-03-02 12:53:39 -05004101 for (retry = 0; retry < 5; retry++) {
4102 reg = FDI_RX_IIR(pipe);
4103 temp = I915_READ(reg);
4104 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4105 if (temp & FDI_RX_BIT_LOCK) {
4106 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4107 DRM_DEBUG_KMS("FDI train 1 done.\n");
4108 break;
4109 }
4110 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004111 }
Sean Paulfa37d392012-03-02 12:53:39 -05004112 if (retry < 5)
4113 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004114 }
4115 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004116 DRM_ERROR("FDI train 1 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004117
4118 /* Train 2 */
Chris Wilson5eddb702010-09-11 13:48:45 +01004119 reg = FDI_TX_CTL(pipe);
4120 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004121 temp &= ~FDI_LINK_TRAIN_NONE;
4122 temp |= FDI_LINK_TRAIN_PATTERN_2;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004123 if (IS_GEN(dev_priv, 6)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004124 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4125 /* SNB-B */
4126 temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
4127 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004128 I915_WRITE(reg, temp);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004129
Chris Wilson5eddb702010-09-11 13:48:45 +01004130 reg = FDI_RX_CTL(pipe);
4131 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004132 if (HAS_PCH_CPT(dev_priv)) {
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004133 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4134 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
4135 } else {
4136 temp &= ~FDI_LINK_TRAIN_NONE;
4137 temp |= FDI_LINK_TRAIN_PATTERN_2;
4138 }
Chris Wilson5eddb702010-09-11 13:48:45 +01004139 I915_WRITE(reg, temp);
4140
4141 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004142 udelay(150);
4143
Akshay Joshi0206e352011-08-16 15:34:10 -04004144 for (i = 0; i < 4; i++) {
Chris Wilson5eddb702010-09-11 13:48:45 +01004145 reg = FDI_TX_CTL(pipe);
4146 temp = I915_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004147 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
4148 temp |= snb_b_fdi_train_param[i];
Chris Wilson5eddb702010-09-11 13:48:45 +01004149 I915_WRITE(reg, temp);
4150
4151 POSTING_READ(reg);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004152 udelay(500);
4153
Sean Paulfa37d392012-03-02 12:53:39 -05004154 for (retry = 0; retry < 5; retry++) {
4155 reg = FDI_RX_IIR(pipe);
4156 temp = I915_READ(reg);
4157 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4158 if (temp & FDI_RX_SYMBOL_LOCK) {
4159 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4160 DRM_DEBUG_KMS("FDI train 2 done.\n");
4161 break;
4162 }
4163 udelay(50);
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004164 }
Sean Paulfa37d392012-03-02 12:53:39 -05004165 if (retry < 5)
4166 break;
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004167 }
4168 if (i == 4)
Chris Wilson5eddb702010-09-11 13:48:45 +01004169 DRM_ERROR("FDI train 2 fail!\n");
Zhenyu Wang8db9d772010-04-07 16:15:54 +08004170
4171 DRM_DEBUG_KMS("FDI train done.\n");
4172}
4173
Jesse Barnes357555c2011-04-28 15:09:55 -07004174/* Manual link training for Ivy Bridge A0 parts */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004175static void ivb_manual_fdi_link_train(struct intel_crtc *crtc,
4176 const struct intel_crtc_state *crtc_state)
Jesse Barnes357555c2011-04-28 15:09:55 -07004177{
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004178 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004179 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004180 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004181 i915_reg_t reg;
4182 u32 temp, i, j;
Jesse Barnes357555c2011-04-28 15:09:55 -07004183
4184 /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
4185 for train result */
4186 reg = FDI_RX_IMR(pipe);
4187 temp = I915_READ(reg);
4188 temp &= ~FDI_RX_SYMBOL_LOCK;
4189 temp &= ~FDI_RX_BIT_LOCK;
4190 I915_WRITE(reg, temp);
4191
4192 POSTING_READ(reg);
4193 udelay(150);
4194
Daniel Vetter01a415f2012-10-27 15:58:40 +02004195 DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
4196 I915_READ(FDI_RX_IIR(pipe)));
4197
Jesse Barnes139ccd32013-08-19 11:04:55 -07004198 /* Try each vswing and preemphasis setting twice before moving on */
4199 for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) {
4200 /* disable first in case we need to retry */
Jesse Barnes357555c2011-04-28 15:09:55 -07004201 reg = FDI_TX_CTL(pipe);
4202 temp = I915_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004203 temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
4204 temp &= ~FDI_TX_ENABLE;
4205 I915_WRITE(reg, temp);
4206
4207 reg = FDI_RX_CTL(pipe);
4208 temp = I915_READ(reg);
4209 temp &= ~FDI_LINK_TRAIN_AUTO;
4210 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4211 temp &= ~FDI_RX_ENABLE;
4212 I915_WRITE(reg, temp);
4213
4214 /* enable CPU FDI TX and PCH FDI RX */
4215 reg = FDI_TX_CTL(pipe);
4216 temp = I915_READ(reg);
4217 temp &= ~FDI_DP_PORT_WIDTH_MASK;
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004218 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004219 temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
Jesse Barnes357555c2011-04-28 15:09:55 -07004220 temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
Jesse Barnes139ccd32013-08-19 11:04:55 -07004221 temp |= snb_b_fdi_train_param[j/2];
4222 temp |= FDI_COMPOSITE_SYNC;
4223 I915_WRITE(reg, temp | FDI_TX_ENABLE);
4224
4225 I915_WRITE(FDI_RX_MISC(pipe),
4226 FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
4227
4228 reg = FDI_RX_CTL(pipe);
4229 temp = I915_READ(reg);
4230 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4231 temp |= FDI_COMPOSITE_SYNC;
4232 I915_WRITE(reg, temp | FDI_RX_ENABLE);
4233
4234 POSTING_READ(reg);
4235 udelay(1); /* should be 0.5us */
4236
4237 for (i = 0; i < 4; i++) {
4238 reg = FDI_RX_IIR(pipe);
4239 temp = I915_READ(reg);
4240 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
4241
4242 if (temp & FDI_RX_BIT_LOCK ||
4243 (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
4244 I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
4245 DRM_DEBUG_KMS("FDI train 1 done, level %i.\n",
4246 i);
4247 break;
4248 }
4249 udelay(1); /* should be 0.5us */
4250 }
4251 if (i == 4) {
4252 DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2);
4253 continue;
4254 }
4255
4256 /* Train 2 */
4257 reg = FDI_TX_CTL(pipe);
4258 temp = I915_READ(reg);
4259 temp &= ~FDI_LINK_TRAIN_NONE_IVB;
4260 temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
4261 I915_WRITE(reg, temp);
4262
4263 reg = FDI_RX_CTL(pipe);
4264 temp = I915_READ(reg);
4265 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4266 temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
Jesse Barnes357555c2011-04-28 15:09:55 -07004267 I915_WRITE(reg, temp);
4268
4269 POSTING_READ(reg);
Jesse Barnes139ccd32013-08-19 11:04:55 -07004270 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004271
Jesse Barnes139ccd32013-08-19 11:04:55 -07004272 for (i = 0; i < 4; i++) {
4273 reg = FDI_RX_IIR(pipe);
4274 temp = I915_READ(reg);
4275 DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
Jesse Barnes357555c2011-04-28 15:09:55 -07004276
Jesse Barnes139ccd32013-08-19 11:04:55 -07004277 if (temp & FDI_RX_SYMBOL_LOCK ||
4278 (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) {
4279 I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
4280 DRM_DEBUG_KMS("FDI train 2 done, level %i.\n",
4281 i);
4282 goto train_done;
4283 }
4284 udelay(2); /* should be 1.5us */
Jesse Barnes357555c2011-04-28 15:09:55 -07004285 }
Jesse Barnes139ccd32013-08-19 11:04:55 -07004286 if (i == 4)
4287 DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2);
Jesse Barnes357555c2011-04-28 15:09:55 -07004288 }
Jesse Barnes357555c2011-04-28 15:09:55 -07004289
Jesse Barnes139ccd32013-08-19 11:04:55 -07004290train_done:
Jesse Barnes357555c2011-04-28 15:09:55 -07004291 DRM_DEBUG_KMS("FDI train done.\n");
4292}
4293
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004294static void ironlake_fdi_pll_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes0e23b992010-09-10 11:10:00 -07004295{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004296 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
4297 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004298 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004299 i915_reg_t reg;
4300 u32 temp;
Jesse Barnesc64e3112010-09-10 11:27:03 -07004301
Jesse Barnes0e23b992010-09-10 11:10:00 -07004302 /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
Chris Wilson5eddb702010-09-11 13:48:45 +01004303 reg = FDI_RX_CTL(pipe);
4304 temp = I915_READ(reg);
Daniel Vetter627eb5a2013-04-29 19:33:42 +02004305 temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16));
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02004306 temp |= FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004307 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Chris Wilson5eddb702010-09-11 13:48:45 +01004308 I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
4309
4310 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004311 udelay(200);
4312
4313 /* Switch from Rawclk to PCDclk */
Chris Wilson5eddb702010-09-11 13:48:45 +01004314 temp = I915_READ(reg);
4315 I915_WRITE(reg, temp | FDI_PCDCLK);
4316
4317 POSTING_READ(reg);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004318 udelay(200);
4319
Paulo Zanoni20749732012-11-23 15:30:38 -02004320 /* Enable CPU FDI TX PLL, always on for Ironlake */
4321 reg = FDI_TX_CTL(pipe);
4322 temp = I915_READ(reg);
4323 if ((temp & FDI_TX_PLL_ENABLE) == 0) {
4324 I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
Chris Wilson5eddb702010-09-11 13:48:45 +01004325
Paulo Zanoni20749732012-11-23 15:30:38 -02004326 POSTING_READ(reg);
4327 udelay(100);
Jesse Barnes0e23b992010-09-10 11:10:00 -07004328 }
4329}
4330
Daniel Vetter88cefb62012-08-12 19:27:14 +02004331static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
4332{
4333 struct drm_device *dev = intel_crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004334 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter88cefb62012-08-12 19:27:14 +02004335 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004336 i915_reg_t reg;
4337 u32 temp;
Daniel Vetter88cefb62012-08-12 19:27:14 +02004338
4339 /* Switch from PCDclk to Rawclk */
4340 reg = FDI_RX_CTL(pipe);
4341 temp = I915_READ(reg);
4342 I915_WRITE(reg, temp & ~FDI_PCDCLK);
4343
4344 /* Disable CPU FDI TX PLL */
4345 reg = FDI_TX_CTL(pipe);
4346 temp = I915_READ(reg);
4347 I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
4348
4349 POSTING_READ(reg);
4350 udelay(100);
4351
4352 reg = FDI_RX_CTL(pipe);
4353 temp = I915_READ(reg);
4354 I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
4355
4356 /* Wait for the clocks to turn off. */
4357 POSTING_READ(reg);
4358 udelay(100);
4359}
4360
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004361static void ironlake_fdi_disable(struct drm_crtc *crtc)
4362{
4363 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004364 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004365 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
4366 int pipe = intel_crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004367 i915_reg_t reg;
4368 u32 temp;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004369
4370 /* disable CPU FDI tx and PCH FDI rx */
4371 reg = FDI_TX_CTL(pipe);
4372 temp = I915_READ(reg);
4373 I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
4374 POSTING_READ(reg);
4375
4376 reg = FDI_RX_CTL(pipe);
4377 temp = I915_READ(reg);
4378 temp &= ~(0x7 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004379 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004380 I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
4381
4382 POSTING_READ(reg);
4383 udelay(100);
4384
4385 /* Ironlake workaround, disable clock pointer after downing FDI */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004386 if (HAS_PCH_IBX(dev_priv))
Jesse Barnes6f06ce12011-01-04 15:09:38 -08004387 I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004388
4389 /* still set train pattern 1 */
4390 reg = FDI_TX_CTL(pipe);
4391 temp = I915_READ(reg);
4392 temp &= ~FDI_LINK_TRAIN_NONE;
4393 temp |= FDI_LINK_TRAIN_PATTERN_1;
4394 I915_WRITE(reg, temp);
4395
4396 reg = FDI_RX_CTL(pipe);
4397 temp = I915_READ(reg);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004398 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004399 temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
4400 temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
4401 } else {
4402 temp &= ~FDI_LINK_TRAIN_NONE;
4403 temp |= FDI_LINK_TRAIN_PATTERN_1;
4404 }
4405 /* BPC in FDI rx is consistent with that in PIPECONF */
4406 temp &= ~(0x07 << 16);
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004407 temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
Jesse Barnes0fc932b2011-01-04 15:09:37 -08004408 I915_WRITE(reg, temp);
4409
4410 POSTING_READ(reg);
4411 udelay(100);
4412}
4413
Chris Wilson49d73912016-11-29 09:50:08 +00004414bool intel_has_pending_fb_unpin(struct drm_i915_private *dev_priv)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004415{
Daniel Vetterfa058872017-07-20 19:57:52 +02004416 struct drm_crtc *crtc;
4417 bool cleanup_done;
Chris Wilson5dce5b932014-01-20 10:17:36 +00004418
Daniel Vetterfa058872017-07-20 19:57:52 +02004419 drm_for_each_crtc(crtc, &dev_priv->drm) {
4420 struct drm_crtc_commit *commit;
4421 spin_lock(&crtc->commit_lock);
4422 commit = list_first_entry_or_null(&crtc->commit_list,
4423 struct drm_crtc_commit, commit_entry);
4424 cleanup_done = commit ?
4425 try_wait_for_completion(&commit->cleanup_done) : true;
4426 spin_unlock(&crtc->commit_lock);
4427
4428 if (cleanup_done)
Chris Wilson5dce5b932014-01-20 10:17:36 +00004429 continue;
4430
Daniel Vetterfa058872017-07-20 19:57:52 +02004431 drm_crtc_wait_one_vblank(crtc);
Chris Wilson5dce5b932014-01-20 10:17:36 +00004432
4433 return true;
4434 }
4435
4436 return false;
4437}
4438
Maarten Lankhorstb7076542016-08-23 16:18:08 +02004439void lpt_disable_iclkip(struct drm_i915_private *dev_priv)
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004440{
4441 u32 temp;
4442
4443 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
4444
4445 mutex_lock(&dev_priv->sb_lock);
4446
4447 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4448 temp |= SBI_SSCCTL_DISABLE;
4449 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
4450
4451 mutex_unlock(&dev_priv->sb_lock);
4452}
4453
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004454/* Program iCLKIP clock to the desired frequency */
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004455static void lpt_program_iclkip(const struct intel_crtc_state *crtc_state)
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004456{
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004457 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004458 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004459 int clock = crtc_state->base.adjusted_mode.crtc_clock;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004460 u32 divsel, phaseinc, auxdiv, phasedir = 0;
4461 u32 temp;
4462
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004463 lpt_disable_iclkip(dev_priv);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004464
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004465 /* The iCLK virtual clock root frequency is in MHz,
4466 * but the adjusted_mode->crtc_clock in in KHz. To get the
4467 * divisors, it is necessary to divide one by another, so we
4468 * convert the virtual clock precision to KHz here for higher
4469 * precision.
4470 */
4471 for (auxdiv = 0; auxdiv < 2; auxdiv++) {
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004472 u32 iclk_virtual_root_freq = 172800 * 1000;
4473 u32 iclk_pi_range = 64;
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004474 u32 desired_divisor;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004475
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004476 desired_divisor = DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4477 clock << auxdiv);
4478 divsel = (desired_divisor / iclk_pi_range) - 2;
4479 phaseinc = desired_divisor % iclk_pi_range;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004480
Ville Syrjälä64b46a02016-02-17 21:41:11 +02004481 /*
4482 * Near 20MHz is a corner case which is
4483 * out of range for the 7-bit divisor
4484 */
4485 if (divsel <= 0x7f)
4486 break;
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004487 }
4488
4489 /* This should not happen with any sane values */
4490 WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
4491 ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
4492 WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
4493 ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
4494
4495 DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
Ville Syrjälä12d7cee2013-09-04 18:25:19 +03004496 clock,
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004497 auxdiv,
4498 divsel,
4499 phasedir,
4500 phaseinc);
4501
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004502 mutex_lock(&dev_priv->sb_lock);
4503
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004504 /* Program SSCDIVINTPHASE6 */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004505 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004506 temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
4507 temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
4508 temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
4509 temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
4510 temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
4511 temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004512 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004513
4514 /* Program SSCAUXDIV */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004515 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004516 temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
4517 temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004518 intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004519
4520 /* Enable modulator and associated divider */
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004521 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004522 temp &= ~SBI_SSCCTL_DISABLE;
Paulo Zanoni988d6ee2012-12-01 12:04:24 -02004523 intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004524
Ville Syrjälä060f02d2015-12-04 22:21:34 +02004525 mutex_unlock(&dev_priv->sb_lock);
4526
Eugeni Dodonove615efe2012-05-09 15:37:26 -03004527 /* Wait for initialization time */
4528 udelay(24);
4529
4530 I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
4531}
4532
Ville Syrjälä8802e5b2016-02-17 21:41:12 +02004533int lpt_get_iclkip(struct drm_i915_private *dev_priv)
4534{
4535 u32 divsel, phaseinc, auxdiv;
4536 u32 iclk_virtual_root_freq = 172800 * 1000;
4537 u32 iclk_pi_range = 64;
4538 u32 desired_divisor;
4539 u32 temp;
4540
4541 if ((I915_READ(PIXCLK_GATE) & PIXCLK_GATE_UNGATE) == 0)
4542 return 0;
4543
4544 mutex_lock(&dev_priv->sb_lock);
4545
4546 temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
4547 if (temp & SBI_SSCCTL_DISABLE) {
4548 mutex_unlock(&dev_priv->sb_lock);
4549 return 0;
4550 }
4551
4552 temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
4553 divsel = (temp & SBI_SSCDIVINTPHASE_DIVSEL_MASK) >>
4554 SBI_SSCDIVINTPHASE_DIVSEL_SHIFT;
4555 phaseinc = (temp & SBI_SSCDIVINTPHASE_INCVAL_MASK) >>
4556 SBI_SSCDIVINTPHASE_INCVAL_SHIFT;
4557
4558 temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
4559 auxdiv = (temp & SBI_SSCAUXDIV_FINALDIV2SEL_MASK) >>
4560 SBI_SSCAUXDIV_FINALDIV2SEL_SHIFT;
4561
4562 mutex_unlock(&dev_priv->sb_lock);
4563
4564 desired_divisor = (divsel + 2) * iclk_pi_range + phaseinc;
4565
4566 return DIV_ROUND_CLOSEST(iclk_virtual_root_freq,
4567 desired_divisor << auxdiv);
4568}
4569
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004570static void ironlake_pch_transcoder_set_timings(const struct intel_crtc_state *crtc_state,
Daniel Vetter275f01b22013-05-03 11:49:47 +02004571 enum pipe pch_transcoder)
4572{
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004573 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
4575 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter275f01b22013-05-03 11:49:47 +02004576
4577 I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder),
4578 I915_READ(HTOTAL(cpu_transcoder)));
4579 I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder),
4580 I915_READ(HBLANK(cpu_transcoder)));
4581 I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder),
4582 I915_READ(HSYNC(cpu_transcoder)));
4583
4584 I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder),
4585 I915_READ(VTOTAL(cpu_transcoder)));
4586 I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder),
4587 I915_READ(VBLANK(cpu_transcoder)));
4588 I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder),
4589 I915_READ(VSYNC(cpu_transcoder)));
4590 I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder),
4591 I915_READ(VSYNCSHIFT(cpu_transcoder)));
4592}
4593
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004594static void cpt_set_fdi_bc_bifurcation(struct drm_i915_private *dev_priv, bool enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004595{
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004596 uint32_t temp;
4597
4598 temp = I915_READ(SOUTH_CHICKEN1);
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004599 if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004600 return;
4601
4602 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
4603 WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
4604
Ander Conselvan de Oliveira003632d2015-03-11 13:35:43 +02004605 temp &= ~FDI_BC_BIFURCATION_SELECT;
4606 if (enable)
4607 temp |= FDI_BC_BIFURCATION_SELECT;
4608
4609 DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis");
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004610 I915_WRITE(SOUTH_CHICKEN1, temp);
4611 POSTING_READ(SOUTH_CHICKEN1);
4612}
4613
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004614static void ivybridge_update_fdi_bc_bifurcation(const struct intel_crtc_state *crtc_state)
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004615{
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004616 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
4617 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004618
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004619 switch (crtc->pipe) {
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004620 case PIPE_A:
4621 break;
4622 case PIPE_B:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004623 if (crtc_state->fdi_lanes > 2)
4624 cpt_set_fdi_bc_bifurcation(dev_priv, false);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004625 else
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004626 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004627
4628 break;
4629 case PIPE_C:
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004630 cpt_set_fdi_bc_bifurcation(dev_priv, true);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004631
4632 break;
4633 default:
4634 BUG();
4635 }
4636}
4637
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004638/*
4639 * Finds the encoder associated with the given CRTC. This can only be
4640 * used when we know that the CRTC isn't feeding multiple encoders!
4641 */
4642static struct intel_encoder *
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004643intel_get_crtc_new_encoder(const struct intel_atomic_state *state,
4644 const struct intel_crtc_state *crtc_state)
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004645{
4646 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004647 const struct drm_connector_state *connector_state;
4648 const struct drm_connector *connector;
4649 struct intel_encoder *encoder = NULL;
4650 int num_encoders = 0;
4651 int i;
4652
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004653 for_each_new_connector_in_state(&state->base, connector, connector_state, i) {
Ville Syrjäläf606bc62018-05-18 18:29:25 +03004654 if (connector_state->crtc != &crtc->base)
4655 continue;
4656
4657 encoder = to_intel_encoder(connector_state->best_encoder);
4658 num_encoders++;
4659 }
4660
4661 WARN(num_encoders != 1, "%d encoders for pipe %c\n",
4662 num_encoders, pipe_name(crtc->pipe));
4663
4664 return encoder;
4665}
4666
Jesse Barnesf67a5592011-01-05 10:31:48 -08004667/*
4668 * Enable PCH resources required for PCH ports:
4669 * - PCH PLLs
4670 * - FDI training & RX/TX
4671 * - update transcoder timings
4672 * - DP transcoding bits
4673 * - transcoder
4674 */
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004675static void ironlake_pch_enable(const struct intel_atomic_state *state,
4676 const struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08004677{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004678 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004679 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004680 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira4cbe4b22017-03-02 14:58:51 +02004681 int pipe = crtc->pipe;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004682 u32 temp;
Jesse Barnes6be4a602010-09-10 10:26:01 -07004683
Daniel Vetterab9412b2013-05-03 11:49:46 +02004684 assert_pch_transcoder_disabled(dev_priv, pipe);
Chris Wilsone7e164d2012-05-11 09:21:25 +01004685
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01004686 if (IS_IVYBRIDGE(dev_priv))
Maarten Lankhorstb0b62d82018-10-11 12:04:56 +02004687 ivybridge_update_fdi_bc_bifurcation(crtc_state);
Daniel Vetter1fbc0d72013-10-29 12:04:08 +01004688
Daniel Vettercd986ab2012-10-26 10:58:12 +02004689 /* Write the TU size bits before fdi link training, so that error
4690 * detection works. */
4691 I915_WRITE(FDI_RX_TUSIZE1(pipe),
4692 I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
4693
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004694 /* For PCH output, training FDI link */
Ander Conselvan de Oliveiradc4a1092017-03-02 14:58:54 +02004695 dev_priv->display.fdi_link_train(crtc, crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07004696
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004697 /* We need to program the right clock selection before writing the pixel
4698 * mutliplier into the DPLL. */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004699 if (HAS_PCH_CPT(dev_priv)) {
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004700 u32 sel;
Jesse Barnes4b645f12011-10-12 09:51:31 -07004701
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004702 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02004703 temp |= TRANS_DPLL_ENABLE(pipe);
4704 sel = TRANS_DPLLB_SEL(pipe);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004705 if (crtc_state->shared_dpll ==
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02004706 intel_get_shared_dpll_by_id(dev_priv, DPLL_ID_PCH_PLL_B))
Jesse Barnesee7b9f92012-04-20 17:11:53 +01004707 temp |= sel;
4708 else
4709 temp &= ~sel;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004710 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004711 }
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004712
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004713 /* XXX: pch pll's can be enabled any time before we enable the PCH
4714 * transcoder, and we actually should do this to not upset any PCH
4715 * transcoder that already use the clock when we share it.
4716 *
4717 * Note that enable_shared_dpll tries to do the right thing, but
4718 * get_shared_dpll unconditionally resets the pll - we need that to have
4719 * the right LVDS enable sequence. */
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02004720 intel_enable_shared_dpll(crtc_state);
Daniel Vetter3ad8a202013-06-05 13:34:32 +02004721
Jesse Barnesd9b6cb52011-01-04 15:09:35 -08004722 /* set transcoder timing, panel must allow it */
4723 assert_panel_unlocked(dev_priv, pipe);
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004724 ironlake_pch_transcoder_set_timings(crtc_state, pipe);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004725
Paulo Zanoni303b81e2012-10-31 18:12:23 -02004726 intel_fdi_normal_train(crtc);
Zhenyu Wang5e84e1a2010-10-28 16:38:08 +08004727
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004728 /* For PCH DP, enable TRANS_DP_CTL */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004729 if (HAS_PCH_CPT(dev_priv) &&
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004730 intel_crtc_has_dp_encoder(crtc_state)) {
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004731 const struct drm_display_mode *adjusted_mode =
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004732 &crtc_state->base.adjusted_mode;
Daniel Vetterdfd07d72012-12-17 11:21:38 +01004733 u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004734 i915_reg_t reg = TRANS_DP_CTL(pipe);
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004735 enum port port;
4736
Chris Wilson5eddb702010-09-11 13:48:45 +01004737 temp = I915_READ(reg);
4738 temp &= ~(TRANS_DP_PORT_SEL_MASK |
Eric Anholt220cad32010-11-18 09:32:58 +08004739 TRANS_DP_SYNC_MASK |
4740 TRANS_DP_BPC_MASK);
Ville Syrjäläe3ef4472015-05-05 17:17:31 +03004741 temp |= TRANS_DP_OUTPUT_ENABLE;
Jesse Barnes9325c9f2011-06-24 12:19:21 -07004742 temp |= bpc << 9; /* same format but at 11:9 */
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004743
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004744 if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004745 temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
Ville Syrjälä9c4edae2015-10-29 21:25:51 +02004746 if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
Chris Wilson5eddb702010-09-11 13:48:45 +01004747 temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004748
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004749 port = intel_get_crtc_new_encoder(state, crtc_state)->port;
Ville Syrjäläf67dc6d2018-05-18 18:29:26 +03004750 WARN_ON(port < PORT_B || port > PORT_D);
4751 temp |= TRANS_DP_PORT_SEL(port);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004752
Chris Wilson5eddb702010-09-11 13:48:45 +01004753 I915_WRITE(reg, temp);
Jesse Barnesc98e9dc2010-09-10 10:57:18 -07004754 }
4755
Maarten Lankhorst7efd90f2018-10-04 11:45:55 +02004756 ironlake_enable_pch_transcoder(crtc_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004757}
4758
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03004759static void lpt_pch_enable(const struct intel_atomic_state *state,
4760 const struct intel_crtc_state *crtc_state)
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004761{
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004762 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ander Conselvan de Oliveira0dcdc382017-03-02 14:58:52 +02004763 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ander Conselvan de Oliveira2ce42272017-03-02 14:58:53 +02004764 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004765
Matthias Kaehlckea2196032017-07-17 11:14:03 -07004766 assert_pch_transcoder_disabled(dev_priv, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004767
Maarten Lankhorstc5b36fa2018-10-11 12:04:55 +02004768 lpt_program_iclkip(crtc_state);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004769
Paulo Zanoni0540e482012-10-31 18:12:40 -02004770 /* Set transcoder timing. */
Maarten Lankhorst5e1cdf52018-10-04 11:45:58 +02004771 ironlake_pch_transcoder_set_timings(crtc_state, PIPE_A);
Paulo Zanoni1507e5b2012-10-31 18:12:22 -02004772
Paulo Zanoni937bb612012-10-31 18:12:47 -02004773 lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
Jesse Barnesf67a5592011-01-05 10:31:48 -08004774}
4775
Daniel Vettera1520312013-05-03 11:49:50 +02004776static void cpt_verify_modeset(struct drm_device *dev, int pipe)
Jesse Barnesd4270e52011-10-11 10:43:02 -07004777{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004778 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004779 i915_reg_t dslreg = PIPEDSL(pipe);
Jesse Barnesd4270e52011-10-11 10:43:02 -07004780 u32 temp;
4781
4782 temp = I915_READ(dslreg);
4783 udelay(500);
4784 if (wait_for(I915_READ(dslreg) != temp, 5)) {
Jesse Barnesd4270e52011-10-11 10:43:02 -07004785 if (wait_for(I915_READ(dslreg) != temp, 5))
Ville Syrjälä84f44ce2013-04-17 17:48:49 +03004786 DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe));
Jesse Barnesd4270e52011-10-11 10:43:02 -07004787 }
4788}
4789
Ville Syrjälä0a599522018-05-21 21:56:13 +03004790/*
4791 * The hardware phase 0.0 refers to the center of the pixel.
4792 * We want to start from the top/left edge which is phase
4793 * -0.5. That matches how the hardware calculates the scaling
4794 * factors (from top-left of the first pixel to bottom-right
4795 * of the last pixel, as opposed to the pixel centers).
4796 *
4797 * For 4:2:0 subsampled chroma planes we obviously have to
4798 * adjust that so that the chroma sample position lands in
4799 * the right spot.
4800 *
4801 * Note that for packed YCbCr 4:2:2 formats there is no way to
4802 * control chroma siting. The hardware simply replicates the
4803 * chroma samples for both of the luma samples, and thus we don't
4804 * actually get the expected MPEG2 chroma siting convention :(
4805 * The same behaviour is observed on pre-SKL platforms as well.
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004806 *
4807 * Theory behind the formula (note that we ignore sub-pixel
4808 * source coordinates):
4809 * s = source sample position
4810 * d = destination sample position
4811 *
4812 * Downscaling 4:1:
4813 * -0.5
4814 * | 0.0
4815 * | | 1.5 (initial phase)
4816 * | | |
4817 * v v v
4818 * | s | s | s | s |
4819 * | d |
4820 *
4821 * Upscaling 1:4:
4822 * -0.5
4823 * | -0.375 (initial phase)
4824 * | | 0.0
4825 * | | |
4826 * v v v
4827 * | s |
4828 * | d | d | d | d |
Ville Syrjälä0a599522018-05-21 21:56:13 +03004829 */
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004830u16 skl_scaler_calc_phase(int sub, int scale, bool chroma_cosited)
Ville Syrjälä0a599522018-05-21 21:56:13 +03004831{
4832 int phase = -0x8000;
4833 u16 trip = 0;
4834
4835 if (chroma_cosited)
4836 phase += (sub - 1) * 0x8000 / sub;
4837
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02004838 phase += scale / (2 * sub);
4839
4840 /*
4841 * Hardware initial phase limited to [-0.5:1.5].
4842 * Since the max hardware scale factor is 3.0, we
4843 * should never actually excdeed 1.0 here.
4844 */
4845 WARN_ON(phase < -0x8000 || phase > 0x18000);
4846
Ville Syrjälä0a599522018-05-21 21:56:13 +03004847 if (phase < 0)
4848 phase = 0x10000 + phase;
4849 else
4850 trip = PS_PHASE_TRIP;
4851
4852 return ((phase >> 2) & PS_PHASE_MASK) | trip;
4853}
4854
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004855static int
4856skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach,
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004857 unsigned int scaler_user, int *scaler_id,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304858 int src_w, int src_h, int dst_w, int dst_h,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004859 const struct drm_format_info *format, bool need_scaler)
Chandra Kondurua1b22782015-04-07 15:28:45 -07004860{
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004861 struct intel_crtc_scaler_state *scaler_state =
4862 &crtc_state->scaler_state;
4863 struct intel_crtc *intel_crtc =
4864 to_intel_crtc(crtc_state->base.crtc);
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304865 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
4866 const struct drm_display_mode *adjusted_mode =
4867 &crtc_state->base.adjusted_mode;
Chandra Konduru6156a452015-04-27 13:48:39 -07004868
Ville Syrjäläd96a7d22017-03-31 21:00:54 +03004869 /*
4870 * Src coordinates are already rotated by 270 degrees for
4871 * the 90/270 degree plane rotation cases (to match the
4872 * GTT mapping), hence no need to account for rotation here.
4873 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004874 if (src_w != dst_w || src_h != dst_h)
4875 need_scaler = true;
Shashank Sharmae5c05932017-07-21 20:55:05 +05304876
Chandra Kondurua1b22782015-04-07 15:28:45 -07004877 /*
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304878 * Scaling/fitting not supported in IF-ID mode in GEN9+
4879 * TODO: Interlace fetch mode doesn't support YUV420 planar formats.
4880 * Once NV12 is enabled, handle it here while allocating scaler
4881 * for NV12.
4882 */
4883 if (INTEL_GEN(dev_priv) >= 9 && crtc_state->base.enable &&
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004884 need_scaler && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Mahesh Kumar7f58cbb2017-06-30 17:41:00 +05304885 DRM_DEBUG_KMS("Pipe/Plane scaling not supported with IF-ID mode\n");
4886 return -EINVAL;
4887 }
4888
4889 /*
Chandra Kondurua1b22782015-04-07 15:28:45 -07004890 * if plane is being disabled or scaler is no more required or force detach
4891 * - free scaler binded to this plane/crtc
4892 * - in order to do this, update crtc->scaler_usage
4893 *
4894 * Here scaler state in crtc_state is set free so that
4895 * scaler can be assigned to other user. Actual register
4896 * update to free the scaler is done in plane/panel-fit programming.
4897 * For this purpose crtc/plane_state->scaler_id isn't reset here.
4898 */
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004899 if (force_detach || !need_scaler) {
Chandra Kondurua1b22782015-04-07 15:28:45 -07004900 if (*scaler_id >= 0) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004901 scaler_state->scaler_users &= ~(1 << scaler_user);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004902 scaler_state->scalers[*scaler_id].in_use = 0;
4903
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004904 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4905 "Staged freeing scaler id %d scaler_users = 0x%x\n",
4906 intel_crtc->pipe, scaler_user, *scaler_id,
Chandra Kondurua1b22782015-04-07 15:28:45 -07004907 scaler_state->scaler_users);
4908 *scaler_id = -1;
4909 }
4910 return 0;
4911 }
4912
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004913 if (format && format->format == DRM_FORMAT_NV12 &&
Maarten Lankhorst5d794282018-05-12 03:03:14 +05304914 (src_h < SKL_MIN_YUV_420_SRC_H || src_w < SKL_MIN_YUV_420_SRC_W)) {
Chandra Konduru77224cd2018-04-09 09:11:13 +05304915 DRM_DEBUG_KMS("NV12: src dimensions not met\n");
4916 return -EINVAL;
4917 }
4918
Chandra Kondurua1b22782015-04-07 15:28:45 -07004919 /* range checks */
4920 if (src_w < SKL_MIN_SRC_W || src_h < SKL_MIN_SRC_H ||
Nabendu Maiti323301a2018-03-23 10:24:18 -07004921 dst_w < SKL_MIN_DST_W || dst_h < SKL_MIN_DST_H ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004922 (IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07004923 (src_w > ICL_MAX_SRC_W || src_h > ICL_MAX_SRC_H ||
4924 dst_w > ICL_MAX_DST_W || dst_h > ICL_MAX_DST_H)) ||
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004925 (!IS_GEN(dev_priv, 11) &&
Nabendu Maiti323301a2018-03-23 10:24:18 -07004926 (src_w > SKL_MAX_SRC_W || src_h > SKL_MAX_SRC_H ||
4927 dst_w > SKL_MAX_DST_W || dst_h > SKL_MAX_DST_H))) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004928 DRM_DEBUG_KMS("scaler_user index %u.%u: src %ux%u dst %ux%u "
Chandra Kondurua1b22782015-04-07 15:28:45 -07004929 "size is out of scaler range\n",
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004930 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h);
Chandra Kondurua1b22782015-04-07 15:28:45 -07004931 return -EINVAL;
4932 }
4933
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004934 /* mark this plane as a scaler user in crtc_state */
4935 scaler_state->scaler_users |= (1 << scaler_user);
4936 DRM_DEBUG_KMS("scaler_user index %u.%u: "
4937 "staged scaling request for %ux%u->%ux%u scaler_users = 0x%x\n",
4938 intel_crtc->pipe, scaler_user, src_w, src_h, dst_w, dst_h,
4939 scaler_state->scaler_users);
4940
4941 return 0;
4942}
4943
4944/**
4945 * skl_update_scaler_crtc - Stages update to scaler state for a given crtc.
4946 *
4947 * @state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004948 *
4949 * Return
4950 * 0 - scaler_usage updated successfully
4951 * error - requested scaling cannot be supported or other error condition
4952 */
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004953int skl_update_scaler_crtc(struct intel_crtc_state *state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004954{
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03004955 const struct drm_display_mode *adjusted_mode = &state->base.adjusted_mode;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004956 bool need_scaler = false;
4957
4958 if (state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
4959 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004960
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02004961 return skl_update_scaler(state, !state->base.active, SKL_CRTC_INDEX,
Chandra Konduru77224cd2018-04-09 09:11:13 +05304962 &state->scaler_state.scaler_id,
4963 state->pipe_src_w, state->pipe_src_h,
4964 adjusted_mode->crtc_hdisplay,
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004965 adjusted_mode->crtc_vdisplay, NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004966}
4967
4968/**
4969 * skl_update_scaler_plane - Stages update to scaler state for a given plane.
Chris Wilsonc38c1452018-02-14 13:49:22 +00004970 * @crtc_state: crtc's scaler state
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004971 * @plane_state: atomic plane state to update
4972 *
4973 * Return
4974 * 0 - scaler_usage updated successfully
4975 * error - requested scaling cannot be supported or other error condition
4976 */
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004977static int skl_update_scaler_plane(struct intel_crtc_state *crtc_state,
4978 struct intel_plane_state *plane_state)
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004979{
Maarten Lankhorstda20eab2015-06-15 12:33:44 +02004980 struct intel_plane *intel_plane =
4981 to_intel_plane(plane_state->base.plane);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004982 struct drm_framebuffer *fb = plane_state->base.fb;
4983 int ret;
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004984 bool force_detach = !fb || !plane_state->base.visible;
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004985 bool need_scaler = false;
4986
4987 /* Pre-gen11 and SDR planes always need a scaler for planar formats. */
4988 if (!icl_is_hdr_plane(intel_plane) &&
4989 fb && fb->format->format == DRM_FORMAT_NV12)
4990 need_scaler = true;
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004991
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02004992 ret = skl_update_scaler(crtc_state, force_detach,
4993 drm_plane_index(&intel_plane->base),
4994 &plane_state->scaler_id,
Ville Syrjälä936e71e2016-07-26 19:06:59 +03004995 drm_rect_width(&plane_state->base.src) >> 16,
4996 drm_rect_height(&plane_state->base.src) >> 16,
4997 drm_rect_width(&plane_state->base.dst),
Chandra Konduru77224cd2018-04-09 09:11:13 +05304998 drm_rect_height(&plane_state->base.dst),
Maarten Lankhorstb1554e22018-10-18 13:51:31 +02004999 fb ? fb->format : NULL, need_scaler);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005000
5001 if (ret || plane_state->scaler_id < 0)
5002 return ret;
5003
Chandra Kondurua1b22782015-04-07 15:28:45 -07005004 /* check colorkey */
Ville Syrjälä6ec5bd32018-02-02 22:42:31 +02005005 if (plane_state->ckey.flags) {
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005006 DRM_DEBUG_KMS("[PLANE:%d:%s] scaling with color key not allowed",
5007 intel_plane->base.base.id,
5008 intel_plane->base.name);
Chandra Kondurua1b22782015-04-07 15:28:45 -07005009 return -EINVAL;
5010 }
5011
5012 /* Check src format */
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005013 switch (fb->format->format) {
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005014 case DRM_FORMAT_RGB565:
5015 case DRM_FORMAT_XBGR8888:
5016 case DRM_FORMAT_XRGB8888:
5017 case DRM_FORMAT_ABGR8888:
5018 case DRM_FORMAT_ARGB8888:
5019 case DRM_FORMAT_XRGB2101010:
5020 case DRM_FORMAT_XBGR2101010:
5021 case DRM_FORMAT_YUYV:
5022 case DRM_FORMAT_YVYU:
5023 case DRM_FORMAT_UYVY:
5024 case DRM_FORMAT_VYUY:
Chandra Konduru77224cd2018-04-09 09:11:13 +05305025 case DRM_FORMAT_NV12:
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005026 break;
5027 default:
Ville Syrjälä72660ce2016-05-27 20:59:20 +03005028 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d unsupported scaling format 0x%x\n",
5029 intel_plane->base.base.id, intel_plane->base.name,
Ville Syrjälä438b74a2016-12-14 23:32:55 +02005030 fb->base.id, fb->format->format);
Maarten Lankhorst86adf9d2015-06-22 09:50:32 +02005031 return -EINVAL;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005032 }
5033
Chandra Kondurua1b22782015-04-07 15:28:45 -07005034 return 0;
5035}
5036
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005037static void skylake_scaler_disable(struct intel_crtc *crtc)
5038{
5039 int i;
5040
5041 for (i = 0; i < crtc->num_scalers; i++)
5042 skl_detach_scaler(crtc, i);
5043}
5044
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005045static void skylake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005046{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005047 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5048 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5049 enum pipe pipe = crtc->pipe;
5050 const struct intel_crtc_scaler_state *scaler_state =
5051 &crtc_state->scaler_state;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005052
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005053 if (crtc_state->pch_pfit.enabled) {
Ville Syrjälä0a599522018-05-21 21:56:13 +03005054 u16 uv_rgb_hphase, uv_rgb_vphase;
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005055 int pfit_w, pfit_h, hscale, vscale;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005056 int id;
5057
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005058 if (WARN_ON(crtc_state->scaler_state.scaler_id < 0))
Chandra Kondurua1b22782015-04-07 15:28:45 -07005059 return;
Chandra Kondurua1b22782015-04-07 15:28:45 -07005060
Ville Syrjäläe7a278a2018-10-29 20:18:20 +02005061 pfit_w = (crtc_state->pch_pfit.size >> 16) & 0xFFFF;
5062 pfit_h = crtc_state->pch_pfit.size & 0xFFFF;
5063
5064 hscale = (crtc_state->pipe_src_w << 16) / pfit_w;
5065 vscale = (crtc_state->pipe_src_h << 16) / pfit_h;
5066
5067 uv_rgb_hphase = skl_scaler_calc_phase(1, hscale, false);
5068 uv_rgb_vphase = skl_scaler_calc_phase(1, vscale, false);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005069
Chandra Kondurua1b22782015-04-07 15:28:45 -07005070 id = scaler_state->scaler_id;
5071 I915_WRITE(SKL_PS_CTRL(pipe, id), PS_SCALER_EN |
5072 PS_FILTER_MEDIUM | scaler_state->scalers[id].mode);
Ville Syrjälä0a599522018-05-21 21:56:13 +03005073 I915_WRITE_FW(SKL_PS_VPHASE(pipe, id),
5074 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_vphase));
5075 I915_WRITE_FW(SKL_PS_HPHASE(pipe, id),
5076 PS_Y_PHASE(0) | PS_UV_RGB_PHASE(uv_rgb_hphase));
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005077 I915_WRITE(SKL_PS_WIN_POS(pipe, id), crtc_state->pch_pfit.pos);
5078 I915_WRITE(SKL_PS_WIN_SZ(pipe, id), crtc_state->pch_pfit.size);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00005079 }
5080}
5081
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005082static void ironlake_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnesb074cec2013-04-25 12:55:02 -07005083{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005084 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5085 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesb074cec2013-04-25 12:55:02 -07005086 int pipe = crtc->pipe;
5087
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005088 if (crtc_state->pch_pfit.enabled) {
Jesse Barnesb074cec2013-04-25 12:55:02 -07005089 /* Force use of hard-coded filter coefficients
5090 * as some pre-programmed values are broken,
5091 * e.g. x201.
5092 */
Tvrtko Ursulinfd6b8f42016-10-14 10:13:06 +01005093 if (IS_IVYBRIDGE(dev_priv) || IS_HASWELL(dev_priv))
Jesse Barnesb074cec2013-04-25 12:55:02 -07005094 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
5095 PF_PIPE_SEL_IVB(pipe));
5096 else
5097 I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005098 I915_WRITE(PF_WIN_POS(pipe), crtc_state->pch_pfit.pos);
5099 I915_WRITE(PF_WIN_SZ(pipe), crtc_state->pch_pfit.size);
Jesse Barnes040484a2011-01-03 12:14:26 -08005100 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005101}
5102
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005103void hsw_enable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005104{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005105 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Ville Syrjäläcea165c2014-04-15 21:41:35 +03005106 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005107 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005108
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005109 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005110 return;
5111
Maarten Lankhorst307e4492016-03-23 14:33:28 +01005112 /*
5113 * We can only enable IPS after we enable a plane and wait for a vblank
5114 * This function is called from post_plane_update, which is run after
5115 * a vblank wait.
5116 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005117 WARN_ON(!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)));
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02005118
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005119 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005120 mutex_lock(&dev_priv->pcu_lock);
Ville Syrjälä61843f02017-09-12 18:34:11 +03005121 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL,
5122 IPS_ENABLE | IPS_PCODE_CONTROL));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005123 mutex_unlock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005124 /* Quoting Art Runyan: "its not safe to expect any particular
5125 * value in IPS_CTL bit 31 after enabling IPS through the
Jesse Barnese59150d2014-01-07 13:30:45 -08005126 * mailbox." Moreover, the mailbox may return a bogus state,
5127 * so we need to just enable it and continue on.
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005128 */
5129 } else {
5130 I915_WRITE(IPS_CTL, IPS_ENABLE);
5131 /* The bit only becomes 1 in the next vblank, so this wait here
5132 * is essentially intel_wait_for_vblank. If we don't have this
5133 * and don't wait for vblanks until the end of crtc_enable, then
5134 * the HW state readout code will complain that the expected
5135 * IPS_CTL value is not the one we read. */
Chris Wilson2ec9ba32016-06-30 15:33:01 +01005136 if (intel_wait_for_register(dev_priv,
5137 IPS_CTL, IPS_ENABLE, IPS_ENABLE,
5138 50))
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005139 DRM_ERROR("Timed out waiting for IPS enable\n");
5140 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005141}
5142
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005143void hsw_disable_ips(const struct intel_crtc_state *crtc_state)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005144{
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005145 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005146 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005147 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005148
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005149 if (!crtc_state->ips_enabled)
Paulo Zanonid77e4532013-09-24 13:52:55 -03005150 return;
5151
Tvrtko Ursulin86527442016-10-13 11:03:00 +01005152 if (IS_BROADWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005153 mutex_lock(&dev_priv->pcu_lock);
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005154 WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0));
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01005155 mutex_unlock(&dev_priv->pcu_lock);
Imre Deakacb3ef02018-09-05 13:00:05 +03005156 /*
5157 * Wait for PCODE to finish disabling IPS. The BSpec specified
5158 * 42ms timeout value leads to occasional timeouts so use 100ms
5159 * instead.
5160 */
Chris Wilsonb85c1ec2016-06-30 15:33:02 +01005161 if (intel_wait_for_register(dev_priv,
5162 IPS_CTL, IPS_ENABLE, 0,
Imre Deakacb3ef02018-09-05 13:00:05 +03005163 100))
Ben Widawsky23d0b132014-04-10 14:32:41 -07005164 DRM_ERROR("Timed out waiting for IPS disable\n");
Jesse Barnese59150d2014-01-07 13:30:45 -08005165 } else {
Ben Widawsky2a114cc2013-11-02 21:07:47 -07005166 I915_WRITE(IPS_CTL, 0);
Jesse Barnese59150d2014-01-07 13:30:45 -08005167 POSTING_READ(IPS_CTL);
5168 }
Paulo Zanonid77e4532013-09-24 13:52:55 -03005169
5170 /* We need to wait for a vblank before we can disable the plane. */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005171 intel_wait_for_vblank(dev_priv, crtc->pipe);
Paulo Zanonid77e4532013-09-24 13:52:55 -03005172}
5173
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005174static void intel_crtc_dpms_overlay_disable(struct intel_crtc *intel_crtc)
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005175{
Maarten Lankhorst7cac9452015-04-21 17:12:55 +03005176 if (intel_crtc->overlay) {
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005177 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005178
5179 mutex_lock(&dev->struct_mutex);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005180 (void) intel_overlay_switch_off(intel_crtc->overlay);
Ville Syrjäläd3eedb12014-05-08 19:23:13 +03005181 mutex_unlock(&dev->struct_mutex);
5182 }
5183
5184 /* Let userspace switch the overlay on again. In most cases userspace
5185 * has to recompute where to put it anyway.
5186 */
5187}
5188
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005189/**
5190 * intel_post_enable_primary - Perform operations after enabling primary plane
5191 * @crtc: the CRTC whose primary plane was just enabled
Chris Wilsonc38c1452018-02-14 13:49:22 +00005192 * @new_crtc_state: the enabling state
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005193 *
5194 * Performs potentially sleeping operations that must be done after the primary
5195 * plane is enabled, such as updating FBC and IPS. Note that this may be
5196 * called due to an explicit primary plane update, or due to an implicit
5197 * re-enable that is caused when a sprite plane is updated to no longer
5198 * completely hide the primary plane.
5199 */
5200static void
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005201intel_post_enable_primary(struct drm_crtc *crtc,
5202 const struct intel_crtc_state *new_crtc_state)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005203{
5204 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005205 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005206 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5207 int pipe = intel_crtc->pipe;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005208
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005209 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005210 * Gen2 reports pipe underruns whenever all planes are disabled.
5211 * So don't enable underrun reporting before at least some planes
5212 * are enabled.
5213 * FIXME: Need to fix the logic to work when we turn off all planes
5214 * but leave the pipe running.
Daniel Vetterf99d7062014-06-19 16:01:59 +02005215 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005216 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005217 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
5218
Ville Syrjäläaca7b682015-10-30 19:22:21 +02005219 /* Underruns don't always raise interrupts, so check manually. */
5220 intel_check_cpu_fifo_underruns(dev_priv);
5221 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005222}
5223
Ville Syrjälä2622a082016-03-09 19:07:26 +02005224/* FIXME get rid of this and use pre_plane_update */
5225static void
5226intel_pre_disable_primary_noatomic(struct drm_crtc *crtc)
5227{
5228 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005229 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä2622a082016-03-09 19:07:26 +02005230 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5231 int pipe = intel_crtc->pipe;
5232
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005233 /*
5234 * Gen2 reports pipe underruns whenever all planes are disabled.
5235 * So disable underrun reporting before all the planes get disabled.
5236 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005237 if (IS_GEN(dev_priv, 2))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005238 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5239
5240 hsw_disable_ips(to_intel_crtc_state(crtc->state));
Ville Syrjälä2622a082016-03-09 19:07:26 +02005241
5242 /*
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005243 * Vblank time updates from the shadow to live plane control register
5244 * are blocked if the memory self-refresh mode is active at that
5245 * moment. So to make sure the plane gets truly disabled, disable
5246 * first the self-refresh mode. The self-refresh enable bit in turn
5247 * will be checked/applied by the HW only at the next frame start
5248 * event which is after the vblank start event, so we need to have a
5249 * wait-for-vblank between disabling the plane and the pipe.
5250 */
Ville Syrjälä11a85d62016-11-28 19:37:12 +02005251 if (HAS_GMCH_DISPLAY(dev_priv) &&
5252 intel_set_memory_cxsr(dev_priv, false))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005253 intel_wait_for_vblank(dev_priv, pipe);
Maarten Lankhorst87d43002015-04-21 17:12:54 +03005254}
5255
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005256static bool hsw_pre_update_disable_ips(const struct intel_crtc_state *old_crtc_state,
5257 const struct intel_crtc_state *new_crtc_state)
5258{
5259 if (!old_crtc_state->ips_enabled)
5260 return false;
5261
5262 if (needs_modeset(&new_crtc_state->base))
5263 return true;
5264
5265 return !new_crtc_state->ips_enabled;
5266}
5267
5268static bool hsw_post_update_enable_ips(const struct intel_crtc_state *old_crtc_state,
5269 const struct intel_crtc_state *new_crtc_state)
5270{
5271 if (!new_crtc_state->ips_enabled)
5272 return false;
5273
5274 if (needs_modeset(&new_crtc_state->base))
5275 return true;
5276
5277 /*
5278 * We can't read out IPS on broadwell, assume the worst and
5279 * forcibly enable IPS on the first fastset.
5280 */
5281 if (new_crtc_state->update_pipe &&
5282 old_crtc_state->base.adjusted_mode.private_flags & I915_MODE_FLAG_INHERITED)
5283 return true;
5284
5285 return !old_crtc_state->ips_enabled;
5286}
5287
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305288static bool needs_nv12_wa(struct drm_i915_private *dev_priv,
5289 const struct intel_crtc_state *crtc_state)
5290{
5291 if (!crtc_state->nv12_planes)
5292 return false;
5293
Rodrigo Vivi1347d3c2018-10-31 09:28:45 -07005294 /* WA Display #0827: Gen9:all */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005295 if (IS_GEN(dev_priv, 9) && !IS_GEMINILAKE(dev_priv))
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305296 return true;
5297
5298 return false;
5299}
5300
Daniel Vetter5a21b662016-05-24 17:13:53 +02005301static void intel_post_plane_update(struct intel_crtc_state *old_crtc_state)
5302{
5303 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Vidya Srinivasc4a4efa2018-04-09 09:11:09 +05305304 struct drm_device *dev = crtc->base.dev;
5305 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005306 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5307 struct intel_crtc_state *pipe_config =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005308 intel_atomic_get_new_crtc_state(to_intel_atomic_state(old_state),
5309 crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005310 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005311 struct drm_plane_state *old_primary_state =
5312 drm_atomic_get_old_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005313
Chris Wilson5748b6a2016-08-04 16:32:38 +01005314 intel_frontbuffer_flip(to_i915(crtc->base.dev), pipe_config->fb_bits);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005315
Daniel Vetter5a21b662016-05-24 17:13:53 +02005316 if (pipe_config->update_wm_post && pipe_config->base.active)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005317 intel_update_watermarks(crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005318
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005319 if (hsw_post_update_enable_ips(old_crtc_state, pipe_config))
5320 hsw_enable_ips(pipe_config);
5321
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005322 if (old_primary_state) {
5323 struct drm_plane_state *new_primary_state =
5324 drm_atomic_get_new_plane_state(old_state, primary);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005325
5326 intel_fbc_post_update(crtc);
5327
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005328 if (new_primary_state->visible &&
Daniel Vetter5a21b662016-05-24 17:13:53 +02005329 (needs_modeset(&pipe_config->base) ||
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005330 !old_primary_state->visible))
Maarten Lankhorst199ea382017-11-10 12:35:00 +01005331 intel_post_enable_primary(&crtc->base, pipe_config);
Daniel Vetter5a21b662016-05-24 17:13:53 +02005332 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305333
5334 /* Display WA 827 */
5335 if (needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305336 !needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305337 skl_wa_clkgate(dev_priv, crtc->pipe, false);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305338 }
Daniel Vetter5a21b662016-05-24 17:13:53 +02005339}
5340
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005341static void intel_pre_plane_update(struct intel_crtc_state *old_crtc_state,
5342 struct intel_crtc_state *pipe_config)
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005343{
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005344 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005345 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005346 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005347 struct drm_atomic_state *old_state = old_crtc_state->base.state;
5348 struct drm_plane *primary = crtc->base.primary;
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005349 struct drm_plane_state *old_primary_state =
5350 drm_atomic_get_old_plane_state(old_state, primary);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005351 bool modeset = needs_modeset(&pipe_config->base);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005352 struct intel_atomic_state *old_intel_state =
5353 to_intel_atomic_state(old_state);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005354
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005355 if (hsw_pre_update_disable_ips(old_crtc_state, pipe_config))
5356 hsw_disable_ips(old_crtc_state);
5357
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005358 if (old_primary_state) {
5359 struct intel_plane_state *new_primary_state =
Ville Syrjäläf9a8c142017-08-23 18:22:24 +03005360 intel_atomic_get_new_plane_state(old_intel_state,
5361 to_intel_plane(primary));
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005362
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005363 intel_fbc_pre_update(crtc, pipe_config, new_primary_state);
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005364 /*
5365 * Gen2 reports pipe underruns whenever all planes are disabled.
5366 * So disable underrun reporting before all the planes get disabled.
5367 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08005368 if (IS_GEN(dev_priv, 2) && old_primary_state->visible &&
Maarten Lankhorst8b694492018-04-09 14:46:55 +02005369 (modeset || !new_primary_state->base.visible))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01005370 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, false);
Maarten Lankhorst5c74cd72016-02-03 16:53:24 +01005371 }
Ville Syrjälä852eb002015-06-24 22:00:07 +03005372
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305373 /* Display WA 827 */
5374 if (!needs_nv12_wa(dev_priv, old_crtc_state) &&
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305375 needs_nv12_wa(dev_priv, pipe_config)) {
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305376 skl_wa_clkgate(dev_priv, crtc->pipe, true);
Vidya Srinivas6deef9b602018-05-12 03:03:13 +05305377 }
Maarten Lankhorst8e021152018-05-12 03:03:12 +05305378
Ville Syrjälä5eeb7982017-03-02 19:15:00 +02005379 /*
5380 * Vblank time updates from the shadow to live plane control register
5381 * are blocked if the memory self-refresh mode is active at that
5382 * moment. So to make sure the plane gets truly disabled, disable
5383 * first the self-refresh mode. The self-refresh enable bit in turn
5384 * will be checked/applied by the HW only at the next frame start
5385 * event which is after the vblank start event, so we need to have a
5386 * wait-for-vblank between disabling the plane and the pipe.
5387 */
5388 if (HAS_GMCH_DISPLAY(dev_priv) && old_crtc_state->base.active &&
5389 pipe_config->disable_cxsr && intel_set_memory_cxsr(dev_priv, false))
5390 intel_wait_for_vblank(dev_priv, crtc->pipe);
Maarten Lankhorst92826fc2015-12-03 13:49:13 +01005391
Matt Ropered4a6a72016-02-23 17:20:13 -08005392 /*
5393 * IVB workaround: must disable low power watermarks for at least
5394 * one frame before enabling scaling. LP watermarks can be re-enabled
5395 * when scaling is disabled.
5396 *
5397 * WaCxSRDisabledForSpriteScaling:ivb
5398 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +03005399 if (pipe_config->disable_lp_wm && ilk_disable_lp_wm(dev) &&
5400 old_crtc_state->base.active)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005401 intel_wait_for_vblank(dev_priv, crtc->pipe);
Matt Ropered4a6a72016-02-23 17:20:13 -08005402
5403 /*
5404 * If we're doing a modeset, we're done. No need to do any pre-vblank
5405 * watermark programming here.
5406 */
5407 if (needs_modeset(&pipe_config->base))
5408 return;
5409
5410 /*
5411 * For platforms that support atomic watermarks, program the
5412 * 'intermediate' watermarks immediately. On pre-gen9 platforms, these
5413 * will be the intermediate values that are safe for both pre- and
5414 * post- vblank; when vblank happens, the 'active' values will be set
5415 * to the final 'target' values and we'll do this again to get the
5416 * optimal watermarks. For gen9+ platforms, the values we program here
5417 * will be the final target values which will get automatically latched
5418 * at vblank time; no further programming will be necessary.
5419 *
5420 * If a platform hasn't been transitioned to atomic watermarks yet,
5421 * we'll continue to update watermarks the old way, if flags tell
5422 * us to.
5423 */
5424 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005425 dev_priv->display.initial_watermarks(old_intel_state,
5426 pipe_config);
Ville Syrjäläcaed3612016-03-09 19:07:25 +02005427 else if (pipe_config->update_wm_pre)
Ville Syrjälä432081b2016-10-31 22:37:03 +02005428 intel_update_watermarks(crtc);
Maarten Lankhorstac21b222015-06-15 12:33:49 +02005429}
5430
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005431static void intel_crtc_disable_planes(struct intel_atomic_state *state,
5432 struct intel_crtc *crtc)
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005433{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005434 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5435 const struct intel_crtc_state *new_crtc_state =
5436 intel_atomic_get_new_crtc_state(state, crtc);
5437 unsigned int update_mask = new_crtc_state->update_planes;
5438 const struct intel_plane_state *old_plane_state;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005439 struct intel_plane *plane;
5440 unsigned fb_bits = 0;
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005441 int i;
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005442
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005443 intel_crtc_dpms_overlay_disable(crtc);
Maarten Lankhorst27321ae2015-04-21 17:12:52 +03005444
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005445 for_each_old_intel_plane_in_state(state, plane, old_plane_state, i) {
5446 if (crtc->pipe != plane->pipe ||
5447 !(update_mask & BIT(plane->id)))
5448 continue;
Ville Syrjäläf98551a2014-05-22 17:48:06 +03005449
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005450 plane->disable_plane(plane, new_crtc_state);
5451
5452 if (old_plane_state->base.visible)
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005453 fb_bits |= plane->frontbuffer_bit;
Maarten Lankhorstf59e9702018-09-20 12:27:07 +02005454 }
5455
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02005456 intel_frontbuffer_flip(dev_priv, fb_bits);
Ville Syrjäläa5c4d7b2014-03-07 18:32:13 +02005457}
5458
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005459static void intel_encoders_pre_pll_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005460 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005461 struct drm_atomic_state *old_state)
5462{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005463 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005464 struct drm_connector *conn;
5465 int i;
5466
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005467 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005468 struct intel_encoder *encoder =
5469 to_intel_encoder(conn_state->best_encoder);
5470
5471 if (conn_state->crtc != crtc)
5472 continue;
5473
5474 if (encoder->pre_pll_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005475 encoder->pre_pll_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005476 }
5477}
5478
5479static void intel_encoders_pre_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005480 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005481 struct drm_atomic_state *old_state)
5482{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005483 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005484 struct drm_connector *conn;
5485 int i;
5486
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005487 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005488 struct intel_encoder *encoder =
5489 to_intel_encoder(conn_state->best_encoder);
5490
5491 if (conn_state->crtc != crtc)
5492 continue;
5493
5494 if (encoder->pre_enable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005495 encoder->pre_enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005496 }
5497}
5498
5499static void intel_encoders_enable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005500 struct intel_crtc_state *crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005501 struct drm_atomic_state *old_state)
5502{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005503 struct drm_connector_state *conn_state;
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005504 struct drm_connector *conn;
5505 int i;
5506
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005507 for_each_new_connector_in_state(old_state, conn, conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005508 struct intel_encoder *encoder =
5509 to_intel_encoder(conn_state->best_encoder);
5510
5511 if (conn_state->crtc != crtc)
5512 continue;
5513
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005514 if (encoder->enable)
5515 encoder->enable(encoder, crtc_state, conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005516 intel_opregion_notify_encoder(encoder, true);
5517 }
5518}
5519
5520static void intel_encoders_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005521 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005522 struct drm_atomic_state *old_state)
5523{
5524 struct drm_connector_state *old_conn_state;
5525 struct drm_connector *conn;
5526 int i;
5527
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005528 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005529 struct intel_encoder *encoder =
5530 to_intel_encoder(old_conn_state->best_encoder);
5531
5532 if (old_conn_state->crtc != crtc)
5533 continue;
5534
5535 intel_opregion_notify_encoder(encoder, false);
Jani Nikulac84c6fe2018-10-16 15:41:34 +03005536 if (encoder->disable)
5537 encoder->disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005538 }
5539}
5540
5541static void intel_encoders_post_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005542 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005543 struct drm_atomic_state *old_state)
5544{
5545 struct drm_connector_state *old_conn_state;
5546 struct drm_connector *conn;
5547 int i;
5548
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005549 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005550 struct intel_encoder *encoder =
5551 to_intel_encoder(old_conn_state->best_encoder);
5552
5553 if (old_conn_state->crtc != crtc)
5554 continue;
5555
5556 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005557 encoder->post_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005558 }
5559}
5560
5561static void intel_encoders_post_pll_disable(struct drm_crtc *crtc,
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005562 struct intel_crtc_state *old_crtc_state,
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005563 struct drm_atomic_state *old_state)
5564{
5565 struct drm_connector_state *old_conn_state;
5566 struct drm_connector *conn;
5567 int i;
5568
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +01005569 for_each_old_connector_in_state(old_state, conn, old_conn_state, i) {
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005570 struct intel_encoder *encoder =
5571 to_intel_encoder(old_conn_state->best_encoder);
5572
5573 if (old_conn_state->crtc != crtc)
5574 continue;
5575
5576 if (encoder->post_pll_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005577 encoder->post_pll_disable(encoder, old_crtc_state, old_conn_state);
Maarten Lankhorstfb1c98b2016-08-09 17:04:03 +02005578 }
5579}
5580
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005581static void ironlake_crtc_enable(struct intel_crtc_state *pipe_config,
5582 struct drm_atomic_state *old_state)
Jesse Barnesf67a5592011-01-05 10:31:48 -08005583{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005584 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnesf67a5592011-01-05 10:31:48 -08005585 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005586 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005587 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5588 int pipe = intel_crtc->pipe;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005589 struct intel_atomic_state *old_intel_state =
5590 to_intel_atomic_state(old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005591
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005592 if (WARN_ON(intel_crtc->active))
Jesse Barnesf67a5592011-01-05 10:31:48 -08005593 return;
5594
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005595 /*
5596 * Sometimes spurious CPU pipe underruns happen during FDI
5597 * training, at least with VGA+HDMI cloning. Suppress them.
5598 *
5599 * On ILK we get an occasional spurious CPU pipe underruns
5600 * between eDP port A enable and vdd enable. Also PCH port
5601 * enable seems to result in the occasional CPU pipe underrun.
5602 *
5603 * Spurious PCH underruns also occur during PCH enabling.
5604 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005605 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5606 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005607
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005608 if (pipe_config->has_pch_encoder)
5609 intel_prepare_shared_dpll(pipe_config);
Daniel Vetterb14b1052014-04-24 23:55:13 +02005610
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005611 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005612 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005613
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005614 intel_set_pipe_timings(pipe_config);
5615 intel_set_pipe_src_size(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005616
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005617 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005618 intel_cpu_transcoder_set_m_n(pipe_config,
5619 &pipe_config->fdi_m_n, NULL);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005620 }
5621
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005622 ironlake_set_pipeconf(pipe_config);
Daniel Vetter29407aa2014-04-24 23:55:08 +02005623
Jesse Barnesf67a5592011-01-05 10:31:48 -08005624 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005625
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005626 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005627
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005628 if (pipe_config->has_pch_encoder) {
Daniel Vetterfff367c2012-10-27 15:50:28 +02005629 /* Note: FDI PLL enabling _must_ be done before we enable the
5630 * cpu pipes, hence this is separate from all the other fdi/pch
5631 * enabling. */
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02005632 ironlake_fdi_pll_enable(pipe_config);
Daniel Vetter46b6f812012-09-06 22:08:33 +02005633 } else {
5634 assert_fdi_tx_disabled(dev_priv, pipe);
5635 assert_fdi_rx_disabled(dev_priv, pipe);
5636 }
Jesse Barnesf67a5592011-01-05 10:31:48 -08005637
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005638 ironlake_pfit_enable(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005639
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005640 /*
5641 * On ILK+ LUT must be loaded before the pipe is running but with
5642 * clocks enabled
5643 */
Matt Roper302da0c2018-12-10 13:54:15 -08005644 intel_color_load_luts(pipe_config);
Jesse Barnes9c54c0d2011-06-15 23:32:33 +02005645
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005646 if (dev_priv->display.initial_watermarks != NULL)
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005647 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02005648 intel_enable_pipe(pipe_config);
Jesse Barnesf67a5592011-01-05 10:31:48 -08005649
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005650 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005651 ironlake_pch_enable(old_intel_state, pipe_config);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005652
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005653 assert_vblank_disabled(crtc);
5654 drm_crtc_vblank_on(crtc);
5655
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005656 intel_encoders_enable(crtc, pipe_config, old_state);
Daniel Vetter61b77dd2012-07-02 00:16:19 +02005657
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005658 if (HAS_PCH_CPT(dev_priv))
Daniel Vettera1520312013-05-03 11:49:50 +02005659 cpt_verify_modeset(dev, intel_crtc->pipe);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005660
Ville Syrjäläea80a662018-05-24 22:04:05 +03005661 /*
5662 * Must wait for vblank to avoid spurious PCH FIFO underruns.
5663 * And a second vblank wait is needed at least on ILK with
5664 * some interlaced HDMI modes. Let's do the double wait always
5665 * in case there are more corner cases we don't know about.
5666 */
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005667 if (pipe_config->has_pch_encoder) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005668 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjäläea80a662018-05-24 22:04:05 +03005669 intel_wait_for_vblank(dev_priv, pipe);
5670 }
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005671 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005672 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005673}
5674
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005675/* IPS only exists on ULT machines and is tied to pipe A. */
5676static bool hsw_crtc_supports_ips(struct intel_crtc *crtc)
5677{
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01005678 return HAS_IPS(to_i915(crtc->base.dev)) && crtc->pipe == PIPE_A;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005679}
5680
Imre Deaked69cd42017-10-02 10:55:57 +03005681static void glk_pipe_scaler_clock_gating_wa(struct drm_i915_private *dev_priv,
5682 enum pipe pipe, bool apply)
5683{
5684 u32 val = I915_READ(CLKGATE_DIS_PSL(pipe));
5685 u32 mask = DPF_GATING_DIS | DPF_RAM_GATING_DIS | DPFR_GATING_DIS;
5686
5687 if (apply)
5688 val |= mask;
5689 else
5690 val &= ~mask;
5691
5692 I915_WRITE(CLKGATE_DIS_PSL(pipe), val);
5693}
5694
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005695static void icl_pipe_mbus_enable(struct intel_crtc *crtc)
5696{
5697 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5698 enum pipe pipe = crtc->pipe;
5699 uint32_t val;
5700
Rodrigo Vivi443d5e32018-10-04 08:18:14 -07005701 val = MBUS_DBOX_A_CREDIT(2);
5702 val |= MBUS_DBOX_BW_CREDIT(1);
5703 val |= MBUS_DBOX_B_CREDIT(8);
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005704
5705 I915_WRITE(PIPE_MBUS_DBOX_CTL(pipe), val);
5706}
5707
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005708static void haswell_crtc_enable(struct intel_crtc_state *pipe_config,
5709 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005710{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005711 struct drm_crtc *crtc = pipe_config->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005712 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005713 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005714 int pipe = intel_crtc->pipe, hsw_workaround_pipe;
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005715 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +01005716 struct intel_atomic_state *old_intel_state =
5717 to_intel_atomic_state(old_state);
Imre Deaked69cd42017-10-02 10:55:57 +03005718 bool psl_clkgate_wa;
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305719 u32 pipe_chicken;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005720
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02005721 if (WARN_ON(intel_crtc->active))
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005722 return;
5723
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005724 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Imre Deak95a7a2a2016-06-13 16:44:35 +03005725
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02005726 if (pipe_config->shared_dpll)
5727 intel_enable_shared_dpll(pipe_config);
Daniel Vetterdf8ad702014-06-25 22:02:03 +03005728
Paulo Zanonic8af5272018-05-02 14:58:51 -07005729 intel_encoders_pre_enable(crtc, pipe_config, old_state);
5730
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005731 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005732 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter229fca92014-04-24 23:55:09 +02005733
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005734 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005735 intel_set_pipe_timings(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005736
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02005737 intel_set_pipe_src_size(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005738
Jani Nikula4d1de972016-03-18 17:05:42 +02005739 if (cpu_transcoder != TRANSCODER_EDP &&
5740 !transcoder_is_dsi(cpu_transcoder)) {
5741 I915_WRITE(PIPE_MULT(cpu_transcoder),
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005742 pipe_config->pixel_multiplier - 1);
Clint Taylorebb69c92014-09-30 10:30:22 -07005743 }
5744
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005745 if (pipe_config->has_pch_encoder) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02005746 intel_cpu_transcoder_set_m_n(pipe_config,
5747 &pipe_config->fdi_m_n, NULL);
Daniel Vetter229fca92014-04-24 23:55:09 +02005748 }
5749
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005750 if (!transcoder_is_dsi(cpu_transcoder))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005751 haswell_set_pipeconf(pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005752
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02005753 haswell_set_pipemisc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005754
Matt Roper302da0c2018-12-10 13:54:15 -08005755 intel_color_set_csc(pipe_config);
Daniel Vetter229fca92014-04-24 23:55:09 +02005756
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005757 intel_crtc->active = true;
Paulo Zanoni86642812013-04-12 17:57:57 -03005758
Imre Deaked69cd42017-10-02 10:55:57 +03005759 /* Display WA #1180: WaDisableScalarClockGating: glk, cnl */
5760 psl_clkgate_wa = (IS_GEMINILAKE(dev_priv) || IS_CANNONLAKE(dev_priv)) &&
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005761 pipe_config->pch_pfit.enabled;
Imre Deaked69cd42017-10-02 10:55:57 +03005762 if (psl_clkgate_wa)
5763 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, true);
5764
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005765 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005766 skylake_pfit_enable(pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005767 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005768 ironlake_pfit_enable(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005769
5770 /*
5771 * On ILK+ LUT must be loaded before the pipe is running but with
5772 * clocks enabled
5773 */
Matt Roper302da0c2018-12-10 13:54:15 -08005774 intel_color_load_luts(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005775
Vandita Kulkarnie16a3752018-06-21 20:43:56 +05305776 /*
5777 * Display WA #1153: enable hardware to bypass the alpha math
5778 * and rounding for per-pixel values 00 and 0xff
5779 */
5780 if (INTEL_GEN(dev_priv) >= 11) {
5781 pipe_chicken = I915_READ(PIPE_CHICKEN(pipe));
5782 if (!(pipe_chicken & PER_PIXEL_ALPHA_BYPASS_EN))
5783 I915_WRITE_FW(PIPE_CHICKEN(pipe),
5784 pipe_chicken | PER_PIXEL_ALPHA_BYPASS_EN);
5785 }
5786
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005787 intel_ddi_set_pipe_settings(pipe_config);
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005788 if (!transcoder_is_dsi(cpu_transcoder))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005789 intel_ddi_enable_transcoder_func(pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005790
Imre Deak1d5bf5d2016-02-29 22:10:33 +02005791 if (dev_priv->display.initial_watermarks != NULL)
Ville Syrjälä3125d392016-11-28 19:37:03 +02005792 dev_priv->display.initial_watermarks(old_intel_state, pipe_config);
Jani Nikula4d1de972016-03-18 17:05:42 +02005793
Mahesh Kumarc3cc39c2018-02-05 15:21:31 -02005794 if (INTEL_GEN(dev_priv) >= 11)
5795 icl_pipe_mbus_enable(intel_crtc);
5796
Jani Nikula4d1de972016-03-18 17:05:42 +02005797 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005798 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005799 intel_enable_pipe(pipe_config);
Paulo Zanoni42db64e2013-05-31 16:33:22 -03005800
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005801 if (pipe_config->has_pch_encoder)
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03005802 lpt_pch_enable(old_intel_state, pipe_config);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005803
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005804 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DP_MST))
Ander Conselvan de Oliveira3dc38ee2017-03-02 14:58:56 +02005805 intel_ddi_set_vc_payload_alloc(pipe_config, true);
Dave Airlie0e32b392014-05-02 14:02:48 +10005806
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005807 assert_vblank_disabled(crtc);
5808 drm_crtc_vblank_on(crtc);
5809
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005810 intel_encoders_enable(crtc, pipe_config, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005811
Imre Deaked69cd42017-10-02 10:55:57 +03005812 if (psl_clkgate_wa) {
5813 intel_wait_for_vblank(dev_priv, pipe);
5814 glk_pipe_scaler_clock_gating_wa(dev_priv, pipe, false);
5815 }
5816
Paulo Zanonie4916942013-09-20 16:21:19 -03005817 /* If we change the relative order between pipe/planes enabling, we need
5818 * to change the workaround. */
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005819 hsw_workaround_pipe = pipe_config->hsw_workaround_pipe;
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01005820 if (IS_HASWELL(dev_priv) && hsw_workaround_pipe != INVALID_PIPE) {
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02005821 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
5822 intel_wait_for_vblank(dev_priv, hsw_workaround_pipe);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +02005823 }
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005824}
5825
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005826static void ironlake_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005827{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005828 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
5829 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
5830 enum pipe pipe = crtc->pipe;
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005831
5832 /* To avoid upsetting the power well on haswell only disable the pfit if
5833 * it's in use. The hw state code will make sure we get this right. */
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005834 if (old_crtc_state->pch_pfit.enabled) {
Daniel Vetter3f8dce32013-05-08 10:36:30 +02005835 I915_WRITE(PF_CTL(pipe), 0);
5836 I915_WRITE(PF_WIN_POS(pipe), 0);
5837 I915_WRITE(PF_WIN_SZ(pipe), 0);
5838 }
5839}
5840
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005841static void ironlake_crtc_disable(struct intel_crtc_state *old_crtc_state,
5842 struct drm_atomic_state *old_state)
Jesse Barnes6be4a602010-09-10 10:26:01 -07005843{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005844 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005845 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01005846 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005847 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
5848 int pipe = intel_crtc->pipe;
Jesse Barnes6be4a602010-09-10 10:26:01 -07005849
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005850 /*
5851 * Sometimes spurious CPU pipe underruns happen when the
5852 * pipe is already disabled, but FDI RX/TX is still enabled.
5853 * Happens at least with VGA+HDMI cloning. Suppress them.
5854 */
Ville Syrjälä2b5b6312018-05-24 22:04:06 +03005855 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
5856 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjälä37ca8d42015-10-30 19:20:27 +02005857
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005858 intel_encoders_disable(crtc, old_crtc_state, old_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +02005859
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005860 drm_crtc_vblank_off(crtc);
5861 assert_vblank_disabled(crtc);
5862
Ville Syrjälä4972f702017-11-29 17:37:32 +02005863 intel_disable_pipe(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005864
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005865 ironlake_pfit_disable(old_crtc_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005866
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005867 if (old_crtc_state->has_pch_encoder)
Ville Syrjälä5a74f702015-05-05 17:17:38 +03005868 ironlake_fdi_disable(crtc);
5869
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005870 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005871
Maarten Lankhorst6f405632018-10-04 11:46:04 +02005872 if (old_crtc_state->has_pch_encoder) {
Daniel Vetterd925c592013-06-05 13:34:04 +02005873 ironlake_disable_pch_transcoder(dev_priv, pipe);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005874
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01005875 if (HAS_PCH_CPT(dev_priv)) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02005876 i915_reg_t reg;
5877 u32 temp;
5878
Daniel Vetterd925c592013-06-05 13:34:04 +02005879 /* disable TRANS_DP_CTL */
5880 reg = TRANS_DP_CTL(pipe);
5881 temp = I915_READ(reg);
5882 temp &= ~(TRANS_DP_OUTPUT_ENABLE |
5883 TRANS_DP_PORT_SEL_MASK);
5884 temp |= TRANS_DP_PORT_SEL_NONE;
5885 I915_WRITE(reg, temp);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005886
Daniel Vetterd925c592013-06-05 13:34:04 +02005887 /* disable DPLL_SEL */
5888 temp = I915_READ(PCH_DPLL_SEL);
Daniel Vetter11887392013-06-05 13:34:09 +02005889 temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe));
Daniel Vetterd925c592013-06-05 13:34:04 +02005890 I915_WRITE(PCH_DPLL_SEL, temp);
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08005891 }
Daniel Vetterd925c592013-06-05 13:34:04 +02005892
Daniel Vetterd925c592013-06-05 13:34:04 +02005893 ironlake_fdi_pll_disable(intel_crtc);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005894 }
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005895
Ville Syrjäläb2c05932016-04-01 21:53:17 +03005896 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä81b088c2015-10-30 19:21:31 +02005897 intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true);
Jesse Barnes6be4a602010-09-10 10:26:01 -07005898}
5899
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005900static void haswell_crtc_disable(struct intel_crtc_state *old_crtc_state,
5901 struct drm_atomic_state *old_state)
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005902{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02005903 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005904 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005905 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Imre Deak24a28172018-06-13 20:07:06 +03005906 enum transcoder cpu_transcoder = old_crtc_state->cpu_transcoder;
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005907
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005908 intel_encoders_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005909
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01005910 drm_crtc_vblank_off(crtc);
5911 assert_vblank_disabled(crtc);
5912
Jani Nikula4d1de972016-03-18 17:05:42 +02005913 /* XXX: Do the pipe assertions at the right place for BXT DSI. */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005914 if (!transcoder_is_dsi(cpu_transcoder))
Ville Syrjälä4972f702017-11-29 17:37:32 +02005915 intel_disable_pipe(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005916
Imre Deak24a28172018-06-13 20:07:06 +03005917 if (intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DP_MST))
5918 intel_ddi_set_vc_payload_alloc(old_crtc_state, false);
Ville Syrjäläa4bf2142014-08-18 21:27:34 +03005919
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03005920 if (!transcoder_is_dsi(cpu_transcoder))
Clint Taylor90c3e212018-07-10 13:02:05 -07005921 intel_ddi_disable_transcoder_func(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005922
Manasi Navarea6006222018-11-28 12:26:23 -08005923 intel_dsc_disable(old_crtc_state);
5924
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00005925 if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +02005926 skylake_scaler_disable(intel_crtc);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08005927 else
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005928 ironlake_pfit_disable(old_crtc_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005929
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02005930 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Paulo Zanonic27e9172018-04-27 16:14:36 -07005931
Imre Deakbdaa29b2018-11-01 16:04:24 +02005932 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Paulo Zanoni4f771f12012-10-23 18:29:51 -02005933}
5934
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005935static void i9xx_pfit_enable(const struct intel_crtc_state *crtc_state)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005936{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005937 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
5938 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005939
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005940 if (!crtc_state->gmch_pfit.control)
Jesse Barnes2dd24552013-04-25 12:55:01 -07005941 return;
5942
Daniel Vetterc0b03412013-05-28 12:05:54 +02005943 /*
5944 * The panel fitter should only be adjusted whilst the pipe is disabled,
5945 * according to register description and PRM.
5946 */
Jesse Barnes2dd24552013-04-25 12:55:01 -07005947 WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE);
5948 assert_pipe_disabled(dev_priv, crtc->pipe);
5949
Maarten Lankhorstb2562712018-10-04 11:45:53 +02005950 I915_WRITE(PFIT_PGM_RATIOS, crtc_state->gmch_pfit.pgm_ratios);
5951 I915_WRITE(PFIT_CONTROL, crtc_state->gmch_pfit.control);
Daniel Vetter5a80c452013-04-25 22:52:18 +02005952
5953 /* Border color in case we don't scale up to the full screen. Black by
5954 * default, change to something else for debugging. */
5955 I915_WRITE(BCLRPAT(crtc->pipe), 0);
Jesse Barnes2dd24552013-04-25 12:55:01 -07005956}
5957
Mahesh Kumar176597a2018-10-04 14:20:43 +05305958bool intel_port_is_combophy(struct drm_i915_private *dev_priv, enum port port)
5959{
5960 if (port == PORT_NONE)
5961 return false;
5962
5963 if (IS_ICELAKE(dev_priv))
5964 return port <= PORT_B;
5965
5966 return false;
5967}
5968
Paulo Zanoniac213c12018-05-21 17:25:37 -07005969bool intel_port_is_tc(struct drm_i915_private *dev_priv, enum port port)
5970{
5971 if (IS_ICELAKE(dev_priv))
5972 return port >= PORT_C && port <= PORT_F;
5973
5974 return false;
5975}
5976
5977enum tc_port intel_port_to_tc(struct drm_i915_private *dev_priv, enum port port)
5978{
5979 if (!intel_port_is_tc(dev_priv, port))
5980 return PORT_TC_NONE;
5981
5982 return port - PORT_C;
5983}
5984
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02005985enum intel_display_power_domain intel_port_to_power_domain(enum port port)
Dave Airlied05410f2014-06-05 13:22:59 +10005986{
5987 switch (port) {
5988 case PORT_A:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005989 return POWER_DOMAIN_PORT_DDI_A_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005990 case PORT_B:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005991 return POWER_DOMAIN_PORT_DDI_B_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005992 case PORT_C:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005993 return POWER_DOMAIN_PORT_DDI_C_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10005994 case PORT_D:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005995 return POWER_DOMAIN_PORT_DDI_D_LANES;
Xiong Zhangd8e19f92015-08-13 18:00:12 +08005996 case PORT_E:
Patrik Jakobsson6331a702015-11-09 16:48:21 +01005997 return POWER_DOMAIN_PORT_DDI_E_LANES;
Rodrigo Vivi9787e832018-01-29 15:22:22 -08005998 case PORT_F:
5999 return POWER_DOMAIN_PORT_DDI_F_LANES;
Dave Airlied05410f2014-06-05 13:22:59 +10006000 default:
Imre Deakb9fec162015-11-18 15:57:25 +02006001 MISSING_CASE(port);
Dave Airlied05410f2014-06-05 13:22:59 +10006002 return POWER_DOMAIN_PORT_OTHER;
6003 }
6004}
6005
Imre Deak337837a2018-11-01 16:04:23 +02006006enum intel_display_power_domain
6007intel_aux_power_domain(struct intel_digital_port *dig_port)
6008{
6009 switch (dig_port->aux_ch) {
6010 case AUX_CH_A:
6011 return POWER_DOMAIN_AUX_A;
6012 case AUX_CH_B:
6013 return POWER_DOMAIN_AUX_B;
6014 case AUX_CH_C:
6015 return POWER_DOMAIN_AUX_C;
6016 case AUX_CH_D:
6017 return POWER_DOMAIN_AUX_D;
6018 case AUX_CH_E:
6019 return POWER_DOMAIN_AUX_E;
6020 case AUX_CH_F:
6021 return POWER_DOMAIN_AUX_F;
6022 default:
6023 MISSING_CASE(dig_port->aux_ch);
6024 return POWER_DOMAIN_AUX_A;
6025 }
6026}
6027
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006028static u64 get_crtc_power_domains(struct drm_crtc *crtc,
6029 struct intel_crtc_state *crtc_state)
Imre Deak319be8a2014-03-04 19:22:57 +02006030{
6031 struct drm_device *dev = crtc->dev;
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006032 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006033 struct drm_encoder *encoder;
Imre Deak319be8a2014-03-04 19:22:57 +02006034 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6035 enum pipe pipe = intel_crtc->pipe;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006036 u64 mask;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006037 enum transcoder transcoder = crtc_state->cpu_transcoder;
Imre Deak77d22dc2014-03-05 16:20:52 +02006038
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006039 if (!crtc_state->base.active)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006040 return 0;
6041
Imre Deak17bd6e62018-01-09 14:20:40 +02006042 mask = BIT_ULL(POWER_DOMAIN_PIPE(pipe));
6043 mask |= BIT_ULL(POWER_DOMAIN_TRANSCODER(transcoder));
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006044 if (crtc_state->pch_pfit.enabled ||
6045 crtc_state->pch_pfit.force_thru)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006046 mask |= BIT_ULL(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe));
Imre Deak77d22dc2014-03-05 16:20:52 +02006047
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006048 drm_for_each_encoder_mask(encoder, dev, crtc_state->base.encoder_mask) {
6049 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
6050
Ander Conselvan de Oliveira79f255a2017-02-22 08:34:27 +02006051 mask |= BIT_ULL(intel_encoder->power_domain);
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006052 }
Imre Deak319be8a2014-03-04 19:22:57 +02006053
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006054 if (HAS_DDI(dev_priv) && crtc_state->has_audio)
Imre Deak17bd6e62018-01-09 14:20:40 +02006055 mask |= BIT_ULL(POWER_DOMAIN_AUDIO);
Maarten Lankhorst37255d82016-12-15 15:29:43 +01006056
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006057 if (crtc_state->shared_dpll)
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006058 mask |= BIT_ULL(POWER_DOMAIN_PLLS);
Maarten Lankhorst15e7ec22016-03-14 09:27:54 +01006059
Imre Deak77d22dc2014-03-05 16:20:52 +02006060 return mask;
6061}
6062
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006063static u64
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006064modeset_get_crtc_power_domains(struct drm_crtc *crtc,
6065 struct intel_crtc_state *crtc_state)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006066{
Chris Wilsonfac5e232016-07-04 11:34:36 +01006067 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006068 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6069 enum intel_display_power_domain domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006070 u64 domains, new_domains, old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006071
6072 old_domains = intel_crtc->enabled_power_domains;
Maarten Lankhorst74bff5f2016-02-10 13:49:36 +01006073 intel_crtc->enabled_power_domains = new_domains =
6074 get_crtc_power_domains(crtc, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006075
Daniel Vetter5a21b662016-05-24 17:13:53 +02006076 domains = new_domains & ~old_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006077
6078 for_each_power_domain(domain, domains)
6079 intel_display_power_get(dev_priv, domain);
6080
Daniel Vetter5a21b662016-05-24 17:13:53 +02006081 return old_domains & ~new_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006082}
6083
6084static void modeset_put_power_domains(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02006085 u64 domains)
Maarten Lankhorst292b9902015-07-13 16:30:27 +02006086{
6087 enum intel_display_power_domain domain;
6088
6089 for_each_power_domain(domain, domains)
6090 intel_display_power_put(dev_priv, domain);
6091}
6092
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006093static void valleyview_crtc_enable(struct intel_crtc_state *pipe_config,
6094 struct drm_atomic_state *old_state)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006095{
Ville Syrjäläff32c542017-03-02 19:14:57 +02006096 struct intel_atomic_state *old_intel_state =
6097 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006098 struct drm_crtc *crtc = pipe_config->base.crtc;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006099 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006100 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006101 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006102 int pipe = intel_crtc->pipe;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006103
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006104 if (WARN_ON(intel_crtc->active))
Jesse Barnes89b667f2013-04-18 14:51:36 -07006105 return;
6106
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006107 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006108 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006109
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006110 intel_set_pipe_timings(pipe_config);
6111 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006112
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006113 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjäläc14b0482014-10-16 20:52:34 +03006114 I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY);
6115 I915_WRITE(CHV_CANVAS(pipe), 0);
6116 }
6117
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006118 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006119
Matt Roper302da0c2018-12-10 13:54:15 -08006120 intel_color_set_csc(pipe_config);
P Raviraj Sitaramc59d2da2018-09-10 19:57:14 +05306121
Jesse Barnes89b667f2013-04-18 14:51:36 -07006122 intel_crtc->active = true;
Jesse Barnes89b667f2013-04-18 14:51:36 -07006123
Daniel Vettera72e4c92014-09-30 10:56:47 +02006124 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006125
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006126 intel_encoders_pre_pll_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006127
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006128 if (IS_CHERRYVIEW(dev_priv)) {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006129 chv_prepare_pll(intel_crtc, pipe_config);
6130 chv_enable_pll(intel_crtc, pipe_config);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006131 } else {
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006132 vlv_prepare_pll(intel_crtc, pipe_config);
6133 vlv_enable_pll(intel_crtc, pipe_config);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03006134 }
Jesse Barnes89b667f2013-04-18 14:51:36 -07006135
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006136 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006137
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006138 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006139
Matt Roper302da0c2018-12-10 13:54:15 -08006140 intel_color_load_luts(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006141
Ville Syrjäläff32c542017-03-02 19:14:57 +02006142 dev_priv->display.initial_watermarks(old_intel_state,
6143 pipe_config);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006144 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006145
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006146 assert_vblank_disabled(crtc);
6147 drm_crtc_vblank_on(crtc);
6148
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006149 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006150}
6151
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006152static void i9xx_set_pll_dividers(const struct intel_crtc_state *crtc_state)
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006153{
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006154 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6155 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006156
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006157 I915_WRITE(FP0(crtc->pipe), crtc_state->dpll_hw_state.fp0);
6158 I915_WRITE(FP1(crtc->pipe), crtc_state->dpll_hw_state.fp1);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006159}
6160
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006161static void i9xx_crtc_enable(struct intel_crtc_state *pipe_config,
6162 struct drm_atomic_state *old_state)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006163{
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006164 struct intel_atomic_state *old_intel_state =
6165 to_intel_atomic_state(old_state);
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006166 struct drm_crtc *crtc = pipe_config->base.crtc;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006167 struct drm_device *dev = crtc->dev;
Daniel Vettera72e4c92014-09-30 10:56:47 +02006168 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes79e53942008-11-07 14:24:08 -08006169 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006170 enum pipe pipe = intel_crtc->pipe;
Jesse Barnes79e53942008-11-07 14:24:08 -08006171
Maarten Lankhorst53d9f4e2015-06-01 12:49:52 +02006172 if (WARN_ON(intel_crtc->active))
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006173 return;
6174
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006175 i9xx_set_pll_dividers(pipe_config);
Daniel Vetterf13c2ef2014-04-24 23:55:10 +02006176
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006177 if (intel_crtc_has_dp_encoder(pipe_config))
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006178 intel_dp_set_m_n(pipe_config, M1_N1);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006179
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02006180 intel_set_pipe_timings(pipe_config);
6181 intel_set_pipe_src_size(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006182
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02006183 i9xx_set_pipeconf(pipe_config);
Daniel Vetter5b18e572014-04-24 23:55:06 +02006184
Chris Wilsonf7abfe82010-09-13 14:19:16 +01006185 intel_crtc->active = true;
Chris Wilson6b383a72010-09-13 13:54:26 +01006186
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006187 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006188 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true);
Ville Syrjälä4a3436e2014-05-16 19:40:25 +03006189
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006190 intel_encoders_pre_enable(crtc, pipe_config, old_state);
Mika Kuoppala9d6d9f12013-02-08 16:35:38 +02006191
Ville Syrjälä939994d2017-09-13 17:08:56 +03006192 i9xx_enable_pll(intel_crtc, pipe_config);
Daniel Vetterf6736a12013-06-05 13:34:30 +02006193
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006194 i9xx_pfit_enable(pipe_config);
Jesse Barnes2dd24552013-04-25 12:55:01 -07006195
Matt Roper302da0c2018-12-10 13:54:15 -08006196 intel_color_load_luts(pipe_config);
Ville Syrjälä63cbb072013-06-04 13:48:59 +03006197
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006198 if (dev_priv->display.initial_watermarks != NULL)
6199 dev_priv->display.initial_watermarks(old_intel_state,
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006200 pipe_config);
Ville Syrjälä04548cb2017-04-21 21:14:29 +03006201 else
6202 intel_update_watermarks(intel_crtc);
Ville Syrjälä4972f702017-11-29 17:37:32 +02006203 intel_enable_pipe(pipe_config);
Daniel Vetterbe6a6f82014-04-15 18:41:22 +02006204
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006205 assert_vblank_disabled(crtc);
6206 drm_crtc_vblank_on(crtc);
6207
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006208 intel_encoders_enable(crtc, pipe_config, old_state);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006209}
6210
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006211static void i9xx_pfit_disable(const struct intel_crtc_state *old_crtc_state)
Daniel Vetter87476d62013-04-11 16:29:06 +02006212{
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006213 struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
6214 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter328d8e82013-05-08 10:36:31 +02006215
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006216 if (!old_crtc_state->gmch_pfit.control)
Daniel Vetter328d8e82013-05-08 10:36:31 +02006217 return;
Daniel Vetter87476d62013-04-11 16:29:06 +02006218
6219 assert_pipe_disabled(dev_priv, crtc->pipe);
6220
Chris Wilson43031782018-09-13 14:16:26 +01006221 DRM_DEBUG_KMS("disabling pfit, current: 0x%08x\n",
6222 I915_READ(PFIT_CONTROL));
Daniel Vetter328d8e82013-05-08 10:36:31 +02006223 I915_WRITE(PFIT_CONTROL, 0);
Daniel Vetter87476d62013-04-11 16:29:06 +02006224}
6225
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006226static void i9xx_crtc_disable(struct intel_crtc_state *old_crtc_state,
6227 struct drm_atomic_state *old_state)
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006228{
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006229 struct drm_crtc *crtc = old_crtc_state->base.crtc;
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006230 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006231 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006232 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
6233 int pipe = intel_crtc->pipe;
Daniel Vetteref9c3ae2012-06-29 22:40:09 +02006234
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006235 /*
6236 * On gen2 planes are double buffered but the pipe isn't, so we must
6237 * wait for planes to fully turn off before disabling the pipe.
6238 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006239 if (IS_GEN(dev_priv, 2))
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +02006240 intel_wait_for_vblank(dev_priv, pipe);
Ville Syrjälä6304cd92014-04-25 13:30:12 +03006241
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006242 intel_encoders_disable(crtc, old_crtc_state, old_state);
Ville Syrjälä4b3a9522014-08-14 22:04:37 +03006243
Daniel Vetterf9b61ff2015-01-07 13:54:39 +01006244 drm_crtc_vblank_off(crtc);
6245 assert_vblank_disabled(crtc);
6246
Ville Syrjälä4972f702017-11-29 17:37:32 +02006247 intel_disable_pipe(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006248
Maarten Lankhorstb2562712018-10-04 11:45:53 +02006249 i9xx_pfit_disable(old_crtc_state);
Mika Kuoppala24a1f162013-02-08 16:35:37 +02006250
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006251 intel_encoders_post_disable(crtc, old_crtc_state, old_state);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006252
Maarten Lankhorst6f405632018-10-04 11:46:04 +02006253 if (!intel_crtc_has_type(old_crtc_state, INTEL_OUTPUT_DSI)) {
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01006254 if (IS_CHERRYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006255 chv_disable_pll(dev_priv, pipe);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01006256 else if (IS_VALLEYVIEW(dev_priv))
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006257 vlv_disable_pll(dev_priv, pipe);
6258 else
Maarten Lankhorstb2354c72018-10-04 11:45:57 +02006259 i9xx_disable_pll(old_crtc_state);
Chon Ming Lee076ed3b2014-04-09 13:28:17 +03006260 }
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006261
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +02006262 intel_encoders_post_pll_disable(crtc, old_crtc_state, old_state);
Ville Syrjäläd6db9952015-07-08 23:45:49 +03006263
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006264 if (!IS_GEN(dev_priv, 2))
Daniel Vettera72e4c92014-09-30 10:56:47 +02006265 intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false);
Ville Syrjäläff32c542017-03-02 19:14:57 +02006266
6267 if (!dev_priv->display.initial_watermarks)
6268 intel_update_watermarks(intel_crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +03006269
6270 /* clock the pipe down to 640x480@60 to potentially save power */
6271 if (IS_I830(dev_priv))
6272 i830_enable_pipe(dev_priv, pipe);
Jesse Barnes0b8765c62010-09-10 10:31:34 -07006273}
6274
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006275static void intel_crtc_disable_noatomic(struct drm_crtc *crtc,
6276 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnesee7b9f92012-04-20 17:11:53 +01006277{
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006278 struct intel_encoder *encoder;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006279 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006280 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006281 enum intel_display_power_domain domain;
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006282 struct intel_plane *plane;
Ander Conselvan de Oliveirad2d15012017-02-13 16:57:33 +02006283 u64 domains;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006284 struct drm_atomic_state *state;
6285 struct intel_crtc_state *crtc_state;
6286 int ret;
Daniel Vetter976f8a22012-07-08 22:34:21 +02006287
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006288 if (!intel_crtc->active)
6289 return;
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006290
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006291 for_each_intel_plane_on_crtc(&dev_priv->drm, intel_crtc, plane) {
6292 const struct intel_plane_state *plane_state =
6293 to_intel_plane_state(plane->base.state);
Maarten Lankhorst54a419612015-11-23 10:25:28 +01006294
Ville Syrjäläb1e01592017-11-17 21:19:09 +02006295 if (plane_state->base.visible)
6296 intel_plane_disable_noatomic(intel_crtc, plane);
Maarten Lankhorsta5392052015-06-15 12:33:52 +02006297 }
6298
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006299 state = drm_atomic_state_alloc(crtc->dev);
Ander Conselvan de Oliveira31bb2ef2017-01-20 16:28:45 +02006300 if (!state) {
6301 DRM_DEBUG_KMS("failed to disable [CRTC:%d:%s], out of memory",
6302 crtc->base.id, crtc->name);
6303 return;
6304 }
6305
Ville Syrjäläda1d0e22017-06-01 17:36:14 +03006306 state->acquire_ctx = ctx;
Maarten Lankhorst4a806552016-08-09 17:04:01 +02006307
6308 /* Everything's already locked, -EDEADLK can't happen. */
6309 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
6310 ret = drm_atomic_add_affected_connectors(state, crtc);
6311
6312 WARN_ON(IS_ERR(crtc_state) || ret);
6313
6314 dev_priv->display.crtc_disable(crtc_state, state);
6315
Chris Wilson08536952016-10-14 13:18:18 +01006316 drm_atomic_state_put(state);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006317
Ville Syrjälä78108b72016-05-27 20:59:19 +03006318 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state adjusted, was enabled, now disabled\n",
6319 crtc->base.id, crtc->name);
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006320
6321 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->state, NULL) < 0);
6322 crtc->state->active = false;
Matt Roper37d90782015-09-24 15:53:06 -07006323 intel_crtc->active = false;
Maarten Lankhorst842e0302016-03-02 15:48:01 +01006324 crtc->enabled = false;
6325 crtc->state->connector_mask = 0;
6326 crtc->state->encoder_mask = 0;
6327
6328 for_each_encoder_on_crtc(crtc->dev, crtc, encoder)
6329 encoder->base.crtc = NULL;
6330
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -02006331 intel_fbc_disable(intel_crtc);
Ville Syrjälä432081b2016-10-31 22:37:03 +02006332 intel_update_watermarks(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +02006333 intel_disable_shared_dpll(to_intel_crtc_state(crtc->state));
Daniel Vetter0e572fe2014-04-24 23:55:42 +02006334
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006335 domains = intel_crtc->enabled_power_domains;
6336 for_each_power_domain(domain, domains)
6337 intel_display_power_put(dev_priv, domain);
6338 intel_crtc->enabled_power_domains = 0;
Maarten Lankhorst565602d2015-12-10 12:33:57 +01006339
6340 dev_priv->active_crtcs &= ~(1 << intel_crtc->pipe);
Ville Syrjäläd305e062017-08-30 21:57:03 +03006341 dev_priv->min_cdclk[intel_crtc->pipe] = 0;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +03006342 dev_priv->min_voltage_level[intel_crtc->pipe] = 0;
Maarten Lankhorstb17d48e2015-06-12 11:15:39 +02006343}
6344
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006345/*
6346 * turn all crtc's off, but do not adjust state
6347 * This has to be paired with a call to intel_modeset_setup_hw_state.
6348 */
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006349int intel_display_suspend(struct drm_device *dev)
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006350{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006351 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006352 struct drm_atomic_state *state;
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006353 int ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006354
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006355 state = drm_atomic_helper_suspend(dev);
6356 ret = PTR_ERR_OR_ZERO(state);
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006357 if (ret)
6358 DRM_ERROR("Suspending crtc's failed with %i\n", ret);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +01006359 else
6360 dev_priv->modeset_restore_state = state;
Maarten Lankhorst70e0bd72015-07-13 16:30:29 +02006361 return ret;
Maarten Lankhorst6b72d482015-06-01 12:49:47 +02006362}
6363
Chris Wilsonea5b2132010-08-04 13:50:23 +01006364void intel_encoder_destroy(struct drm_encoder *encoder)
6365{
Chris Wilson4ef69c72010-09-09 15:14:28 +01006366 struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
Chris Wilsonea5b2132010-08-04 13:50:23 +01006367
Chris Wilsonea5b2132010-08-04 13:50:23 +01006368 drm_encoder_cleanup(encoder);
6369 kfree(intel_encoder);
6370}
6371
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006372/* Cross check the actual hw state with our own modeset state tracking (and it's
6373 * internal consistency). */
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006374static void intel_connector_verify_state(struct drm_crtc_state *crtc_state,
6375 struct drm_connector_state *conn_state)
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006376{
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006377 struct intel_connector *connector = to_intel_connector(conn_state->connector);
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006378
6379 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
6380 connector->base.base.id,
6381 connector->base.name);
6382
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006383 if (connector->get_hw_state(connector)) {
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006384 struct intel_encoder *encoder = connector->encoder;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006385
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006386 I915_STATE_WARN(!crtc_state,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006387 "connector enabled without attached crtc\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006388
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006389 if (!crtc_state)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006390 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006391
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006392 I915_STATE_WARN(!crtc_state->active,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006393 "connector is active, but attached crtc isn't\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006394
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006395 if (!encoder || encoder->type == INTEL_OUTPUT_DP_MST)
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006396 return;
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006397
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006398 I915_STATE_WARN(conn_state->best_encoder != &encoder->base,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006399 "atomic encoder doesn't match attached encoder\n");
Dave Airlie36cd7442014-05-02 13:44:18 +10006400
Maarten Lankhorste85376c2015-08-27 13:13:31 +02006401 I915_STATE_WARN(conn_state->crtc != encoder->base.crtc,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006402 "attached encoder crtc differs from connector crtc\n");
6403 } else {
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006404 I915_STATE_WARN(crtc_state && crtc_state->active,
Maarten Lankhorst4d688a22015-08-05 12:37:06 +02006405 "attached crtc is active, but connector isn't\n");
Maarten Lankhorst749d98b2017-05-11 10:28:43 +02006406 I915_STATE_WARN(!crtc_state && conn_state->best_encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +02006407 "best encoder set without crtc!\n");
Daniel Vetter0a91ca22012-07-02 21:54:27 +02006408 }
6409}
6410
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006411static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state)
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006412{
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006413 if (crtc_state->base.enable && crtc_state->has_pch_encoder)
6414 return crtc_state->fdi_lanes;
Ville Syrjäläd272ddf2015-03-11 18:52:31 +02006415
6416 return 0;
6417}
6418
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006419static int ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006420 struct intel_crtc_state *pipe_config)
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006421{
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006422 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006423 struct drm_atomic_state *state = pipe_config->base.state;
6424 struct intel_crtc *other_crtc;
6425 struct intel_crtc_state *other_crtc_state;
6426
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006427 DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n",
6428 pipe_name(pipe), pipe_config->fdi_lanes);
6429 if (pipe_config->fdi_lanes > 4) {
6430 DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n",
6431 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006432 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006433 }
6434
Tvrtko Ursulin86527442016-10-13 11:03:00 +01006435 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006436 if (pipe_config->fdi_lanes > 2) {
6437 DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n",
6438 pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006439 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006440 } else {
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006441 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006442 }
6443 }
6444
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +00006445 if (INTEL_INFO(dev_priv)->num_pipes == 2)
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006446 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006447
6448 /* Ivybridge 3 pipe is really complicated */
6449 switch (pipe) {
6450 case PIPE_A:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006451 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006452 case PIPE_B:
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006453 if (pipe_config->fdi_lanes <= 2)
6454 return 0;
6455
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006456 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_C);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006457 other_crtc_state =
6458 intel_atomic_get_crtc_state(state, other_crtc);
6459 if (IS_ERR(other_crtc_state))
6460 return PTR_ERR(other_crtc_state);
6461
6462 if (pipe_required_fdi_lanes(other_crtc_state) > 0) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006463 DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n",
6464 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006465 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006466 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006467 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006468 case PIPE_C:
Ville Syrjälä251cc672015-03-11 18:52:30 +02006469 if (pipe_config->fdi_lanes > 2) {
6470 DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n",
6471 pipe_name(pipe), pipe_config->fdi_lanes);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006472 return -EINVAL;
Ville Syrjälä251cc672015-03-11 18:52:30 +02006473 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006474
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02006475 other_crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_B);
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006476 other_crtc_state =
6477 intel_atomic_get_crtc_state(state, other_crtc);
6478 if (IS_ERR(other_crtc_state))
6479 return PTR_ERR(other_crtc_state);
6480
6481 if (pipe_required_fdi_lanes(other_crtc_state) > 2) {
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006482 DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006483 return -EINVAL;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006484 }
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006485 return 0;
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006486 default:
6487 BUG();
6488 }
6489}
6490
Daniel Vettere29c22c2013-02-21 00:00:16 +01006491#define RETRY 1
6492static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006493 struct intel_crtc_state *pipe_config)
Daniel Vetter877d48d2013-04-19 11:24:43 +02006494{
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006495 struct drm_device *dev = intel_crtc->base.dev;
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006496 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006497 int lane, link_bw, fdi_dotclock, ret;
6498 bool needs_recompute = false;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006499
Daniel Vettere29c22c2013-02-21 00:00:16 +01006500retry:
Daniel Vetter877d48d2013-04-19 11:24:43 +02006501 /* FDI is a binary signal running at ~2.7GHz, encoding
6502 * each output octet as 10 bits. The actual frequency
6503 * is stored as a divider into a 100MHz clock, and the
6504 * mode pixel clock is stored in units of 1KHz.
6505 * Hence the bw of each lane in terms of the mode signal
6506 * is:
6507 */
Ville Syrjälä21a727b2016-02-17 21:41:10 +02006508 link_bw = intel_fdi_link_freq(to_i915(dev), pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006509
Damien Lespiau241bfc32013-09-25 16:45:37 +01006510 fdi_dotclock = adjusted_mode->crtc_clock;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006511
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006512 lane = ironlake_get_lanes_required(fdi_dotclock, link_bw,
Daniel Vetter877d48d2013-04-19 11:24:43 +02006513 pipe_config->pipe_bpp);
6514
6515 pipe_config->fdi_lanes = lane;
6516
Daniel Vetter2bd89a02013-06-01 17:16:19 +02006517 intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006518 link_bw, &pipe_config->fdi_m_n, false);
Daniel Vetter1857e1d2013-04-29 19:34:16 +02006519
Ville Syrjäläe3b247d2016-02-17 21:41:09 +02006520 ret = ironlake_check_fdi_lanes(dev, intel_crtc->pipe, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +02006521 if (ret == -EDEADLK)
6522 return ret;
6523
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006524 if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) {
Daniel Vettere29c22c2013-02-21 00:00:16 +01006525 pipe_config->pipe_bpp -= 2*3;
6526 DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n",
6527 pipe_config->pipe_bpp);
6528 needs_recompute = true;
6529 pipe_config->bw_constrained = true;
6530
6531 goto retry;
6532 }
6533
6534 if (needs_recompute)
6535 return RETRY;
6536
Ander Conselvan de Oliveira6d293982015-03-30 08:33:12 +03006537 return ret;
Daniel Vetter877d48d2013-04-19 11:24:43 +02006538}
6539
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006540bool hsw_crtc_state_ips_capable(const struct intel_crtc_state *crtc_state)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006541{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006542 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6543 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6544
6545 /* IPS only exists on ULT machines and is tied to pipe A. */
6546 if (!hsw_crtc_supports_ips(crtc))
Ville Syrjälä6e644622017-08-17 17:55:09 +03006547 return false;
6548
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006549 if (!i915_modparams.enable_ips)
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006550 return false;
6551
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006552 if (crtc_state->pipe_bpp > 24)
6553 return false;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006554
6555 /*
Ville Syrjäläb432e5c2015-06-03 15:45:13 +03006556 * We compare against max which means we must take
6557 * the increased cdclk requirement into account when
6558 * calculating the new cdclk.
6559 *
6560 * Should measure whether using a lower cdclk w/o IPS
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006561 */
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006562 if (IS_BROADWELL(dev_priv) &&
6563 crtc_state->pixel_rate > dev_priv->max_cdclk_freq * 95 / 100)
6564 return false;
6565
6566 return true;
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006567}
6568
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006569static bool hsw_compute_ips_config(struct intel_crtc_state *crtc_state)
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006570{
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006571 struct drm_i915_private *dev_priv =
6572 to_i915(crtc_state->base.crtc->dev);
6573 struct intel_atomic_state *intel_state =
6574 to_intel_atomic_state(crtc_state->base.state);
Ville Syrjälä8cfb3402015-06-03 15:45:11 +03006575
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006576 if (!hsw_crtc_state_ips_capable(crtc_state))
6577 return false;
6578
6579 if (crtc_state->ips_force_disable)
6580 return false;
6581
Maarten Lankhorstadbe5c52017-11-22 19:39:06 +01006582 /* IPS should be fine as long as at least one plane is enabled. */
6583 if (!(crtc_state->active_planes & ~BIT(PLANE_CURSOR)))
Maarten Lankhorst24f28452017-11-22 19:39:01 +01006584 return false;
6585
6586 /* pixel rate mustn't exceed 95% of cdclk with IPS on BDW */
6587 if (IS_BROADWELL(dev_priv) &&
6588 crtc_state->pixel_rate > intel_state->cdclk.logical.cdclk * 95 / 100)
6589 return false;
6590
6591 return true;
Paulo Zanoni42db64e2013-05-31 16:33:22 -03006592}
6593
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006594static bool intel_crtc_supports_double_wide(const struct intel_crtc *crtc)
6595{
6596 const struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6597
6598 /* GDG double wide on either pipe, otherwise pipe A only */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00006599 return INTEL_GEN(dev_priv) < 4 &&
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006600 (crtc->pipe == PIPE_A || IS_I915G(dev_priv));
6601}
6602
Ville Syrjäläceb99322017-01-20 20:22:05 +02006603static uint32_t ilk_pipe_pixel_rate(const struct intel_crtc_state *pipe_config)
6604{
6605 uint32_t pixel_rate;
6606
6607 pixel_rate = pipe_config->base.adjusted_mode.crtc_clock;
6608
6609 /*
6610 * We only use IF-ID interlacing. If we ever use
6611 * PF-ID we'll need to adjust the pixel_rate here.
6612 */
6613
6614 if (pipe_config->pch_pfit.enabled) {
6615 uint64_t pipe_w, pipe_h, pfit_w, pfit_h;
6616 uint32_t pfit_size = pipe_config->pch_pfit.size;
6617
6618 pipe_w = pipe_config->pipe_src_w;
6619 pipe_h = pipe_config->pipe_src_h;
6620
6621 pfit_w = (pfit_size >> 16) & 0xFFFF;
6622 pfit_h = pfit_size & 0xFFFF;
6623 if (pipe_w < pfit_w)
6624 pipe_w = pfit_w;
6625 if (pipe_h < pfit_h)
6626 pipe_h = pfit_h;
6627
6628 if (WARN_ON(!pfit_w || !pfit_h))
6629 return pixel_rate;
6630
6631 pixel_rate = div_u64((uint64_t) pixel_rate * pipe_w * pipe_h,
6632 pfit_w * pfit_h);
6633 }
6634
6635 return pixel_rate;
6636}
6637
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006638static void intel_crtc_compute_pixel_rate(struct intel_crtc_state *crtc_state)
6639{
6640 struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
6641
6642 if (HAS_GMCH_DISPLAY(dev_priv))
6643 /* FIXME calculate proper pipe pixel rate for GMCH pfit */
6644 crtc_state->pixel_rate =
6645 crtc_state->base.adjusted_mode.crtc_clock;
6646 else
6647 crtc_state->pixel_rate =
6648 ilk_pipe_pixel_rate(crtc_state);
6649}
6650
Daniel Vettera43f6e02013-06-07 23:10:32 +02006651static int intel_crtc_compute_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006652 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -08006653{
Daniel Vettera43f6e02013-06-07 23:10:32 +02006654 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006655 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä7c5f93b2015-09-08 13:40:49 +03006656 const struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
Ville Syrjäläf3261152016-05-24 21:34:18 +03006657 int clock_limit = dev_priv->max_dotclk_freq;
Chris Wilson89749352010-09-12 18:25:19 +01006658
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006659 if (INTEL_GEN(dev_priv) < 4) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006660 clock_limit = dev_priv->max_cdclk_freq * 9 / 10;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006661
6662 /*
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006663 * Enable double wide mode when the dot clock
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006664 * is > 90% of the (display) core speed.
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006665 */
Ville Syrjälä39acb4a2015-10-30 23:39:38 +02006666 if (intel_crtc_supports_double_wide(crtc) &&
6667 adjusted_mode->crtc_clock > clock_limit) {
Ville Syrjäläf3261152016-05-24 21:34:18 +03006668 clock_limit = dev_priv->max_dotclk_freq;
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03006669 pipe_config->double_wide = true;
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006670 }
Ville Syrjäläf3261152016-05-24 21:34:18 +03006671 }
Ville Syrjäläad3a4472013-09-04 18:30:04 +03006672
Ville Syrjäläf3261152016-05-24 21:34:18 +03006673 if (adjusted_mode->crtc_clock > clock_limit) {
6674 DRM_DEBUG_KMS("requested pixel clock (%d kHz) too high (max: %d kHz, double wide: %s)\n",
6675 adjusted_mode->crtc_clock, clock_limit,
6676 yesno(pipe_config->double_wide));
6677 return -EINVAL;
Zhenyu Wang2c072452009-06-05 15:38:42 +08006678 }
Chris Wilson89749352010-09-12 18:25:19 +01006679
Shashank Sharma8c79f842018-10-12 11:53:09 +05306680 if ((pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
6681 pipe_config->output_format == INTEL_OUTPUT_FORMAT_YCBCR444) &&
6682 pipe_config->base.ctm) {
Shashank Sharma25edf912017-07-21 20:55:07 +05306683 /*
6684 * There is only one pipe CSC unit per pipe, and we need that
6685 * for output conversion from RGB->YCBCR. So if CTM is already
6686 * applied we can't support YCBCR420 output.
6687 */
6688 DRM_DEBUG_KMS("YCBCR420 and CTM together are not possible\n");
6689 return -EINVAL;
6690 }
6691
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006692 /*
6693 * Pipe horizontal size must be even in:
6694 * - DVO ganged mode
6695 * - LVDS dual channel mode
6696 * - Double wide pipe
6697 */
Ville Syrjälä0574bd82017-11-23 21:04:48 +02006698 if (pipe_config->pipe_src_w & 1) {
6699 if (pipe_config->double_wide) {
6700 DRM_DEBUG_KMS("Odd pipe source width not supported with double wide pipe\n");
6701 return -EINVAL;
6702 }
6703
6704 if (intel_crtc_has_type(pipe_config, INTEL_OUTPUT_LVDS) &&
6705 intel_is_dual_link_lvds(dev)) {
6706 DRM_DEBUG_KMS("Odd pipe source width not supported with dual link LVDS\n");
6707 return -EINVAL;
6708 }
6709 }
Ville Syrjälä1d1d0e22013-09-04 18:30:05 +03006710
Damien Lespiau8693a822013-05-03 18:48:11 +01006711 /* Cantiga+ cannot handle modes with a hsync front porch of 0.
6712 * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw.
Chris Wilson44f46b422012-06-21 13:19:59 +03006713 */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01006714 if ((INTEL_GEN(dev_priv) > 4 || IS_G4X(dev_priv)) &&
Ville Syrjäläaad941d2015-09-25 16:38:56 +03006715 adjusted_mode->crtc_hsync_start == adjusted_mode->crtc_hdisplay)
Daniel Vettere29c22c2013-02-21 00:00:16 +01006716 return -EINVAL;
Chris Wilson44f46b422012-06-21 13:19:59 +03006717
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +02006718 intel_crtc_compute_pixel_rate(pipe_config);
6719
Daniel Vetter877d48d2013-04-19 11:24:43 +02006720 if (pipe_config->has_pch_encoder)
Daniel Vettera43f6e02013-06-07 23:10:32 +02006721 return ironlake_fdi_compute_config(crtc, pipe_config);
Daniel Vetter877d48d2013-04-19 11:24:43 +02006722
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +02006723 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08006724}
6725
Zhenyu Wang2c072452009-06-05 15:38:42 +08006726static void
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006727intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006728{
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006729 while (*num > DATA_LINK_M_N_MASK ||
6730 *den > DATA_LINK_M_N_MASK) {
Zhenyu Wang2c072452009-06-05 15:38:42 +08006731 *num >>= 1;
6732 *den >>= 1;
6733 }
6734}
6735
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006736static void compute_m_n(unsigned int m, unsigned int n,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006737 uint32_t *ret_m, uint32_t *ret_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006738 bool constant_n)
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006739{
Jani Nikula9a86cda2017-03-27 14:33:25 +03006740 /*
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006741 * Several DP dongles in particular seem to be fussy about
6742 * too large link M/N values. Give N value as 0x8000 that
6743 * should be acceptable by specific devices. 0x8000 is the
6744 * specified fixed N value for asynchronous clock mode,
6745 * which the devices expect also in synchronous clock mode.
Jani Nikula9a86cda2017-03-27 14:33:25 +03006746 */
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006747 if (constant_n)
6748 *ret_n = 0x8000;
6749 else
6750 *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX);
Jani Nikula9a86cda2017-03-27 14:33:25 +03006751
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006752 *ret_m = div_u64((uint64_t) m * *ret_n, n);
6753 intel_reduce_m_n_ratio(ret_m, ret_n);
6754}
6755
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006756void
Manasi Navarea4a15772018-11-28 13:36:21 -08006757intel_link_compute_m_n(u16 bits_per_pixel, int nlanes,
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006758 int pixel_clock, int link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006759 struct intel_link_m_n *m_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006760 bool constant_n)
Zhenyu Wang2c072452009-06-05 15:38:42 +08006761{
Daniel Vettere69d0bc2012-11-29 15:59:36 +01006762 m_n->tu = 64;
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006763
6764 compute_m_n(bits_per_pixel * pixel_clock,
6765 link_clock * nlanes * 8,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006766 &m_n->gmch_m, &m_n->gmch_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006767 constant_n);
Ville Syrjäläa65851a2013-04-23 15:03:34 +03006768
6769 compute_m_n(pixel_clock, link_clock,
Jani Nikulab31e85e2017-05-18 14:10:25 +03006770 &m_n->link_m, &m_n->link_n,
Lee, Shawn C53ca2ed2018-09-11 23:22:50 -07006771 constant_n);
Zhenyu Wang2c072452009-06-05 15:38:42 +08006772}
6773
Chris Wilsona7615032011-01-12 17:04:08 +00006774static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
6775{
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00006776 if (i915_modparams.panel_use_ssc >= 0)
6777 return i915_modparams.panel_use_ssc != 0;
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03006778 return dev_priv->vbt.lvds_use_ssc
Keith Packard435793d2011-07-12 14:56:22 -07006779 && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
Chris Wilsona7615032011-01-12 17:04:08 +00006780}
6781
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006782static uint32_t pnv_dpll_compute_fp(struct dpll *dpll)
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006783{
Daniel Vetter7df00d72013-05-21 21:54:55 +02006784 return (1 << dpll->n) << 16 | dpll->m2;
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006785}
Daniel Vetterf47709a2013-03-28 10:42:02 +01006786
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006787static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll)
6788{
6789 return dpll->n << 16 | dpll->m1 << 8 | dpll->m2;
Jesse Barnesc65d77d2011-12-15 12:30:36 -08006790}
6791
Daniel Vetterf47709a2013-03-28 10:42:02 +01006792static void i9xx_update_pll_dividers(struct intel_crtc *crtc,
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006793 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03006794 struct dpll *reduced_clock)
Jesse Barnesa7516a02011-12-15 12:30:37 -08006795{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006797 u32 fp, fp2 = 0;
6798
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02006799 if (IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006800 fp = pnv_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006801 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006802 fp2 = pnv_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006803 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006804 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006805 if (reduced_clock)
Daniel Vetter7429e9d2013-04-20 17:19:46 +02006806 fp2 = i9xx_dpll_compute_fp(reduced_clock);
Jesse Barnesa7516a02011-12-15 12:30:37 -08006807 }
6808
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006809 crtc_state->dpll_hw_state.fp0 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006810
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03006811 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Rodrigo Viviab585de2015-03-24 12:40:09 -07006812 reduced_clock) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006813 crtc_state->dpll_hw_state.fp1 = fp2;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006814 } else {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02006815 crtc_state->dpll_hw_state.fp1 = fp;
Jesse Barnesa7516a02011-12-15 12:30:37 -08006816 }
6817}
6818
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006819static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe
6820 pipe)
Jesse Barnes89b667f2013-04-18 14:51:36 -07006821{
6822 u32 reg_val;
6823
6824 /*
6825 * PLLB opamp always calibrates to max value of 0x3f, force enable it
6826 * and set it to a reasonable value instead.
6827 */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006828 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006829 reg_val &= 0xffffff00;
6830 reg_val |= 0x00000030;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006831 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006832
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006833 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Imre Deaked585702017-05-10 12:21:47 +03006834 reg_val &= 0x00ffffff;
6835 reg_val |= 0x8c000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006836 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006837
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006838 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1));
Jesse Barnes89b667f2013-04-18 14:51:36 -07006839 reg_val &= 0xffffff00;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006840 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006841
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006842 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006843 reg_val &= 0x00ffffff;
6844 reg_val |= 0xb0000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08006845 vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006846}
6847
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006848static void intel_pch_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6849 const struct intel_link_m_n *m_n)
Daniel Vetterb5518422013-05-03 11:49:48 +02006850{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006851 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
6852 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
6853 enum pipe pipe = crtc->pipe;
Daniel Vetterb5518422013-05-03 11:49:48 +02006854
Daniel Vettere3b95f12013-05-03 11:49:49 +02006855 I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6856 I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n);
6857 I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m);
6858 I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006859}
6860
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006861static bool transcoder_has_m2_n2(struct drm_i915_private *dev_priv,
6862 enum transcoder transcoder)
6863{
6864 if (IS_HASWELL(dev_priv))
6865 return transcoder == TRANSCODER_EDP;
6866
6867 /*
6868 * Strictly speaking some registers are available before
6869 * gen7, but we only support DRRS on gen7+
6870 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08006871 return IS_GEN(dev_priv, 7) || IS_CHERRYVIEW(dev_priv);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006872}
6873
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006874static void intel_cpu_transcoder_set_m_n(const struct intel_crtc_state *crtc_state,
6875 const struct intel_link_m_n *m_n,
6876 const struct intel_link_m_n *m2_n2)
Daniel Vetterb5518422013-05-03 11:49:48 +02006877{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006878 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006879 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006880 enum pipe pipe = crtc->pipe;
6881 enum transcoder transcoder = crtc_state->cpu_transcoder;
Daniel Vetterb5518422013-05-03 11:49:48 +02006882
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00006883 if (INTEL_GEN(dev_priv) >= 5) {
Daniel Vetterb5518422013-05-03 11:49:48 +02006884 I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m);
6885 I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n);
6886 I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m);
6887 I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n);
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006888 /*
6889 * M2_N2 registers are set only if DRRS is supported
6890 * (to make sure the registers are not unnecessarily accessed).
Vandana Kannanf769cd22014-08-05 07:51:22 -07006891 */
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02006892 if (m2_n2 && crtc_state->has_drrs &&
6893 transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanf769cd22014-08-05 07:51:22 -07006894 I915_WRITE(PIPE_DATA_M2(transcoder),
6895 TU_SIZE(m2_n2->tu) | m2_n2->gmch_m);
6896 I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n);
6897 I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m);
6898 I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n);
6899 }
Daniel Vetterb5518422013-05-03 11:49:48 +02006900 } else {
Daniel Vettere3b95f12013-05-03 11:49:49 +02006901 I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m);
6902 I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n);
6903 I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m);
6904 I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n);
Daniel Vetterb5518422013-05-03 11:49:48 +02006905 }
6906}
6907
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006908void 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 +02006909{
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006910 const struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306911
6912 if (m_n == M1_N1) {
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006913 dp_m_n = &crtc_state->dp_m_n;
6914 dp_m2_n2 = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306915 } else if (m_n == M2_N2) {
6916
6917 /*
6918 * M2_N2 registers are not supported. Hence m2_n2 divider value
6919 * needs to be programmed into M1_N1.
6920 */
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006921 dp_m_n = &crtc_state->dp_m2_n2;
Ramalingam Cfe3cd482015-02-13 15:32:59 +05306922 } else {
6923 DRM_ERROR("Unsupported divider value\n");
6924 return;
6925 }
6926
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006927 if (crtc_state->has_pch_encoder)
6928 intel_pch_transcoder_set_m_n(crtc_state, &crtc_state->dp_m_n);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006929 else
Maarten Lankhorst4c354752018-10-11 12:04:49 +02006930 intel_cpu_transcoder_set_m_n(crtc_state, dp_m_n, dp_m2_n2);
Daniel Vetter03afc4a2013-04-02 23:42:31 +02006931}
6932
Daniel Vetter251ac862015-06-18 10:30:24 +02006933static void vlv_compute_dpll(struct intel_crtc *crtc,
6934 struct intel_crtc_state *pipe_config)
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006935{
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006936 pipe_config->dpll_hw_state.dpll = DPLL_INTEGRATED_REF_CLK_VLV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006937 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006938 if (crtc->pipe != PIPE_A)
6939 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006940
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006941 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006942 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006943 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE |
6944 DPLL_EXT_BUFFER_ENABLE_VLV;
6945
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006946 pipe_config->dpll_hw_state.dpll_md =
6947 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
6948}
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006949
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006950static void chv_compute_dpll(struct intel_crtc *crtc,
6951 struct intel_crtc_state *pipe_config)
6952{
6953 pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLK_CHV |
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006954 DPLL_REF_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS;
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006955 if (crtc->pipe != PIPE_A)
6956 pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV;
6957
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006958 /* DPLL not used with DSI, but still need the rest set up */
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03006959 if (!intel_crtc_has_type(pipe_config, INTEL_OUTPUT_DSI))
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006960 pipe_config->dpll_hw_state.dpll |= DPLL_VCO_ENABLE;
6961
Ville Syrjälä03ed5cbf2016-03-15 16:39:55 +02006962 pipe_config->dpll_hw_state.dpll_md =
6963 (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006964}
6965
Ville Syrjäläd288f652014-10-28 13:20:22 +02006966static void vlv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02006967 const struct intel_crtc_state *pipe_config)
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006968{
Daniel Vetterf47709a2013-03-28 10:42:02 +01006969 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01006970 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006971 enum pipe pipe = crtc->pipe;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006972 u32 mdiv;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006973 u32 bestn, bestm1, bestm2, bestp1, bestp2;
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006974 u32 coreclk, reg_val;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006975
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03006976 /* Enable Refclk */
6977 I915_WRITE(DPLL(pipe),
6978 pipe_config->dpll_hw_state.dpll &
6979 ~(DPLL_VCO_ENABLE | DPLL_EXT_BUFFER_ENABLE_VLV));
6980
6981 /* No need to actually set up the DPLL with DSI */
6982 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
6983 return;
6984
Ville Syrjäläa5805162015-05-26 20:42:30 +03006985 mutex_lock(&dev_priv->sb_lock);
Daniel Vetter09153002012-12-12 14:06:44 +01006986
Ville Syrjäläd288f652014-10-28 13:20:22 +02006987 bestn = pipe_config->dpll.n;
6988 bestm1 = pipe_config->dpll.m1;
6989 bestm2 = pipe_config->dpll.m2;
6990 bestp1 = pipe_config->dpll.p1;
6991 bestp2 = pipe_config->dpll.p2;
Jesse Barnesa0c4da242012-06-15 11:55:13 -07006992
Jesse Barnes89b667f2013-04-18 14:51:36 -07006993 /* See eDP HDMI DPIO driver vbios notes doc */
6994
6995 /* PLL B needs special handling */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02006996 if (pipe == PIPE_B)
Chon Ming Lee5e69f972013-09-05 20:41:49 +08006997 vlv_pllb_recal_opamp(dev_priv, pipe);
Jesse Barnes89b667f2013-04-18 14:51:36 -07006998
6999 /* Set up Tx target for periodic Rcomp update */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007000 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007001
7002 /* Disable target IRef on PLL */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007003 reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007004 reg_val &= 0x00ffffff;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007005 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007006
7007 /* Disable fast lock */
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007008 vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007009
7010 /* Set idtafcrecal before PLL is enabled */
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007011 mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
7012 mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
7013 mdiv |= ((bestn << DPIO_N_SHIFT));
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007014 mdiv |= (1 << DPIO_K_SHIFT);
Jesse Barnes7df50802013-05-02 10:48:09 -07007015
7016 /*
7017 * Post divider depends on pixel clock rate, DAC vs digital (and LVDS,
7018 * but we don't support that).
7019 * Note: don't use the DAC post divider as it seems unstable.
7020 */
7021 mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007022 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007023
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007024 mdiv |= DPIO_ENABLE_CALIBRATION;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007025 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007026
Jesse Barnes89b667f2013-04-18 14:51:36 -07007027 /* Set HBR and RBR LPF coefficients */
Ville Syrjäläd288f652014-10-28 13:20:22 +02007028 if (pipe_config->port_clock == 162000 ||
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007029 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_ANALOG) ||
7030 intel_crtc_has_type(pipe_config, INTEL_OUTPUT_HDMI))
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007031 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Ville Syrjälä885b01202013-07-05 19:21:38 +03007032 0x009f0003);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007033 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007034 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007035 0x00d0000f);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007036
Ville Syrjälä37a56502016-06-22 21:57:04 +03007037 if (intel_crtc_has_dp_encoder(pipe_config)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -07007038 /* Use SSC source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007039 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007040 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007041 0x0df40000);
7042 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007043 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007044 0x0df70000);
7045 } else { /* HDMI or VGA */
7046 /* Use bend source */
Daniel Vetterbdd4b6a2014-04-24 23:55:11 +02007047 if (pipe == PIPE_A)
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007048 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007049 0x0df70000);
7050 else
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007051 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe),
Jesse Barnes89b667f2013-04-18 14:51:36 -07007052 0x0df40000);
7053 }
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007054
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007055 coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe));
Jesse Barnes89b667f2013-04-18 14:51:36 -07007056 coreclk = (coreclk & 0x0000ff00) | 0x01c00000;
Maarten Lankhorst92d54b02018-10-11 12:04:50 +02007057 if (intel_crtc_has_dp_encoder(pipe_config))
Jesse Barnes89b667f2013-04-18 14:51:36 -07007058 coreclk |= 0x01000000;
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007059 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk);
Jesse Barnes89b667f2013-04-18 14:51:36 -07007060
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007061 vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000);
Ville Syrjäläa5805162015-05-26 20:42:30 +03007062 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesa0c4da242012-06-15 11:55:13 -07007063}
7064
Ville Syrjäläd288f652014-10-28 13:20:22 +02007065static void chv_prepare_pll(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007066 const struct intel_crtc_state *pipe_config)
Ville Syrjälä1ae0d132014-06-28 02:04:00 +03007067{
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007068 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007069 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007070 enum pipe pipe = crtc->pipe;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007071 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307072 u32 loopfilter, tribuf_calcntr;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007073 u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307074 u32 dpio_val;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307075 int vco;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007076
Ville Syrjäläcd2d34d2016-04-12 22:14:34 +03007077 /* Enable Refclk and SSC */
7078 I915_WRITE(DPLL(pipe),
7079 pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE);
7080
7081 /* No need to actually set up the DPLL with DSI */
7082 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7083 return;
7084
Ville Syrjäläd288f652014-10-28 13:20:22 +02007085 bestn = pipe_config->dpll.n;
7086 bestm2_frac = pipe_config->dpll.m2 & 0x3fffff;
7087 bestm1 = pipe_config->dpll.m1;
7088 bestm2 = pipe_config->dpll.m2 >> 22;
7089 bestp1 = pipe_config->dpll.p1;
7090 bestp2 = pipe_config->dpll.p2;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307091 vco = pipe_config->dpll.vco;
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307092 dpio_val = 0;
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307093 loopfilter = 0;
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007094
Ville Syrjäläa5805162015-05-26 20:42:30 +03007095 mutex_lock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007096
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007097 /* p1 and p2 divider */
7098 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port),
7099 5 << DPIO_CHV_S1_DIV_SHIFT |
7100 bestp1 << DPIO_CHV_P1_DIV_SHIFT |
7101 bestp2 << DPIO_CHV_P2_DIV_SHIFT |
7102 1 << DPIO_CHV_K_DIV_SHIFT);
7103
7104 /* Feedback post-divider - m2 */
7105 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2);
7106
7107 /* Feedback refclk divider - n and m1 */
7108 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port),
7109 DPIO_CHV_M1_DIV_BY_2 |
7110 1 << DPIO_CHV_N_DIV_SHIFT);
7111
7112 /* M2 fraction division */
Ville Syrjälä25a25df2015-07-08 23:45:47 +03007113 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007114
7115 /* M2 fraction division enable */
Vijay Purushothamana945ce7e2015-03-05 19:30:57 +05307116 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
7117 dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN);
7118 dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT);
7119 if (bestm2_frac)
7120 dpio_val |= DPIO_CHV_FRAC_DIV_EN;
7121 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007122
Vijay Purushothamande3a0fd2015-03-05 19:32:06 +05307123 /* Program digital lock detect threshold */
7124 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port));
7125 dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK |
7126 DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE);
7127 dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT);
7128 if (!bestm2_frac)
7129 dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE;
7130 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val);
7131
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007132 /* Loop filter */
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307133 if (vco == 5400000) {
7134 loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT);
7135 loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT);
7136 loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT);
7137 tribuf_calcntr = 0x9;
7138 } else if (vco <= 6200000) {
7139 loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT);
7140 loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT);
7141 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7142 tribuf_calcntr = 0x9;
7143 } else if (vco <= 6480000) {
7144 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7145 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7146 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7147 tribuf_calcntr = 0x8;
7148 } else {
7149 /* Not supported. Apply the same limits as in the max case */
7150 loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT);
7151 loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT);
7152 loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT);
7153 tribuf_calcntr = 0;
7154 }
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007155 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter);
7156
Ville Syrjälä968040b2015-03-11 22:52:08 +02007157 dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port));
Vijay Purushothaman9cbe40c2015-03-05 19:33:08 +05307158 dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK;
7159 dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT);
7160 vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val);
7161
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007162 /* AFC Recal */
7163 vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port),
7164 vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) |
7165 DPIO_AFC_RECAL);
7166
Ville Syrjäläa5805162015-05-26 20:42:30 +03007167 mutex_unlock(&dev_priv->sb_lock);
Chon Ming Lee9d556c92014-05-02 14:27:47 +03007168}
7169
Ville Syrjäläd288f652014-10-28 13:20:22 +02007170/**
7171 * vlv_force_pll_on - forcibly enable just the PLL
7172 * @dev_priv: i915 private structure
7173 * @pipe: pipe PLL to enable
7174 * @dpll: PLL configuration
7175 *
7176 * Enable the PLL for @pipe using the supplied @dpll config. To be used
7177 * in cases where we need the PLL enabled even when @pipe is not going to
7178 * be enabled.
7179 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007180int vlv_force_pll_on(struct drm_i915_private *dev_priv, enum pipe pipe,
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007181 const struct dpll *dpll)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007182{
Ville Syrjäläb91eb5c2016-10-31 22:37:09 +02007183 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007184 struct intel_crtc_state *pipe_config;
7185
7186 pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL);
7187 if (!pipe_config)
7188 return -ENOMEM;
7189
7190 pipe_config->base.crtc = &crtc->base;
7191 pipe_config->pixel_multiplier = 1;
7192 pipe_config->dpll = *dpll;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007193
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007194 if (IS_CHERRYVIEW(dev_priv)) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007195 chv_compute_dpll(crtc, pipe_config);
7196 chv_prepare_pll(crtc, pipe_config);
7197 chv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007198 } else {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007199 vlv_compute_dpll(crtc, pipe_config);
7200 vlv_prepare_pll(crtc, pipe_config);
7201 vlv_enable_pll(crtc, pipe_config);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007202 }
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +00007203
7204 kfree(pipe_config);
7205
7206 return 0;
Ville Syrjäläd288f652014-10-28 13:20:22 +02007207}
7208
7209/**
7210 * vlv_force_pll_off - forcibly disable just the PLL
7211 * @dev_priv: i915 private structure
7212 * @pipe: pipe PLL to disable
7213 *
7214 * Disable the PLL for @pipe. To be used in cases where we need
7215 * the PLL enabled even when @pipe is not going to be enabled.
7216 */
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007217void vlv_force_pll_off(struct drm_i915_private *dev_priv, enum pipe pipe)
Ville Syrjäläd288f652014-10-28 13:20:22 +02007218{
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007219 if (IS_CHERRYVIEW(dev_priv))
7220 chv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007221 else
Ville Syrjälä30ad9812016-10-31 22:37:07 +02007222 vlv_disable_pll(dev_priv, pipe);
Ville Syrjäläd288f652014-10-28 13:20:22 +02007223}
7224
Daniel Vetter251ac862015-06-18 10:30:24 +02007225static void i9xx_compute_dpll(struct intel_crtc *crtc,
7226 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007227 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007228{
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007229 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007230 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007231 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007232
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007233 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307234
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007235 dpll = DPLL_VGA_MODE_DIS;
7236
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007237 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007238 dpll |= DPLLB_MODE_LVDS;
7239 else
7240 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter6cc5f342013-03-27 00:44:53 +01007241
Jani Nikula73f67aa2016-12-07 22:48:09 +02007242 if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
7243 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007244 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetter198a037f2013-04-19 11:14:37 +02007245 << SDVO_MULTIPLIER_SHIFT_HIRES;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007246 }
Daniel Vetter198a037f2013-04-19 11:14:37 +02007247
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03007248 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
7249 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007250 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vetter198a037f2013-04-19 11:14:37 +02007251
Ville Syrjälä37a56502016-06-22 21:57:04 +03007252 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007253 dpll |= DPLL_SDVO_HIGH_SPEED;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007254
7255 /* compute bitmask from p1 value */
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007256 if (IS_PINEVIEW(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007257 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
7258 else {
7259 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007260 if (IS_G4X(dev_priv) && reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007261 dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
7262 }
7263 switch (clock->p2) {
7264 case 5:
7265 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
7266 break;
7267 case 7:
7268 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
7269 break;
7270 case 10:
7271 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
7272 break;
7273 case 14:
7274 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
7275 break;
7276 }
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007277 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007278 dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
7279
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007280 if (crtc_state->sdvo_tv_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007281 dpll |= PLL_REF_INPUT_TVCLKINBC;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007282 else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007283 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007284 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7285 else
7286 dpll |= PLL_REF_INPUT_DREFCLK;
7287
7288 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007289 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02007290
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +02007291 if (INTEL_GEN(dev_priv) >= 4) {
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007292 u32 dpll_md = (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02007293 << DPLL_MD_UDI_MULTIPLIER_SHIFT;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007294 crtc_state->dpll_hw_state.dpll_md = dpll_md;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007295 }
7296}
7297
Daniel Vetter251ac862015-06-18 10:30:24 +02007298static void i8xx_compute_dpll(struct intel_crtc *crtc,
7299 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007300 struct dpll *reduced_clock)
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007301{
Daniel Vetterf47709a2013-03-28 10:42:02 +01007302 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007303 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007304 u32 dpll;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007305 struct dpll *clock = &crtc_state->dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007306
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007307 i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock);
Vijay Purushothaman2a8f64c2012-09-27 19:13:06 +05307308
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007309 dpll = DPLL_VGA_MODE_DIS;
7310
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007311 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007312 dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7313 } else {
7314 if (clock->p1 == 2)
7315 dpll |= PLL_P1_DIVIDE_BY_TWO;
7316 else
7317 dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
7318 if (clock->p2 == 4)
7319 dpll |= PLL_P2_DIVIDE_BY_4;
7320 }
7321
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007322 if (!IS_I830(dev_priv) &&
7323 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO))
Daniel Vetter4a33e482013-07-06 12:52:05 +02007324 dpll |= DPLL_DVO_2X_MODE;
7325
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007326 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
Ander Conselvan de Oliveiraceb41002016-03-21 18:00:02 +02007327 intel_panel_use_ssc(dev_priv))
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007328 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
7329 else
7330 dpll |= PLL_REF_INPUT_DREFCLK;
7331
7332 dpll |= DPLL_VCO_ENABLE;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02007333 crtc_state->dpll_hw_state.dpll = dpll;
Daniel Vettereb1cbe42012-03-28 23:12:16 +02007334}
7335
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007336static void intel_set_pipe_timings(const struct intel_crtc_state *crtc_state)
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007337{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007338 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7339 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7340 enum pipe pipe = crtc->pipe;
7341 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
7342 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007343 uint32_t crtc_vtotal, crtc_vblank_end;
7344 int vsyncshift = 0;
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007345
7346 /* We need to be careful not to changed the adjusted mode, for otherwise
7347 * the hw state checker will get angry at the mismatch. */
7348 crtc_vtotal = adjusted_mode->crtc_vtotal;
7349 crtc_vblank_end = adjusted_mode->crtc_vblank_end;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007350
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007351 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007352 /* the chip adds 2 halflines automatically */
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007353 crtc_vtotal -= 1;
7354 crtc_vblank_end -= 1;
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007355
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007356 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjälä609aeac2014-03-28 23:29:30 +02007357 vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2;
7358 else
7359 vsyncshift = adjusted_mode->crtc_hsync_start -
7360 adjusted_mode->crtc_htotal / 2;
Ville Syrjälä1caea6e2014-03-28 23:29:32 +02007361 if (vsyncshift < 0)
7362 vsyncshift += adjusted_mode->crtc_htotal;
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007363 }
7364
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007365 if (INTEL_GEN(dev_priv) > 3)
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007366 I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007367
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007368 I915_WRITE(HTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007369 (adjusted_mode->crtc_hdisplay - 1) |
7370 ((adjusted_mode->crtc_htotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007371 I915_WRITE(HBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007372 (adjusted_mode->crtc_hblank_start - 1) |
7373 ((adjusted_mode->crtc_hblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007374 I915_WRITE(HSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007375 (adjusted_mode->crtc_hsync_start - 1) |
7376 ((adjusted_mode->crtc_hsync_end - 1) << 16));
7377
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007378 I915_WRITE(VTOTAL(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007379 (adjusted_mode->crtc_vdisplay - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007380 ((crtc_vtotal - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007381 I915_WRITE(VBLANK(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007382 (adjusted_mode->crtc_vblank_start - 1) |
Daniel Vetter4d8a62e2013-05-03 11:49:51 +02007383 ((crtc_vblank_end - 1) << 16));
Paulo Zanonife2b8f92012-10-23 18:30:02 -02007384 I915_WRITE(VSYNC(cpu_transcoder),
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007385 (adjusted_mode->crtc_vsync_start - 1) |
7386 ((adjusted_mode->crtc_vsync_end - 1) << 16));
7387
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007388 /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
7389 * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
7390 * documented on the DDI_FUNC_CTL register description, EDP Input Select
7391 * bits. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01007392 if (IS_HASWELL(dev_priv) && cpu_transcoder == TRANSCODER_EDP &&
Paulo Zanonib5e508d2012-10-24 11:34:43 -02007393 (pipe == PIPE_B || pipe == PIPE_C))
7394 I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
7395
Jani Nikulabc58be62016-03-18 17:05:39 +02007396}
7397
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007398static void intel_set_pipe_src_size(const struct intel_crtc_state *crtc_state)
Jani Nikulabc58be62016-03-18 17:05:39 +02007399{
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007400 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7401 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7402 enum pipe pipe = crtc->pipe;
Jani Nikulabc58be62016-03-18 17:05:39 +02007403
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007404 /* pipesrc controls the size that is scaled from, which should
7405 * always be the user's requested size.
7406 */
7407 I915_WRITE(PIPESRC(pipe),
Maarten Lankhorst44fe7f32018-10-04 11:45:54 +02007408 ((crtc_state->pipe_src_w - 1) << 16) |
7409 (crtc_state->pipe_src_h - 1));
Paulo Zanonib0e77b92012-10-01 18:10:53 -03007410}
7411
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007412static void intel_get_pipe_timings(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007413 struct intel_crtc_state *pipe_config)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007414{
7415 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007416 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007417 enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
7418 uint32_t tmp;
7419
7420 tmp = I915_READ(HTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007421 pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1;
7422 pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007423 tmp = I915_READ(HBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007424 pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1;
7425 pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007426 tmp = I915_READ(HSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007427 pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1;
7428 pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007429
7430 tmp = I915_READ(VTOTAL(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007431 pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1;
7432 pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007433 tmp = I915_READ(VBLANK(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007434 pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1;
7435 pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007436 tmp = I915_READ(VSYNC(cpu_transcoder));
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007437 pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1;
7438 pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007439
7440 if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007441 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE;
7442 pipe_config->base.adjusted_mode.crtc_vtotal += 1;
7443 pipe_config->base.adjusted_mode.crtc_vblank_end += 1;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007444 }
Jani Nikulabc58be62016-03-18 17:05:39 +02007445}
7446
7447static void intel_get_pipe_src_size(struct intel_crtc *crtc,
7448 struct intel_crtc_state *pipe_config)
7449{
7450 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007451 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulabc58be62016-03-18 17:05:39 +02007452 u32 tmp;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007453
7454 tmp = I915_READ(PIPESRC(crtc->pipe));
Ville Syrjälä37327ab2013-09-04 18:25:28 +03007455 pipe_config->pipe_src_h = (tmp & 0xffff) + 1;
7456 pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1;
7457
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007458 pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h;
7459 pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w;
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007460}
7461
Daniel Vetterf6a83282014-02-11 15:28:57 -08007462void intel_mode_from_pipe_config(struct drm_display_mode *mode,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007463 struct intel_crtc_state *pipe_config)
Jesse Barnesbabea612013-06-26 18:57:38 +03007464{
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007465 mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay;
7466 mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal;
7467 mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start;
7468 mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007469
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007470 mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay;
7471 mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal;
7472 mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start;
7473 mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end;
Jesse Barnesbabea612013-06-26 18:57:38 +03007474
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007475 mode->flags = pipe_config->base.adjusted_mode.flags;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007476 mode->type = DRM_MODE_TYPE_DRIVER;
Jesse Barnesbabea612013-06-26 18:57:38 +03007477
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +02007478 mode->clock = pipe_config->base.adjusted_mode.crtc_clock;
Maarten Lankhorstcd13f5a2015-07-14 14:12:02 +02007479
7480 mode->hsync = drm_mode_hsync(mode);
7481 mode->vrefresh = drm_mode_vrefresh(mode);
7482 drm_mode_set_name(mode);
Jesse Barnesbabea612013-06-26 18:57:38 +03007483}
7484
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007485static void i9xx_set_pipeconf(const struct intel_crtc_state *crtc_state)
Daniel Vetter84b046f2013-02-19 18:48:54 +01007486{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007487 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
7488 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter84b046f2013-02-19 18:48:54 +01007489 uint32_t pipeconf;
7490
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007491 pipeconf = 0;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007492
Ville Syrjäläe56134b2017-06-01 17:36:19 +03007493 /* we keep both pipes enabled on 830 */
7494 if (IS_I830(dev_priv))
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007495 pipeconf |= I915_READ(PIPECONF(crtc->pipe)) & PIPECONF_ENABLE;
Daniel Vetter67c72a12013-09-24 11:46:14 +02007496
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007497 if (crtc_state->double_wide)
Ville Syrjäläcf532bb2013-09-04 18:30:02 +03007498 pipeconf |= PIPECONF_DOUBLE_WIDE;
Daniel Vetter84b046f2013-02-19 18:48:54 +01007499
Daniel Vetterff9ce462013-04-24 14:57:17 +02007500 /* only g4x and later have fancy bpc/dither controls */
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007501 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7502 IS_CHERRYVIEW(dev_priv)) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007503 /* Bspec claims that we can't use dithering for 30bpp pipes. */
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007504 if (crtc_state->dither && crtc_state->pipe_bpp != 30)
Daniel Vetterff9ce462013-04-24 14:57:17 +02007505 pipeconf |= PIPECONF_DITHER_EN |
7506 PIPECONF_DITHER_TYPE_SP;
7507
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007508 switch (crtc_state->pipe_bpp) {
Daniel Vetterff9ce462013-04-24 14:57:17 +02007509 case 18:
7510 pipeconf |= PIPECONF_6BPC;
7511 break;
7512 case 24:
7513 pipeconf |= PIPECONF_8BPC;
7514 break;
7515 case 30:
7516 pipeconf |= PIPECONF_10BPC;
7517 break;
7518 default:
7519 /* Case prevented by intel_choose_pipe_bpp_dither. */
7520 BUG();
Daniel Vetter84b046f2013-02-19 18:48:54 +01007521 }
7522 }
7523
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007524 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) {
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007525 if (INTEL_GEN(dev_priv) < 4 ||
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007526 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO))
Ville Syrjäläefc2cff2014-03-28 23:29:31 +02007527 pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
7528 else
7529 pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT;
7530 } else
Daniel Vetter84b046f2013-02-19 18:48:54 +01007531 pipeconf |= PIPECONF_PROGRESSIVE;
7532
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007533 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007534 crtc_state->limited_color_range)
Daniel Vetter9f11a9e2013-06-13 00:54:58 +02007535 pipeconf |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä9c8e09b2013-04-02 16:10:09 +03007536
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02007537 I915_WRITE(PIPECONF(crtc->pipe), pipeconf);
7538 POSTING_READ(PIPECONF(crtc->pipe));
Daniel Vetter84b046f2013-02-19 18:48:54 +01007539}
7540
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007541static int i8xx_crtc_compute_clock(struct intel_crtc *crtc,
7542 struct intel_crtc_state *crtc_state)
7543{
7544 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007545 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007546 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007547 int refclk = 48000;
7548
7549 memset(&crtc_state->dpll_hw_state, 0,
7550 sizeof(crtc_state->dpll_hw_state));
7551
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007552 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007553 if (intel_panel_use_ssc(dev_priv)) {
7554 refclk = dev_priv->vbt.lvds_ssc_freq;
7555 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7556 }
7557
7558 limit = &intel_limits_i8xx_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007559 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DVO)) {
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007560 limit = &intel_limits_i8xx_dvo;
7561 } else {
7562 limit = &intel_limits_i8xx_dac;
7563 }
7564
7565 if (!crtc_state->clock_set &&
7566 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7567 refclk, NULL, &crtc_state->dpll)) {
7568 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7569 return -EINVAL;
7570 }
7571
7572 i8xx_compute_dpll(crtc, crtc_state, NULL);
7573
7574 return 0;
7575}
7576
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007577static int g4x_crtc_compute_clock(struct intel_crtc *crtc,
7578 struct intel_crtc_state *crtc_state)
7579{
7580 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007581 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007582 const struct intel_limit *limit;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007583 int refclk = 96000;
7584
7585 memset(&crtc_state->dpll_hw_state, 0,
7586 sizeof(crtc_state->dpll_hw_state));
7587
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007588 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007589 if (intel_panel_use_ssc(dev_priv)) {
7590 refclk = dev_priv->vbt.lvds_ssc_freq;
7591 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7592 }
7593
7594 if (intel_is_dual_link_lvds(dev))
7595 limit = &intel_limits_g4x_dual_channel_lvds;
7596 else
7597 limit = &intel_limits_g4x_single_channel_lvds;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007598 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI) ||
7599 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007600 limit = &intel_limits_g4x_hdmi;
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007601 } else if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO)) {
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +02007602 limit = &intel_limits_g4x_sdvo;
7603 } else {
7604 /* The option is for other outputs */
7605 limit = &intel_limits_i9xx_sdvo;
7606 }
7607
7608 if (!crtc_state->clock_set &&
7609 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7610 refclk, NULL, &crtc_state->dpll)) {
7611 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7612 return -EINVAL;
7613 }
7614
7615 i9xx_compute_dpll(crtc, crtc_state, NULL);
7616
7617 return 0;
7618}
7619
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007620static int pnv_crtc_compute_clock(struct intel_crtc *crtc,
7621 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08007622{
Ander Conselvan de Oliveirac7653192014-10-20 13:46:44 +03007623 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007624 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007625 const struct intel_limit *limit;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007626 int refclk = 96000;
Jesse Barnes79e53942008-11-07 14:24:08 -08007627
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03007628 memset(&crtc_state->dpll_hw_state, 0,
7629 sizeof(crtc_state->dpll_hw_state));
7630
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007631 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007632 if (intel_panel_use_ssc(dev_priv)) {
7633 refclk = dev_priv->vbt.lvds_ssc_freq;
7634 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
7635 }
Jesse Barnes79e53942008-11-07 14:24:08 -08007636
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007637 limit = &intel_limits_pineview_lvds;
7638 } else {
7639 limit = &intel_limits_pineview_sdvo;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007640 }
Jani Nikulaf2335332013-09-13 11:03:09 +03007641
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007642 if (!crtc_state->clock_set &&
7643 !pnv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7644 refclk, NULL, &crtc_state->dpll)) {
7645 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7646 return -EINVAL;
7647 }
7648
7649 i9xx_compute_dpll(crtc, crtc_state, NULL);
7650
7651 return 0;
7652}
7653
7654static int i9xx_crtc_compute_clock(struct intel_crtc *crtc,
7655 struct intel_crtc_state *crtc_state)
7656{
7657 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007658 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007659 const struct intel_limit *limit;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007660 int refclk = 96000;
7661
7662 memset(&crtc_state->dpll_hw_state, 0,
7663 sizeof(crtc_state->dpll_hw_state));
7664
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03007665 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007666 if (intel_panel_use_ssc(dev_priv)) {
7667 refclk = dev_priv->vbt.lvds_ssc_freq;
7668 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk);
Jani Nikulae9fd1c02013-08-27 15:12:23 +03007669 }
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +02007670
7671 limit = &intel_limits_i9xx_lvds;
7672 } else {
7673 limit = &intel_limits_i9xx_sdvo;
7674 }
7675
7676 if (!crtc_state->clock_set &&
7677 !i9xx_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7678 refclk, NULL, &crtc_state->dpll)) {
7679 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7680 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01007681 }
Eric Anholtf564048e2011-03-30 13:01:02 -07007682
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +02007683 i9xx_compute_dpll(crtc, crtc_state, NULL);
Eric Anholtf564048e2011-03-30 13:01:02 -07007684
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02007685 return 0;
Eric Anholtf564048e2011-03-30 13:01:02 -07007686}
7687
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007688static int chv_crtc_compute_clock(struct intel_crtc *crtc,
7689 struct intel_crtc_state *crtc_state)
7690{
7691 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007692 const struct intel_limit *limit = &intel_limits_chv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007693
7694 memset(&crtc_state->dpll_hw_state, 0,
7695 sizeof(crtc_state->dpll_hw_state));
7696
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007697 if (!crtc_state->clock_set &&
7698 !chv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7699 refclk, NULL, &crtc_state->dpll)) {
7700 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7701 return -EINVAL;
7702 }
7703
7704 chv_compute_dpll(crtc, crtc_state);
7705
7706 return 0;
7707}
7708
7709static int vlv_crtc_compute_clock(struct intel_crtc *crtc,
7710 struct intel_crtc_state *crtc_state)
7711{
7712 int refclk = 100000;
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03007713 const struct intel_limit *limit = &intel_limits_vlv;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007714
7715 memset(&crtc_state->dpll_hw_state, 0,
7716 sizeof(crtc_state->dpll_hw_state));
7717
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +02007718 if (!crtc_state->clock_set &&
7719 !vlv_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
7720 refclk, NULL, &crtc_state->dpll)) {
7721 DRM_ERROR("Couldn't find PLL settings for mode!\n");
7722 return -EINVAL;
7723 }
7724
7725 vlv_compute_dpll(crtc, crtc_state);
7726
7727 return 0;
7728}
7729
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007730static void i9xx_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007731 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007732{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007733 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007734 uint32_t tmp;
7735
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01007736 if (INTEL_GEN(dev_priv) <= 3 &&
7737 (IS_I830(dev_priv) || !IS_MOBILE(dev_priv)))
Ville Syrjälädc9e7dec2014-01-10 14:06:45 +02007738 return;
7739
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007740 tmp = I915_READ(PFIT_CONTROL);
Daniel Vetter06922822013-07-11 13:35:40 +02007741 if (!(tmp & PFIT_ENABLE))
7742 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007743
Daniel Vetter06922822013-07-11 13:35:40 +02007744 /* Check whether the pfit is attached to our pipe. */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007745 if (INTEL_GEN(dev_priv) < 4) {
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007746 if (crtc->pipe != PIPE_B)
7747 return;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007748 } else {
7749 if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT))
7750 return;
7751 }
7752
Daniel Vetter06922822013-07-11 13:35:40 +02007753 pipe_config->gmch_pfit.control = tmp;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007754 pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007755}
7756
Jesse Barnesacbec812013-09-20 11:29:32 -07007757static void vlv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007758 struct intel_crtc_state *pipe_config)
Jesse Barnesacbec812013-09-20 11:29:32 -07007759{
7760 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007761 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesacbec812013-09-20 11:29:32 -07007762 int pipe = pipe_config->cpu_transcoder;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007763 struct dpll clock;
Jesse Barnesacbec812013-09-20 11:29:32 -07007764 u32 mdiv;
Chris Wilson662c6ec2013-09-25 14:24:01 -07007765 int refclk = 100000;
Jesse Barnesacbec812013-09-20 11:29:32 -07007766
Ville Syrjäläb5219732016-03-15 16:40:01 +02007767 /* In case of DSI, DPLL will not be used */
7768 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
Shobhit Kumarf573de52014-07-30 20:32:37 +05307769 return;
7770
Ville Syrjäläa5805162015-05-26 20:42:30 +03007771 mutex_lock(&dev_priv->sb_lock);
Chon Ming Leeab3c7592013-11-07 10:43:30 +08007772 mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007773 mutex_unlock(&dev_priv->sb_lock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007774
7775 clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7;
7776 clock.m2 = mdiv & DPIO_M2DIV_MASK;
7777 clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf;
7778 clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7;
7779 clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f;
7780
Imre Deakdccbea32015-06-22 23:35:51 +03007781 pipe_config->port_clock = vlv_calc_dpll_params(refclk, &clock);
Jesse Barnesacbec812013-09-20 11:29:32 -07007782}
7783
Damien Lespiau5724dbd2015-01-20 12:51:52 +00007784static void
7785i9xx_get_initial_plane_config(struct intel_crtc *crtc,
7786 struct intel_initial_plane_config *plane_config)
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007787{
7788 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007789 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007790 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
7791 enum i9xx_plane_id i9xx_plane = plane->i9xx_plane;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007792 enum pipe pipe;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007793 u32 val, base, offset;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007794 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00007795 unsigned int aligned_height;
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007796 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00007797 struct intel_framebuffer *intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007798
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007799 if (!plane->get_hw_state(plane, &pipe))
Damien Lespiau42a7b082015-02-05 19:35:13 +00007800 return;
7801
Ville Syrjäläeade6c82018-01-30 22:38:03 +02007802 WARN_ON(pipe != crtc->pipe);
7803
Damien Lespiaud9806c92015-01-21 14:07:19 +00007804 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00007805 if (!intel_fb) {
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007806 DRM_DEBUG_KMS("failed to alloc fb\n");
7807 return;
7808 }
7809
Damien Lespiau1b842c82015-01-21 13:50:54 +00007810 fb = &intel_fb->base;
7811
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02007812 fb->dev = dev;
7813
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02007814 val = I915_READ(DSPCNTR(i9xx_plane));
7815
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007816 if (INTEL_GEN(dev_priv) >= 4) {
Daniel Vetter18c52472015-02-10 17:16:09 +00007817 if (val & DISPPLANE_TILED) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007818 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02007819 fb->modifier = I915_FORMAT_MOD_X_TILED;
Daniel Vetter18c52472015-02-10 17:16:09 +00007820 }
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007821
7822 if (val & DISPPLANE_ROTATE_180)
7823 plane_config->rotation = DRM_MODE_ROTATE_180;
Daniel Vetter18c52472015-02-10 17:16:09 +00007824 }
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007825
Ville Syrjäläf43348a2018-11-20 15:54:50 +02007826 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B &&
7827 val & DISPPLANE_MIRROR)
7828 plane_config->rotation |= DRM_MODE_REFLECT_X;
7829
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007830 pixel_format = val & DISPPLANE_PIXFORMAT_MASK;
Damien Lespiaub35d63f2015-01-20 12:51:50 +00007831 fourcc = i9xx_format_to_fourcc(pixel_format);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02007832 fb->format = drm_format_info(fourcc);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007833
Ville Syrjälä81894b22017-11-17 21:19:13 +02007834 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
7835 offset = I915_READ(DSPOFFSET(i9xx_plane));
7836 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
7837 } else if (INTEL_GEN(dev_priv) >= 4) {
Damien Lespiau49af4492015-01-20 12:51:44 +00007838 if (plane_config->tiling)
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007839 offset = I915_READ(DSPTILEOFF(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007840 else
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007841 offset = I915_READ(DSPLINOFF(i9xx_plane));
7842 base = I915_READ(DSPSURF(i9xx_plane)) & 0xfffff000;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007843 } else {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007844 base = I915_READ(DSPADDR(i9xx_plane));
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007845 }
7846 plane_config->base = base;
7847
7848 val = I915_READ(PIPESRC(pipe));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007849 fb->width = ((val >> 16) & 0xfff) + 1;
7850 fb->height = ((val >> 0) & 0xfff) + 1;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007851
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007852 val = I915_READ(DSPSTRIDE(i9xx_plane));
Damien Lespiaub113d5e2015-01-20 12:51:46 +00007853 fb->pitches[0] = val & 0xffffffc0;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007854
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02007855 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007856
Daniel Vetterf37b5c22015-02-10 23:12:27 +01007857 plane_config->size = fb->pitches[0] * aligned_height;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007858
Ville Syrjälä282e83e2017-11-17 21:19:12 +02007859 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
7860 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02007861 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiau2844a922015-01-20 12:51:48 +00007862 plane_config->size);
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007863
Damien Lespiau2d140302015-02-05 17:22:18 +00007864 plane_config->fb = intel_fb;
Jesse Barnes1ad292b2014-03-07 08:57:49 -08007865}
7866
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007867static void chv_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007868 struct intel_crtc_state *pipe_config)
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007869{
7870 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01007871 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007872 int pipe = pipe_config->cpu_transcoder;
7873 enum dpio_channel port = vlv_pipe_to_channel(pipe);
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03007874 struct dpll clock;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007875 u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2, pll_dw3;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007876 int refclk = 100000;
7877
Ville Syrjäläb5219732016-03-15 16:40:01 +02007878 /* In case of DSI, DPLL will not be used */
7879 if ((pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE) == 0)
7880 return;
7881
Ville Syrjäläa5805162015-05-26 20:42:30 +03007882 mutex_lock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007883 cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port));
7884 pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port));
7885 pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port));
7886 pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port));
Imre Deak0d7b6b12015-07-02 14:29:58 +03007887 pll_dw3 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port));
Ville Syrjäläa5805162015-05-26 20:42:30 +03007888 mutex_unlock(&dev_priv->sb_lock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007889
7890 clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0;
Imre Deak0d7b6b12015-07-02 14:29:58 +03007891 clock.m2 = (pll_dw0 & 0xff) << 22;
7892 if (pll_dw3 & DPIO_CHV_FRAC_DIV_EN)
7893 clock.m2 |= pll_dw2 & 0x3fffff;
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007894 clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf;
7895 clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7;
7896 clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f;
7897
Imre Deakdccbea32015-06-22 23:35:51 +03007898 pipe_config->port_clock = chv_calc_dpll_params(refclk, &clock);
Ville Syrjälä70b23a92014-04-09 13:28:22 +03007899}
7900
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307901static void intel_get_crtc_ycbcr_config(struct intel_crtc *crtc,
7902 struct intel_crtc_state *pipe_config)
7903{
7904 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
7905 enum intel_output_format output = INTEL_OUTPUT_FORMAT_RGB;
7906
Shashank Sharma668b6c12018-10-12 11:53:14 +05307907 pipe_config->lspcon_downsampling = false;
7908
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307909 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
7910 u32 tmp = I915_READ(PIPEMISC(crtc->pipe));
7911
7912 if (tmp & PIPEMISC_OUTPUT_COLORSPACE_YUV) {
7913 bool ycbcr420_enabled = tmp & PIPEMISC_YUV420_ENABLE;
7914 bool blend = tmp & PIPEMISC_YUV420_MODE_FULL_BLEND;
7915
7916 if (ycbcr420_enabled) {
7917 /* We support 4:2:0 in full blend mode only */
7918 if (!blend)
7919 output = INTEL_OUTPUT_FORMAT_INVALID;
7920 else if (!(IS_GEMINILAKE(dev_priv) ||
7921 INTEL_GEN(dev_priv) >= 10))
7922 output = INTEL_OUTPUT_FORMAT_INVALID;
7923 else
7924 output = INTEL_OUTPUT_FORMAT_YCBCR420;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307925 } else {
Shashank Sharma668b6c12018-10-12 11:53:14 +05307926 /*
7927 * Currently there is no interface defined to
7928 * check user preference between RGB/YCBCR444
7929 * or YCBCR420. So the only possible case for
7930 * YCBCR444 usage is driving YCBCR420 output
7931 * with LSPCON, when pipe is configured for
7932 * YCBCR444 output and LSPCON takes care of
7933 * downsampling it.
7934 */
7935 pipe_config->lspcon_downsampling = true;
Shashank Sharma8c79f842018-10-12 11:53:09 +05307936 output = INTEL_OUTPUT_FORMAT_YCBCR444;
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05307937 }
7938 }
7939 }
7940
7941 pipe_config->output_format = output;
7942}
7943
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007944static bool i9xx_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02007945 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007946{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007947 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02007948 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007949 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02007950 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007951
Imre Deak17290502016-02-12 18:55:11 +02007952 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
7953 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02007954 return false;
7955
Shashank Sharmad9facae2018-10-12 11:53:07 +05307956 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02007957 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02007958 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02007959
Imre Deak17290502016-02-12 18:55:11 +02007960 ret = false;
7961
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007962 tmp = I915_READ(PIPECONF(crtc->pipe));
7963 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02007964 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01007965
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +01007966 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
7967 IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä42571ae2013-09-06 23:29:00 +03007968 switch (tmp & PIPECONF_BPC_MASK) {
7969 case PIPECONF_6BPC:
7970 pipe_config->pipe_bpp = 18;
7971 break;
7972 case PIPECONF_8BPC:
7973 pipe_config->pipe_bpp = 24;
7974 break;
7975 case PIPECONF_10BPC:
7976 pipe_config->pipe_bpp = 30;
7977 break;
7978 default:
7979 break;
7980 }
7981 }
7982
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007983 if ((IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) &&
Wayne Boyer666a4532015-12-09 12:29:35 -08007984 (tmp & PIPECONF_COLOR_RANGE_SELECT))
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02007985 pipe_config->limited_color_range = true;
7986
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007987 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä282740f2013-09-04 18:30:03 +03007988 pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE;
7989
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007990 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02007991 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02007992
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02007993 i9xx_get_pfit_config(crtc, pipe_config);
7994
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00007995 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjäläc2317752016-03-15 16:39:56 +02007996 /* No way to read it out on pipes B and C */
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01007997 if (IS_CHERRYVIEW(dev_priv) && crtc->pipe != PIPE_A)
Ville Syrjäläc2317752016-03-15 16:39:56 +02007998 tmp = dev_priv->chv_dpll_md[crtc->pipe];
7999 else
8000 tmp = I915_READ(DPLL_MD(crtc->pipe));
Daniel Vetter6c49f242013-06-06 12:45:25 +02008001 pipe_config->pixel_multiplier =
8002 ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK)
8003 >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1;
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008004 pipe_config->dpll_hw_state.dpll_md = tmp;
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008005 } else if (IS_I945G(dev_priv) || IS_I945GM(dev_priv) ||
Jani Nikula73f67aa2016-12-07 22:48:09 +02008006 IS_G33(dev_priv) || IS_PINEVIEW(dev_priv)) {
Daniel Vetter6c49f242013-06-06 12:45:25 +02008007 tmp = I915_READ(DPLL(crtc->pipe));
8008 pipe_config->pixel_multiplier =
8009 ((tmp & SDVO_MULTIPLIER_MASK)
8010 >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1;
8011 } else {
8012 /* Note that on i915G/GM the pixel multiplier is in the sdvo
8013 * port and will be fixed up in the encoder->get_config
8014 * function. */
8015 pipe_config->pixel_multiplier = 1;
8016 }
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008017 pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe));
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008018 if (!IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008019 /*
8020 * DPLL_DVO_2X_MODE must be enabled for both DPLLs
8021 * on 830. Filter it out here so that we don't
8022 * report errors due to that.
8023 */
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01008024 if (IS_I830(dev_priv))
Ville Syrjälä1c4e0272014-09-05 21:52:42 +03008025 pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE;
8026
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008027 pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe));
8028 pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe));
Ville Syrjälä165e9012013-06-26 17:44:15 +03008029 } else {
8030 /* Mask out read-only status bits. */
8031 pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV |
8032 DPLL_PORTC_READY_MASK |
8033 DPLL_PORTB_READY_MASK);
Daniel Vetter8bcc2792013-06-05 13:34:28 +02008034 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02008035
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +01008036 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä70b23a92014-04-09 13:28:22 +03008037 chv_crtc_clock_get(crtc, pipe_config);
Tvrtko Ursulin11a914c2016-10-13 11:03:08 +01008038 else if (IS_VALLEYVIEW(dev_priv))
Jesse Barnesacbec812013-09-20 11:29:32 -07008039 vlv_crtc_clock_get(crtc, pipe_config);
8040 else
8041 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä18442d02013-09-13 16:00:08 +03008042
Ville Syrjälä0f646142015-08-26 19:39:18 +03008043 /*
8044 * Normally the dotclock is filled in by the encoder .get_config()
8045 * but in case the pipe is enabled w/o any ports we need a sane
8046 * default.
8047 */
8048 pipe_config->base.adjusted_mode.crtc_clock =
8049 pipe_config->port_clock / pipe_config->pixel_multiplier;
8050
Imre Deak17290502016-02-12 18:55:11 +02008051 ret = true;
8052
8053out:
8054 intel_display_power_put(dev_priv, power_domain);
8055
8056 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01008057}
8058
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008059static void ironlake_init_pch_refclk(struct drm_i915_private *dev_priv)
Jesse Barnes13d83a62011-08-03 12:59:20 -07008060{
Jesse Barnes13d83a62011-08-03 12:59:20 -07008061 struct intel_encoder *encoder;
Lyude1c1a24d2016-06-14 11:04:09 -04008062 int i;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008063 u32 val, final;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008064 bool has_lvds = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008065 bool has_cpu_edp = false;
Keith Packard199e5d72011-09-22 12:01:57 -07008066 bool has_panel = false;
Keith Packard99eb6a02011-09-26 14:29:12 -07008067 bool has_ck505 = false;
8068 bool can_ssc = false;
Lyude1c1a24d2016-06-14 11:04:09 -04008069 bool using_ssc_source = false;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008070
8071 /* We need to take the global config into account */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008072 for_each_intel_encoder(&dev_priv->drm, encoder) {
Keith Packard199e5d72011-09-22 12:01:57 -07008073 switch (encoder->type) {
8074 case INTEL_OUTPUT_LVDS:
8075 has_panel = true;
8076 has_lvds = true;
8077 break;
8078 case INTEL_OUTPUT_EDP:
8079 has_panel = true;
Ville Syrjälä8f4f2792017-11-09 17:24:34 +02008080 if (encoder->port == PORT_A)
Keith Packard199e5d72011-09-22 12:01:57 -07008081 has_cpu_edp = true;
8082 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008083 default:
8084 break;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008085 }
8086 }
8087
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008088 if (HAS_PCH_IBX(dev_priv)) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03008089 has_ck505 = dev_priv->vbt.display_clock_mode;
Keith Packard99eb6a02011-09-26 14:29:12 -07008090 can_ssc = has_ck505;
8091 } else {
8092 has_ck505 = false;
8093 can_ssc = true;
8094 }
8095
Lyude1c1a24d2016-06-14 11:04:09 -04008096 /* Check if any DPLLs are using the SSC source */
8097 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
8098 u32 temp = I915_READ(PCH_DPLL(i));
8099
8100 if (!(temp & DPLL_VCO_ENABLE))
8101 continue;
8102
8103 if ((temp & PLL_REF_INPUT_MASK) ==
8104 PLLB_REF_INPUT_SPREADSPECTRUMIN) {
8105 using_ssc_source = true;
8106 break;
8107 }
8108 }
8109
8110 DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d using_ssc_source %d\n",
8111 has_panel, has_lvds, has_ck505, using_ssc_source);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008112
8113 /* Ironlake: try to setup display ref clock before DPLL
8114 * enabling. This is only under driver's control after
8115 * PCH B stepping, previous chipset stepping should be
8116 * ignoring this setting.
8117 */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008118 val = I915_READ(PCH_DREF_CONTROL);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008119
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008120 /* As we must carefully and slowly disable/enable each source in turn,
8121 * compute the final state we want first and check if we need to
8122 * make any changes at all.
8123 */
8124 final = val;
8125 final &= ~DREF_NONSPREAD_SOURCE_MASK;
Keith Packard99eb6a02011-09-26 14:29:12 -07008126 if (has_ck505)
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008127 final |= DREF_NONSPREAD_CK505_ENABLE;
Keith Packard99eb6a02011-09-26 14:29:12 -07008128 else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008129 final |= DREF_NONSPREAD_SOURCE_ENABLE;
8130
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008131 final &= ~DREF_SSC_SOURCE_MASK;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008132 final &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Daniel Vetter8c07eb62016-06-09 18:39:07 +02008133 final &= ~DREF_SSC1_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008134
Keith Packard199e5d72011-09-22 12:01:57 -07008135 if (has_panel) {
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008136 final |= DREF_SSC_SOURCE_ENABLE;
8137
8138 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8139 final |= DREF_SSC1_ENABLE;
8140
8141 if (has_cpu_edp) {
8142 if (intel_panel_use_ssc(dev_priv) && can_ssc)
8143 final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
8144 else
8145 final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
8146 } else
8147 final |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Lyude1c1a24d2016-06-14 11:04:09 -04008148 } else if (using_ssc_source) {
8149 final |= DREF_SSC_SOURCE_ENABLE;
8150 final |= DREF_SSC1_ENABLE;
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008151 }
8152
8153 if (final == val)
8154 return;
8155
8156 /* Always enable nonspread source */
8157 val &= ~DREF_NONSPREAD_SOURCE_MASK;
8158
8159 if (has_ck505)
8160 val |= DREF_NONSPREAD_CK505_ENABLE;
8161 else
8162 val |= DREF_NONSPREAD_SOURCE_ENABLE;
8163
8164 if (has_panel) {
8165 val &= ~DREF_SSC_SOURCE_MASK;
8166 val |= DREF_SSC_SOURCE_ENABLE;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008167
Keith Packard199e5d72011-09-22 12:01:57 -07008168 /* SSC must be turned on before enabling the CPU output */
Keith Packard99eb6a02011-09-26 14:29:12 -07008169 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008170 DRM_DEBUG_KMS("Using SSC on panel\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008171 val |= DREF_SSC1_ENABLE;
Daniel Vettere77166b2012-03-30 22:14:05 +02008172 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008173 val &= ~DREF_SSC1_ENABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008174
8175 /* Get SSC going before enabling the outputs */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008176 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008177 POSTING_READ(PCH_DREF_CONTROL);
8178 udelay(200);
8179
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008180 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Jesse Barnes13d83a62011-08-03 12:59:20 -07008181
8182 /* Enable CPU source on CPU attached eDP */
Keith Packard199e5d72011-09-22 12:01:57 -07008183 if (has_cpu_edp) {
Keith Packard99eb6a02011-09-26 14:29:12 -07008184 if (intel_panel_use_ssc(dev_priv) && can_ssc) {
Keith Packard199e5d72011-09-22 12:01:57 -07008185 DRM_DEBUG_KMS("Using SSC on eDP\n");
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008186 val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
Robin Schroereba905b2014-05-18 02:24:50 +02008187 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008188 val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
Keith Packard199e5d72011-09-22 12:01:57 -07008189 } else
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008190 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008191
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008192 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008193 POSTING_READ(PCH_DREF_CONTROL);
8194 udelay(200);
8195 } else {
Lyude1c1a24d2016-06-14 11:04:09 -04008196 DRM_DEBUG_KMS("Disabling CPU source output\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008197
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008198 val &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
Keith Packard199e5d72011-09-22 12:01:57 -07008199
8200 /* Turn off CPU output */
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008201 val |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008202
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008203 I915_WRITE(PCH_DREF_CONTROL, val);
Keith Packard199e5d72011-09-22 12:01:57 -07008204 POSTING_READ(PCH_DREF_CONTROL);
8205 udelay(200);
8206
Lyude1c1a24d2016-06-14 11:04:09 -04008207 if (!using_ssc_source) {
8208 DRM_DEBUG_KMS("Disabling SSC source\n");
Keith Packard199e5d72011-09-22 12:01:57 -07008209
Lyude1c1a24d2016-06-14 11:04:09 -04008210 /* Turn off the SSC source */
8211 val &= ~DREF_SSC_SOURCE_MASK;
8212 val |= DREF_SSC_SOURCE_DISABLE;
Keith Packard199e5d72011-09-22 12:01:57 -07008213
Lyude1c1a24d2016-06-14 11:04:09 -04008214 /* Turn off SSC1 */
8215 val &= ~DREF_SSC1_ENABLE;
8216
8217 I915_WRITE(PCH_DREF_CONTROL, val);
8218 POSTING_READ(PCH_DREF_CONTROL);
8219 udelay(200);
8220 }
Jesse Barnes13d83a62011-08-03 12:59:20 -07008221 }
Chris Wilson74cfd7a2013-03-26 16:33:04 -07008222
8223 BUG_ON(val != final);
Jesse Barnes13d83a62011-08-03 12:59:20 -07008224}
8225
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008226static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008227{
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008228 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008229
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008230 tmp = I915_READ(SOUTH_CHICKEN2);
8231 tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
8232 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008233
Imre Deakcf3598c2016-06-28 13:37:31 +03008234 if (wait_for_us(I915_READ(SOUTH_CHICKEN2) &
8235 FDI_MPHY_IOSFSB_RESET_STATUS, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008236 DRM_ERROR("FDI mPHY reset assert timeout\n");
Paulo Zanonidde86e22012-12-01 12:04:25 -02008237
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008238 tmp = I915_READ(SOUTH_CHICKEN2);
8239 tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
8240 I915_WRITE(SOUTH_CHICKEN2, tmp);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008241
Imre Deakcf3598c2016-06-28 13:37:31 +03008242 if (wait_for_us((I915_READ(SOUTH_CHICKEN2) &
8243 FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100))
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008244 DRM_ERROR("FDI mPHY reset de-assert timeout\n");
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008245}
8246
8247/* WaMPhyProgramming:hsw */
8248static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv)
8249{
8250 uint32_t tmp;
Paulo Zanonidde86e22012-12-01 12:04:25 -02008251
8252 tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
8253 tmp &= ~(0xFF << 24);
8254 tmp |= (0x12 << 24);
8255 intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
8256
Paulo Zanonidde86e22012-12-01 12:04:25 -02008257 tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
8258 tmp |= (1 << 11);
8259 intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
8260
8261 tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
8262 tmp |= (1 << 11);
8263 intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
8264
Paulo Zanonidde86e22012-12-01 12:04:25 -02008265 tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
8266 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8267 intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
8268
8269 tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
8270 tmp |= (1 << 24) | (1 << 21) | (1 << 18);
8271 intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
8272
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008273 tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
8274 tmp &= ~(7 << 13);
8275 tmp |= (5 << 13);
8276 intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008277
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008278 tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
8279 tmp &= ~(7 << 13);
8280 tmp |= (5 << 13);
8281 intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008282
8283 tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
8284 tmp &= ~0xFF;
8285 tmp |= 0x1C;
8286 intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
8287
8288 tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
8289 tmp &= ~0xFF;
8290 tmp |= 0x1C;
8291 intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
8292
8293 tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
8294 tmp &= ~(0xFF << 16);
8295 tmp |= (0x1C << 16);
8296 intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
8297
8298 tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
8299 tmp &= ~(0xFF << 16);
8300 tmp |= (0x1C << 16);
8301 intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
8302
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008303 tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
8304 tmp |= (1 << 27);
8305 intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008306
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008307 tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
8308 tmp |= (1 << 27);
8309 intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008310
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008311 tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
8312 tmp &= ~(0xF << 28);
8313 tmp |= (4 << 28);
8314 intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008315
Paulo Zanoni0ff066a2013-07-12 14:19:36 -03008316 tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
8317 tmp &= ~(0xF << 28);
8318 tmp |= (4 << 28);
8319 intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008320}
8321
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008322/* Implements 3 different sequences from BSpec chapter "Display iCLK
8323 * Programming" based on the parameters passed:
8324 * - Sequence to enable CLKOUT_DP
8325 * - Sequence to enable CLKOUT_DP without spread
8326 * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O
8327 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008328static void lpt_enable_clkout_dp(struct drm_i915_private *dev_priv,
8329 bool with_spread, bool with_fdi)
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008330{
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008331 uint32_t reg, tmp;
8332
8333 if (WARN(with_fdi && !with_spread, "FDI requires downspread\n"))
8334 with_spread = true;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008335 if (WARN(HAS_PCH_LPT_LP(dev_priv) &&
8336 with_fdi, "LP PCH doesn't have FDI\n"))
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008337 with_fdi = false;
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008338
Ville Syrjäläa5805162015-05-26 20:42:30 +03008339 mutex_lock(&dev_priv->sb_lock);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008340
8341 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8342 tmp &= ~SBI_SSCCTL_DISABLE;
8343 tmp |= SBI_SSCCTL_PATHALT;
8344 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8345
8346 udelay(24);
8347
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008348 if (with_spread) {
8349 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8350 tmp &= ~SBI_SSCCTL_PATHALT;
8351 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
Paulo Zanonif31f2d52013-07-18 18:51:11 -03008352
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008353 if (with_fdi) {
8354 lpt_reset_fdi_mphy(dev_priv);
8355 lpt_program_fdi_mphy(dev_priv);
8356 }
8357 }
Paulo Zanonidde86e22012-12-01 12:04:25 -02008358
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008359 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni2fa86a12013-07-23 11:19:24 -03008360 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8361 tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8362 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
Daniel Vetterc00db242013-01-22 15:33:27 +01008363
Ville Syrjäläa5805162015-05-26 20:42:30 +03008364 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008365}
8366
Paulo Zanoni47701c32013-07-23 11:19:25 -03008367/* Sequence to disable CLKOUT_DP */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008368static void lpt_disable_clkout_dp(struct drm_i915_private *dev_priv)
Paulo Zanoni47701c32013-07-23 11:19:25 -03008369{
Paulo Zanoni47701c32013-07-23 11:19:25 -03008370 uint32_t reg, tmp;
8371
Ville Syrjäläa5805162015-05-26 20:42:30 +03008372 mutex_lock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008373
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01008374 reg = HAS_PCH_LPT_LP(dev_priv) ? SBI_GEN0 : SBI_DBUFF0;
Paulo Zanoni47701c32013-07-23 11:19:25 -03008375 tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK);
8376 tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE;
8377 intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK);
8378
8379 tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
8380 if (!(tmp & SBI_SSCCTL_DISABLE)) {
8381 if (!(tmp & SBI_SSCCTL_PATHALT)) {
8382 tmp |= SBI_SSCCTL_PATHALT;
8383 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8384 udelay(32);
8385 }
8386 tmp |= SBI_SSCCTL_DISABLE;
8387 intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
8388 }
8389
Ville Syrjäläa5805162015-05-26 20:42:30 +03008390 mutex_unlock(&dev_priv->sb_lock);
Paulo Zanoni47701c32013-07-23 11:19:25 -03008391}
8392
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008393#define BEND_IDX(steps) ((50 + (steps)) / 5)
8394
8395static const uint16_t sscdivintphase[] = {
8396 [BEND_IDX( 50)] = 0x3B23,
8397 [BEND_IDX( 45)] = 0x3B23,
8398 [BEND_IDX( 40)] = 0x3C23,
8399 [BEND_IDX( 35)] = 0x3C23,
8400 [BEND_IDX( 30)] = 0x3D23,
8401 [BEND_IDX( 25)] = 0x3D23,
8402 [BEND_IDX( 20)] = 0x3E23,
8403 [BEND_IDX( 15)] = 0x3E23,
8404 [BEND_IDX( 10)] = 0x3F23,
8405 [BEND_IDX( 5)] = 0x3F23,
8406 [BEND_IDX( 0)] = 0x0025,
8407 [BEND_IDX( -5)] = 0x0025,
8408 [BEND_IDX(-10)] = 0x0125,
8409 [BEND_IDX(-15)] = 0x0125,
8410 [BEND_IDX(-20)] = 0x0225,
8411 [BEND_IDX(-25)] = 0x0225,
8412 [BEND_IDX(-30)] = 0x0325,
8413 [BEND_IDX(-35)] = 0x0325,
8414 [BEND_IDX(-40)] = 0x0425,
8415 [BEND_IDX(-45)] = 0x0425,
8416 [BEND_IDX(-50)] = 0x0525,
8417};
8418
8419/*
8420 * Bend CLKOUT_DP
8421 * steps -50 to 50 inclusive, in steps of 5
8422 * < 0 slow down the clock, > 0 speed up the clock, 0 == no bend (135MHz)
8423 * change in clock period = -(steps / 10) * 5.787 ps
8424 */
8425static void lpt_bend_clkout_dp(struct drm_i915_private *dev_priv, int steps)
8426{
8427 uint32_t tmp;
8428 int idx = BEND_IDX(steps);
8429
8430 if (WARN_ON(steps % 5 != 0))
8431 return;
8432
8433 if (WARN_ON(idx >= ARRAY_SIZE(sscdivintphase)))
8434 return;
8435
8436 mutex_lock(&dev_priv->sb_lock);
8437
8438 if (steps % 10 != 0)
8439 tmp = 0xAAAAAAAB;
8440 else
8441 tmp = 0x00000000;
8442 intel_sbi_write(dev_priv, SBI_SSCDITHPHASE, tmp, SBI_ICLK);
8443
8444 tmp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE, SBI_ICLK);
8445 tmp &= 0xffff0000;
8446 tmp |= sscdivintphase[idx];
8447 intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE, tmp, SBI_ICLK);
8448
8449 mutex_unlock(&dev_priv->sb_lock);
8450}
8451
8452#undef BEND_IDX
8453
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008454static void lpt_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008455{
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008456 struct intel_encoder *encoder;
8457 bool has_vga = false;
8458
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008459 for_each_intel_encoder(&dev_priv->drm, encoder) {
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008460 switch (encoder->type) {
8461 case INTEL_OUTPUT_ANALOG:
8462 has_vga = true;
8463 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02008464 default:
8465 break;
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008466 }
8467 }
8468
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008469 if (has_vga) {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008470 lpt_bend_clkout_dp(dev_priv, 0);
8471 lpt_enable_clkout_dp(dev_priv, true, true);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008472 } else {
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008473 lpt_disable_clkout_dp(dev_priv);
Ville Syrjäläf7be2c22015-12-04 22:19:39 +02008474 }
Paulo Zanonibf8fa3d2013-07-12 14:19:38 -03008475}
8476
Paulo Zanonidde86e22012-12-01 12:04:25 -02008477/*
8478 * Initialize reference clocks when the driver loads
8479 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008480void intel_init_pch_refclk(struct drm_i915_private *dev_priv)
Paulo Zanonidde86e22012-12-01 12:04:25 -02008481{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008482 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008483 ironlake_init_pch_refclk(dev_priv);
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008484 else if (HAS_PCH_LPT(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02008485 lpt_init_pch_refclk(dev_priv);
Paulo Zanonidde86e22012-12-01 12:04:25 -02008486}
8487
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008488static void ironlake_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanonic8203562012-09-12 10:06:29 -03008489{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008490 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8491 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8492 enum pipe pipe = crtc->pipe;
Paulo Zanonic8203562012-09-12 10:06:29 -03008493 uint32_t val;
8494
Daniel Vetter78114072013-06-13 00:54:57 +02008495 val = 0;
Paulo Zanonic8203562012-09-12 10:06:29 -03008496
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008497 switch (crtc_state->pipe_bpp) {
Paulo Zanonic8203562012-09-12 10:06:29 -03008498 case 18:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008499 val |= PIPECONF_6BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008500 break;
8501 case 24:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008502 val |= PIPECONF_8BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008503 break;
8504 case 30:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008505 val |= PIPECONF_10BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008506 break;
8507 case 36:
Daniel Vetterdfd07d72012-12-17 11:21:38 +01008508 val |= PIPECONF_12BPC;
Paulo Zanonic8203562012-09-12 10:06:29 -03008509 break;
8510 default:
Paulo Zanonicc769b62012-09-20 18:36:03 -03008511 /* Case prevented by intel_choose_pipe_bpp_dither. */
8512 BUG();
Paulo Zanonic8203562012-09-12 10:06:29 -03008513 }
8514
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008515 if (crtc_state->dither)
Paulo Zanonic8203562012-09-12 10:06:29 -03008516 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8517
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008518 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanonic8203562012-09-12 10:06:29 -03008519 val |= PIPECONF_INTERLACED_ILK;
8520 else
8521 val |= PIPECONF_PROGRESSIVE;
8522
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008523 if (crtc_state->limited_color_range)
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008524 val |= PIPECONF_COLOR_RANGE_SELECT;
Ville Syrjälä3685a8f2013-01-17 16:31:28 +02008525
Paulo Zanonic8203562012-09-12 10:06:29 -03008526 I915_WRITE(PIPECONF(pipe), val);
8527 POSTING_READ(PIPECONF(pipe));
8528}
8529
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008530static void haswell_set_pipeconf(const struct intel_crtc_state *crtc_state)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008531{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008532 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
8533 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
8534 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Jani Nikula391bf042016-03-18 17:05:40 +02008535 u32 val = 0;
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008536
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008537 if (IS_HASWELL(dev_priv) && crtc_state->dither)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008538 val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
8539
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008540 if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008541 val |= PIPECONF_INTERLACED_ILK;
8542 else
8543 val |= PIPECONF_PROGRESSIVE;
8544
Paulo Zanoni702e7a52012-10-23 18:29:59 -02008545 I915_WRITE(PIPECONF(cpu_transcoder), val);
8546 POSTING_READ(PIPECONF(cpu_transcoder));
Jani Nikula391bf042016-03-18 17:05:40 +02008547}
8548
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008549static void haswell_set_pipemisc(const struct intel_crtc_state *crtc_state)
Jani Nikula391bf042016-03-18 17:05:40 +02008550{
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008551 struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
8552 struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
Jani Nikula391bf042016-03-18 17:05:40 +02008553
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +00008554 if (IS_BROADWELL(dev_priv) || INTEL_GEN(dev_priv) >= 9) {
Jani Nikula391bf042016-03-18 17:05:40 +02008555 u32 val = 0;
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008556
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008557 switch (crtc_state->pipe_bpp) {
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008558 case 18:
8559 val |= PIPEMISC_DITHER_6_BPC;
8560 break;
8561 case 24:
8562 val |= PIPEMISC_DITHER_8_BPC;
8563 break;
8564 case 30:
8565 val |= PIPEMISC_DITHER_10_BPC;
8566 break;
8567 case 36:
8568 val |= PIPEMISC_DITHER_12_BPC;
8569 break;
8570 default:
8571 /* Case prevented by pipe_config_set_bpp. */
8572 BUG();
8573 }
8574
Maarten Lankhorstfdf73512018-10-04 11:45:52 +02008575 if (crtc_state->dither)
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008576 val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP;
8577
Shashank Sharma8c79f842018-10-12 11:53:09 +05308578 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420 ||
8579 crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR444)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308580 val |= PIPEMISC_OUTPUT_COLORSPACE_YUV;
Shashank Sharma8c79f842018-10-12 11:53:09 +05308581
8582 if (crtc_state->output_format == INTEL_OUTPUT_FORMAT_YCBCR420)
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05308583 val |= PIPEMISC_YUV420_ENABLE |
Shashank Sharmab22ca992017-07-24 19:19:32 +05308584 PIPEMISC_YUV420_MODE_FULL_BLEND;
Shashank Sharmab22ca992017-07-24 19:19:32 +05308585
Jani Nikula391bf042016-03-18 17:05:40 +02008586 I915_WRITE(PIPEMISC(intel_crtc->pipe), val);
Paulo Zanoni756f85c2013-11-02 21:07:38 -07008587 }
Paulo Zanoniee2b0b32012-10-05 12:05:57 -03008588}
8589
Paulo Zanonid4b19312012-11-29 11:29:32 -02008590int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
8591{
8592 /*
8593 * Account for spread spectrum to avoid
8594 * oversubscribing the link. Max center spread
8595 * is 2.5%; use 5% for safety's sake.
8596 */
8597 u32 bps = target_clock * bpp * 21 / 20;
Ville Syrjälä619d4d02014-02-27 14:23:14 +02008598 return DIV_ROUND_UP(bps, link_bw * 8);
Paulo Zanonid4b19312012-11-29 11:29:32 -02008599}
8600
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008601static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor)
Daniel Vetter6cf86a52013-04-02 23:38:10 +02008602{
Daniel Vetter7429e9d2013-04-20 17:19:46 +02008603 return i9xx_dpll_compute_m(dpll) < factor * dpll->n;
Paulo Zanonif48d8f22012-09-20 18:36:04 -03008604}
8605
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008606static void ironlake_compute_dpll(struct intel_crtc *intel_crtc,
8607 struct intel_crtc_state *crtc_state,
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +03008608 struct dpll *reduced_clock)
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008609{
8610 struct drm_crtc *crtc = &intel_crtc->base;
8611 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008612 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008613 u32 dpll, fp, fp2;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008614 int factor;
Jesse Barnes79e53942008-11-07 14:24:08 -08008615
Chris Wilsonc1858122010-12-03 21:35:48 +00008616 /* Enable autotuning of the PLL clock (if permissible) */
Eric Anholt8febb292011-03-30 13:01:07 -07008617 factor = 21;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008618 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Eric Anholt8febb292011-03-30 13:01:07 -07008619 if ((intel_panel_use_ssc(dev_priv) &&
Ville Syrjäläe91e9412013-12-09 18:54:16 +02008620 dev_priv->vbt.lvds_ssc_freq == 100000) ||
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01008621 (HAS_PCH_IBX(dev_priv) && intel_is_dual_link_lvds(dev)))
Eric Anholt8febb292011-03-30 13:01:07 -07008622 factor = 25;
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008623 } else if (crtc_state->sdvo_tv_clock)
Eric Anholt8febb292011-03-30 13:01:07 -07008624 factor = 20;
Chris Wilsonc1858122010-12-03 21:35:48 +00008625
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008626 fp = i9xx_dpll_compute_fp(&crtc_state->dpll);
Chris Wilsonc1858122010-12-03 21:35:48 +00008627
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008628 if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor))
8629 fp |= FP_CB_TUNE;
8630
8631 if (reduced_clock) {
8632 fp2 = i9xx_dpll_compute_fp(reduced_clock);
8633
8634 if (reduced_clock->m < factor * reduced_clock->n)
8635 fp2 |= FP_CB_TUNE;
8636 } else {
8637 fp2 = fp;
8638 }
Daniel Vetter9a7c7892013-04-04 22:20:34 +02008639
Chris Wilson5eddb702010-09-11 13:48:45 +01008640 dpll = 0;
Zhenyu Wang2c072452009-06-05 15:38:42 +08008641
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008642 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS))
Eric Anholta07d6782011-03-30 13:01:08 -07008643 dpll |= DPLLB_MODE_LVDS;
8644 else
8645 dpll |= DPLLB_MODE_DAC_SERIAL;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008646
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008647 dpll |= (crtc_state->pixel_multiplier - 1)
Daniel Vetteref1b4602013-06-01 17:17:04 +02008648 << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
Daniel Vetter198a037f2013-04-19 11:14:37 +02008649
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008650 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_SDVO) ||
8651 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008652 dpll |= DPLL_SDVO_HIGH_SPEED;
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008653
Ville Syrjälä37a56502016-06-22 21:57:04 +03008654 if (intel_crtc_has_dp_encoder(crtc_state))
Daniel Vetter4a33e482013-07-06 12:52:05 +02008655 dpll |= DPLL_SDVO_HIGH_SPEED;
Jesse Barnes79e53942008-11-07 14:24:08 -08008656
Ville Syrjälä7d7f8632016-09-26 11:30:46 +03008657 /*
8658 * The high speed IO clock is only really required for
8659 * SDVO/HDMI/DP, but we also enable it for CRT to make it
8660 * possible to share the DPLL between CRT and HDMI. Enabling
8661 * the clock needlessly does no real harm, except use up a
8662 * bit of power potentially.
8663 *
8664 * We'll limit this to IVB with 3 pipes, since it has only two
8665 * DPLLs and so DPLL sharing is the only way to get three pipes
8666 * driving PCH ports at the same time. On SNB we could do this,
8667 * and potentially avoid enabling the second DPLL, but it's not
8668 * clear if it''s a win or loss power wise. No point in doing
8669 * this on ILK at all since it has a fixed DPLL<->pipe mapping.
8670 */
8671 if (INTEL_INFO(dev_priv)->num_pipes == 3 &&
8672 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_ANALOG))
8673 dpll |= DPLL_SDVO_HIGH_SPEED;
8674
Eric Anholta07d6782011-03-30 13:01:08 -07008675 /* compute bitmask from p1 value */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008676 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008677 /* also FPA1 */
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008678 dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
Eric Anholta07d6782011-03-30 13:01:08 -07008679
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008680 switch (crtc_state->dpll.p2) {
Eric Anholta07d6782011-03-30 13:01:08 -07008681 case 5:
8682 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
8683 break;
8684 case 7:
8685 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
8686 break;
8687 case 10:
8688 dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
8689 break;
8690 case 14:
8691 dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
8692 break;
Jesse Barnes79e53942008-11-07 14:24:08 -08008693 }
8694
Ville Syrjälä3d6e9ee2016-06-22 21:57:03 +03008695 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS) &&
8696 intel_panel_use_ssc(dev_priv))
Kristian Høgsberg43565a02009-02-13 20:56:52 -05008697 dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
Jesse Barnes79e53942008-11-07 14:24:08 -08008698 else
8699 dpll |= PLL_REF_INPUT_DREFCLK;
8700
Ander Conselvan de Oliveirab75ca6f2016-03-21 18:00:11 +02008701 dpll |= DPLL_VCO_ENABLE;
8702
8703 crtc_state->dpll_hw_state.dpll = dpll;
8704 crtc_state->dpll_hw_state.fp0 = fp;
8705 crtc_state->dpll_hw_state.fp1 = fp2;
Paulo Zanonide13a2e2012-09-20 18:36:05 -03008706}
8707
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02008708static int ironlake_crtc_compute_clock(struct intel_crtc *crtc,
8709 struct intel_crtc_state *crtc_state)
Jesse Barnes79e53942008-11-07 14:24:08 -08008710{
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008711 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008712 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira1b6f4952016-05-04 12:11:59 +03008713 const struct intel_limit *limit;
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008714 int refclk = 120000;
Jesse Barnes79e53942008-11-07 14:24:08 -08008715
Ander Conselvan de Oliveiradd3cd742015-05-15 13:34:29 +03008716 memset(&crtc_state->dpll_hw_state, 0,
8717 sizeof(crtc_state->dpll_hw_state));
8718
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008719 /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
8720 if (!crtc_state->has_pch_encoder)
8721 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008722
Ville Syrjälä2d84d2b2016-06-22 21:57:02 +03008723 if (intel_crtc_has_type(crtc_state, INTEL_OUTPUT_LVDS)) {
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008724 if (intel_panel_use_ssc(dev_priv)) {
8725 DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n",
8726 dev_priv->vbt.lvds_ssc_freq);
8727 refclk = dev_priv->vbt.lvds_ssc_freq;
8728 }
8729
8730 if (intel_is_dual_link_lvds(dev)) {
8731 if (refclk == 100000)
8732 limit = &intel_limits_ironlake_dual_lvds_100m;
8733 else
8734 limit = &intel_limits_ironlake_dual_lvds;
8735 } else {
8736 if (refclk == 100000)
8737 limit = &intel_limits_ironlake_single_lvds_100m;
8738 else
8739 limit = &intel_limits_ironlake_single_lvds;
8740 }
8741 } else {
8742 limit = &intel_limits_ironlake_dac;
8743 }
8744
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008745 if (!crtc_state->clock_set &&
Ander Conselvan de Oliveira997c0302016-03-21 18:00:12 +02008746 !g4x_find_best_dpll(limit, crtc_state, crtc_state->port_clock,
8747 refclk, NULL, &crtc_state->dpll)) {
Ander Conselvan de Oliveira364ee292016-03-21 18:00:10 +02008748 DRM_ERROR("Couldn't find PLL settings for mode!\n");
8749 return -EINVAL;
Daniel Vetterf47709a2013-03-28 10:42:02 +01008750 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008751
Gustavo A. R. Silvacbaa3312017-05-15 16:56:05 -05008752 ironlake_compute_dpll(crtc, crtc_state, NULL);
Daniel Vetter66e985c2013-06-05 13:34:20 +02008753
Gustavo A. R. Silvaefd38b62017-05-15 17:00:28 -05008754 if (!intel_get_shared_dpll(crtc, crtc_state, NULL)) {
Chris Wilson43031782018-09-13 14:16:26 +01008755 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
8756 pipe_name(crtc->pipe));
Ander Conselvan de Oliveiraded220e2016-03-21 18:00:09 +02008757 return -EINVAL;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +02008758 }
Jesse Barnes79e53942008-11-07 14:24:08 -08008759
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02008760 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08008761}
8762
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008763static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc,
8764 struct intel_link_m_n *m_n)
Daniel Vetter72419202013-04-04 13:28:53 +02008765{
8766 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008767 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008768 enum pipe pipe = crtc->pipe;
Daniel Vetter72419202013-04-04 13:28:53 +02008769
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008770 m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe));
8771 m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe));
8772 m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe))
8773 & ~TU_SIZE_MASK;
8774 m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe));
8775 m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe))
8776 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8777}
8778
8779static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc,
8780 enum transcoder transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008781 struct intel_link_m_n *m_n,
8782 struct intel_link_m_n *m2_n2)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008783{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008784 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008785 enum pipe pipe = crtc->pipe;
8786
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00008787 if (INTEL_GEN(dev_priv) >= 5) {
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008788 m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder));
8789 m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder));
8790 m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder))
8791 & ~TU_SIZE_MASK;
8792 m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder));
8793 m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder))
8794 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
Maarten Lankhorst4207c8b2018-10-15 11:40:23 +02008795
8796 if (m2_n2 && transcoder_has_m2_n2(dev_priv, transcoder)) {
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008797 m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder));
8798 m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder));
8799 m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder))
8800 & ~TU_SIZE_MASK;
8801 m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder));
8802 m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder))
8803 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8804 }
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008805 } else {
8806 m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe));
8807 m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe));
8808 m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe))
8809 & ~TU_SIZE_MASK;
8810 m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe));
8811 m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe))
8812 & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1;
8813 }
8814}
8815
8816void intel_dp_get_m_n(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008817 struct intel_crtc_state *pipe_config)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008818{
Ander Conselvan de Oliveira681a8502015-01-15 14:55:24 +02008819 if (pipe_config->has_pch_encoder)
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008820 intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n);
8821 else
8822 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008823 &pipe_config->dp_m_n,
8824 &pipe_config->dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008825}
8826
Daniel Vetter72419202013-04-04 13:28:53 +02008827static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008828 struct intel_crtc_state *pipe_config)
Daniel Vetter72419202013-04-04 13:28:53 +02008829{
Ville Syrjäläeb14cb72013-09-10 17:02:54 +03008830 intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder,
Vandana Kannanb95af8b2014-08-05 07:51:23 -07008831 &pipe_config->fdi_m_n, NULL);
Daniel Vetter72419202013-04-04 13:28:53 +02008832}
8833
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008834static void skylake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008835 struct intel_crtc_state *pipe_config)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008836{
8837 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008838 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Kondurua1b22782015-04-07 15:28:45 -07008839 struct intel_crtc_scaler_state *scaler_state = &pipe_config->scaler_state;
8840 uint32_t ps_ctrl = 0;
8841 int id = -1;
8842 int i;
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008843
Chandra Kondurua1b22782015-04-07 15:28:45 -07008844 /* find scaler attached to this pipe */
8845 for (i = 0; i < crtc->num_scalers; i++) {
8846 ps_ctrl = I915_READ(SKL_PS_CTRL(crtc->pipe, i));
8847 if (ps_ctrl & PS_SCALER_EN && !(ps_ctrl & PS_PLANE_SEL_MASK)) {
8848 id = i;
8849 pipe_config->pch_pfit.enabled = true;
8850 pipe_config->pch_pfit.pos = I915_READ(SKL_PS_WIN_POS(crtc->pipe, i));
8851 pipe_config->pch_pfit.size = I915_READ(SKL_PS_WIN_SZ(crtc->pipe, i));
8852 break;
8853 }
8854 }
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008855
Chandra Kondurua1b22782015-04-07 15:28:45 -07008856 scaler_state->scaler_id = id;
8857 if (id >= 0) {
8858 scaler_state->scaler_users |= (1 << SKL_CRTC_INDEX);
8859 } else {
8860 scaler_state->scaler_users &= ~(1 << SKL_CRTC_INDEX);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00008861 }
8862}
8863
Damien Lespiau5724dbd2015-01-20 12:51:52 +00008864static void
8865skylake_get_initial_plane_config(struct intel_crtc *crtc,
8866 struct intel_initial_plane_config *plane_config)
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008867{
8868 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008869 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008870 struct intel_plane *plane = to_intel_plane(crtc->base.primary);
8871 enum plane_id plane_id = plane->id;
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008872 enum pipe pipe;
James Ausmus4036c782017-11-13 10:11:28 -08008873 u32 val, base, offset, stride_mult, tiling, alpha;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008874 int fourcc, pixel_format;
Tvrtko Ursulin6761dd32015-03-23 11:10:32 +00008875 unsigned int aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008876 struct drm_framebuffer *fb;
Damien Lespiau1b842c82015-01-21 13:50:54 +00008877 struct intel_framebuffer *intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008878
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008879 if (!plane->get_hw_state(plane, &pipe))
Ville Syrjälä2924b8c2017-11-17 21:19:16 +02008880 return;
8881
Ville Syrjäläeade6c82018-01-30 22:38:03 +02008882 WARN_ON(pipe != crtc->pipe);
8883
Damien Lespiaud9806c92015-01-21 14:07:19 +00008884 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Damien Lespiau1b842c82015-01-21 13:50:54 +00008885 if (!intel_fb) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008886 DRM_DEBUG_KMS("failed to alloc fb\n");
8887 return;
8888 }
8889
Damien Lespiau1b842c82015-01-21 13:50:54 +00008890 fb = &intel_fb->base;
8891
Ville Syrjäläd2e9f5f2016-11-18 21:52:53 +02008892 fb->dev = dev;
8893
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008894 val = I915_READ(PLANE_CTL(pipe, plane_id));
Damien Lespiau42a7b082015-02-05 19:35:13 +00008895
James Ausmusb5972772018-01-30 11:49:16 -02008896 if (INTEL_GEN(dev_priv) >= 11)
8897 pixel_format = val & ICL_PLANE_CTL_FORMAT_MASK;
8898 else
8899 pixel_format = val & PLANE_CTL_FORMAT_MASK;
James Ausmus4036c782017-11-13 10:11:28 -08008900
8901 if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv)) {
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008902 alpha = I915_READ(PLANE_COLOR_CTL(pipe, plane_id));
James Ausmus4036c782017-11-13 10:11:28 -08008903 alpha &= PLANE_COLOR_ALPHA_MASK;
8904 } else {
8905 alpha = val & PLANE_CTL_ALPHA_MASK;
8906 }
8907
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008908 fourcc = skl_format_to_fourcc(pixel_format,
James Ausmus4036c782017-11-13 10:11:28 -08008909 val & PLANE_CTL_ORDER_RGBX, alpha);
Ville Syrjälä2f3f4762016-11-18 21:52:57 +02008910 fb->format = drm_format_info(fourcc);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008911
Damien Lespiau40f46282015-02-27 11:15:21 +00008912 tiling = val & PLANE_CTL_TILED_MASK;
8913 switch (tiling) {
8914 case PLANE_CTL_TILED_LINEAR:
Ben Widawsky2f075562017-03-24 14:29:48 -07008915 fb->modifier = DRM_FORMAT_MOD_LINEAR;
Damien Lespiau40f46282015-02-27 11:15:21 +00008916 break;
8917 case PLANE_CTL_TILED_X:
8918 plane_config->tiling = I915_TILING_X;
Ville Syrjäläbae781b2016-11-16 13:33:16 +02008919 fb->modifier = I915_FORMAT_MOD_X_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008920 break;
8921 case PLANE_CTL_TILED_Y:
Imre Deak914a4fd2018-10-16 19:00:11 +03008922 plane_config->tiling = I915_TILING_Y;
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008923 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008924 fb->modifier = I915_FORMAT_MOD_Y_TILED_CCS;
8925 else
8926 fb->modifier = I915_FORMAT_MOD_Y_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008927 break;
8928 case PLANE_CTL_TILED_YF:
Dhinakaran Pandiyan53867b42018-08-21 18:50:53 -07008929 if (val & PLANE_CTL_RENDER_DECOMPRESSION_ENABLE)
Ville Syrjälä2e2adb02017-08-01 09:58:13 -07008930 fb->modifier = I915_FORMAT_MOD_Yf_TILED_CCS;
8931 else
8932 fb->modifier = I915_FORMAT_MOD_Yf_TILED;
Damien Lespiau40f46282015-02-27 11:15:21 +00008933 break;
8934 default:
8935 MISSING_CASE(tiling);
8936 goto error;
8937 }
8938
Ville Syrjäläf43348a2018-11-20 15:54:50 +02008939 /*
8940 * DRM_MODE_ROTATE_ is counter clockwise to stay compatible with Xrandr
8941 * while i915 HW rotation is clockwise, thats why this swapping.
8942 */
8943 switch (val & PLANE_CTL_ROTATE_MASK) {
8944 case PLANE_CTL_ROTATE_0:
8945 plane_config->rotation = DRM_MODE_ROTATE_0;
8946 break;
8947 case PLANE_CTL_ROTATE_90:
8948 plane_config->rotation = DRM_MODE_ROTATE_270;
8949 break;
8950 case PLANE_CTL_ROTATE_180:
8951 plane_config->rotation = DRM_MODE_ROTATE_180;
8952 break;
8953 case PLANE_CTL_ROTATE_270:
8954 plane_config->rotation = DRM_MODE_ROTATE_90;
8955 break;
8956 }
8957
8958 if (INTEL_GEN(dev_priv) >= 10 &&
8959 val & PLANE_CTL_FLIP_HORIZONTAL)
8960 plane_config->rotation |= DRM_MODE_REFLECT_X;
8961
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008962 base = I915_READ(PLANE_SURF(pipe, plane_id)) & 0xfffff000;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008963 plane_config->base = base;
8964
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008965 offset = I915_READ(PLANE_OFFSET(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008966
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008967 val = I915_READ(PLANE_SIZE(pipe, plane_id));
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008968 fb->height = ((val >> 16) & 0xfff) + 1;
8969 fb->width = ((val >> 0) & 0x1fff) + 1;
8970
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008971 val = I915_READ(PLANE_STRIDE(pipe, plane_id));
Ville Syrjäläb3cf5c02018-09-25 22:37:08 +03008972 stride_mult = skl_plane_stride_mult(fb, 0, DRM_MODE_ROTATE_0);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008973 fb->pitches[0] = (val & 0x3ff) * stride_mult;
8974
Ville Syrjäläd88c4af2017-03-07 21:42:06 +02008975 aligned_height = intel_fb_align_height(fb, 0, fb->height);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008976
Daniel Vetterf37b5c22015-02-10 23:12:27 +01008977 plane_config->size = fb->pitches[0] * aligned_height;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008978
Ville Syrjälä282e83e2017-11-17 21:19:12 +02008979 DRM_DEBUG_KMS("%s/%s with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n",
8980 crtc->base.name, plane->base.name, fb->width, fb->height,
Ville Syrjälä272725c2016-12-14 23:32:20 +02008981 fb->format->cpp[0] * 8, base, fb->pitches[0],
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008982 plane_config->size);
8983
Damien Lespiau2d140302015-02-05 17:22:18 +00008984 plane_config->fb = intel_fb;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008985 return;
8986
8987error:
Matthew Auldd1a3a032016-08-23 16:00:44 +01008988 kfree(intel_fb);
Damien Lespiaubc8d7df2015-01-20 12:51:51 +00008989}
8990
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008991static void ironlake_get_pfit_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02008992 struct intel_crtc_state *pipe_config)
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008993{
8994 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01008995 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02008996 uint32_t tmp;
8997
8998 tmp = I915_READ(PF_CTL(crtc->pipe));
8999
9000 if (tmp & PF_ENABLE) {
Chris Wilsonfd4daa92013-08-27 17:04:17 +01009001 pipe_config->pch_pfit.enabled = true;
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009002 pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe));
9003 pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe));
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009004
9005 /* We currently do not free assignements of panel fitters on
9006 * ivb/hsw (since we don't use the higher upscaling modes which
9007 * differentiates them) so just WARN about this case for now. */
Lucas De Marchicf819ef2018-12-12 10:10:43 -08009008 if (IS_GEN(dev_priv, 7)) {
Daniel Vettercb8b2a32013-06-01 17:16:23 +02009009 WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) !=
9010 PF_PIPE_SEL_IVB(crtc->pipe));
9011 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009012 }
Jesse Barnes79e53942008-11-07 14:24:08 -08009013}
9014
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009015static bool ironlake_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009016 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009017{
9018 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009019 struct drm_i915_private *dev_priv = to_i915(dev);
Imre Deak17290502016-02-12 18:55:11 +02009020 enum intel_display_power_domain power_domain;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009021 uint32_t tmp;
Imre Deak17290502016-02-12 18:55:11 +02009022 bool ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009023
Imre Deak17290502016-02-12 18:55:11 +02009024 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9025 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Paulo Zanoni930e8c92014-07-04 13:38:34 -03009026 return false;
9027
Shashank Sharmad9facae2018-10-12 11:53:07 +05309028 pipe_config->output_format = INTEL_OUTPUT_FORMAT_RGB;
Daniel Vettere143a212013-07-04 12:01:15 +02009029 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009030 pipe_config->shared_dpll = NULL;
Daniel Vettereccb1402013-05-22 00:50:22 +02009031
Imre Deak17290502016-02-12 18:55:11 +02009032 ret = false;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009033 tmp = I915_READ(PIPECONF(crtc->pipe));
9034 if (!(tmp & PIPECONF_ENABLE))
Imre Deak17290502016-02-12 18:55:11 +02009035 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009036
Ville Syrjälä42571ae2013-09-06 23:29:00 +03009037 switch (tmp & PIPECONF_BPC_MASK) {
9038 case PIPECONF_6BPC:
9039 pipe_config->pipe_bpp = 18;
9040 break;
9041 case PIPECONF_8BPC:
9042 pipe_config->pipe_bpp = 24;
9043 break;
9044 case PIPECONF_10BPC:
9045 pipe_config->pipe_bpp = 30;
9046 break;
9047 case PIPECONF_12BPC:
9048 pipe_config->pipe_bpp = 36;
9049 break;
9050 default:
9051 break;
9052 }
9053
Daniel Vetterb5a9fa02014-04-24 23:54:49 +02009054 if (tmp & PIPECONF_COLOR_RANGE_SELECT)
9055 pipe_config->limited_color_range = true;
9056
Daniel Vetterab9412b2013-05-03 11:49:46 +02009057 if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) {
Daniel Vetter66e985c2013-06-05 13:34:20 +02009058 struct intel_shared_dpll *pll;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009059 enum intel_dpll_id pll_id;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009060
Daniel Vetter88adfff2013-03-28 10:42:01 +01009061 pipe_config->has_pch_encoder = true;
9062
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009063 tmp = I915_READ(FDI_RX_CTL(crtc->pipe));
9064 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9065 FDI_DP_PORT_WIDTH_SHIFT) + 1;
Daniel Vetter72419202013-04-04 13:28:53 +02009066
9067 ironlake_get_fdi_m_n_config(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009068
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03009069 if (HAS_PCH_IBX(dev_priv)) {
Imre Deakd9a7bc62016-05-12 16:18:50 +03009070 /*
9071 * The pipe->pch transcoder and pch transcoder->pll
9072 * mapping is fixed.
9073 */
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009074 pll_id = (enum intel_dpll_id) crtc->pipe;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009075 } else {
9076 tmp = I915_READ(PCH_DPLL_SEL);
9077 if (tmp & TRANS_DPLLB_SEL(crtc->pipe))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009078 pll_id = DPLL_ID_PCH_PLL_B;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009079 else
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009080 pll_id= DPLL_ID_PCH_PLL_A;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009081 }
Daniel Vetter66e985c2013-06-05 13:34:20 +02009082
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009083 pipe_config->shared_dpll =
9084 intel_get_shared_dpll_by_id(dev_priv, pll_id);
9085 pll = pipe_config->shared_dpll;
Daniel Vetter66e985c2013-06-05 13:34:20 +02009086
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009087 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9088 &pipe_config->dpll_hw_state));
Daniel Vetterc93f54c2013-06-27 19:47:19 +02009089
9090 tmp = pipe_config->dpll_hw_state.dpll;
9091 pipe_config->pixel_multiplier =
9092 ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK)
9093 >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1;
Ville Syrjälä18442d02013-09-13 16:00:08 +03009094
9095 ironlake_pch_clock_get(crtc, pipe_config);
Daniel Vetter6c49f242013-06-06 12:45:25 +02009096 } else {
9097 pipe_config->pixel_multiplier = 1;
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009098 }
9099
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009100 intel_get_pipe_timings(crtc, pipe_config);
Jani Nikulabc58be62016-03-18 17:05:39 +02009101 intel_get_pipe_src_size(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009102
Daniel Vetter2fa2fe92013-05-07 23:34:16 +02009103 ironlake_get_pfit_config(crtc, pipe_config);
9104
Imre Deak17290502016-02-12 18:55:11 +02009105 ret = true;
9106
9107out:
9108 intel_display_power_put(dev_priv, power_domain);
9109
9110 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009111}
9112
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009113static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv)
9114{
Chris Wilson91c8a322016-07-05 10:40:23 +01009115 struct drm_device *dev = &dev_priv->drm;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009116 struct intel_crtc *crtc;
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009117
Damien Lespiaud3fcc802014-05-13 23:32:22 +01009118 for_each_intel_crtc(dev, crtc)
Rob Clarke2c719b2014-12-15 13:56:32 -05009119 I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n",
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009120 pipe_name(crtc->pipe));
9121
Imre Deak75e39682018-08-06 12:58:39 +03009122 I915_STATE_WARN(I915_READ(HSW_PWR_WELL_CTL2),
Imre Deak9c3a16c2017-08-14 18:15:30 +03009123 "Display power well on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009124 I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n");
Ville Syrjälä01403de2015-09-18 20:03:33 +03009125 I915_STATE_WARN(I915_READ(WRPLL_CTL(0)) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n");
9126 I915_STATE_WARN(I915_READ(WRPLL_CTL(1)) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n");
Imre Deak44cb7342016-08-10 14:07:29 +03009127 I915_STATE_WARN(I915_READ(PP_STATUS(0)) & PP_ON, "Panel power on\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009128 I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009129 "CPU PWM1 enabled\n");
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009130 if (IS_HASWELL(dev_priv))
Rob Clarke2c719b2014-12-15 13:56:32 -05009131 I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE,
Paulo Zanonic5107b82014-07-04 11:50:30 -03009132 "CPU PWM2 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009133 I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009134 "PCH PWM1 enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009135 I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE,
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009136 "Utility pin enabled\n");
Rob Clarke2c719b2014-12-15 13:56:32 -05009137 I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009138
Paulo Zanoni9926ada2014-04-01 19:39:47 -03009139 /*
9140 * In theory we can still leave IRQs enabled, as long as only the HPD
9141 * interrupts remain enabled. We used to check for that, but since it's
9142 * gen-specific and since we only disable LCPLL after we fully disable
9143 * the interrupts, the check below should be enough.
9144 */
Rob Clarke2c719b2014-12-15 13:56:32 -05009145 I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009146}
9147
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009148static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv)
9149{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009150 if (IS_HASWELL(dev_priv))
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009151 return I915_READ(D_COMP_HSW);
9152 else
9153 return I915_READ(D_COMP_BDW);
9154}
9155
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009156static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val)
9157{
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01009158 if (IS_HASWELL(dev_priv)) {
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009159 mutex_lock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009160 if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP,
9161 val))
Chris Wilson79cf2192016-08-24 11:16:07 +01009162 DRM_DEBUG_KMS("Failed to write to D_COMP\n");
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01009163 mutex_unlock(&dev_priv->pcu_lock);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009164 } else {
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009165 I915_WRITE(D_COMP_BDW, val);
9166 POSTING_READ(D_COMP_BDW);
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009167 }
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009168}
9169
9170/*
9171 * This function implements pieces of two sequences from BSpec:
9172 * - Sequence for display software to disable LCPLL
9173 * - Sequence for display software to allow package C8+
9174 * The steps implemented here are just the steps that actually touch the LCPLL
9175 * register. Callers should take care of disabling all the display engine
9176 * functions, doing the mode unset, fixing interrupts, etc.
9177 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009178static void hsw_disable_lcpll(struct drm_i915_private *dev_priv,
9179 bool switch_to_fclk, bool allow_power_down)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009180{
9181 uint32_t val;
9182
9183 assert_can_disable_lcpll(dev_priv);
9184
9185 val = I915_READ(LCPLL_CTL);
9186
9187 if (switch_to_fclk) {
9188 val |= LCPLL_CD_SOURCE_FCLK;
9189 I915_WRITE(LCPLL_CTL, val);
9190
Imre Deakf53dd632016-06-28 13:37:32 +03009191 if (wait_for_us(I915_READ(LCPLL_CTL) &
9192 LCPLL_CD_SOURCE_FCLK_DONE, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009193 DRM_ERROR("Switching to FCLK failed\n");
9194
9195 val = I915_READ(LCPLL_CTL);
9196 }
9197
9198 val |= LCPLL_PLL_DISABLE;
9199 I915_WRITE(LCPLL_CTL, val);
9200 POSTING_READ(LCPLL_CTL);
9201
Chris Wilson24d84412016-06-30 15:33:07 +01009202 if (intel_wait_for_register(dev_priv, LCPLL_CTL, LCPLL_PLL_LOCK, 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009203 DRM_ERROR("LCPLL still locked\n");
9204
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009205 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009206 val |= D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009207 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009208 ndelay(100);
9209
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009210 if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0,
9211 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009212 DRM_ERROR("D_COMP RCOMP still in progress\n");
9213
9214 if (allow_power_down) {
9215 val = I915_READ(LCPLL_CTL);
9216 val |= LCPLL_POWER_DOWN_ALLOW;
9217 I915_WRITE(LCPLL_CTL, val);
9218 POSTING_READ(LCPLL_CTL);
9219 }
9220}
9221
9222/*
9223 * Fully restores LCPLL, disallowing power down and switching back to LCPLL
9224 * source.
9225 */
Paulo Zanoni6ff58d52013-09-24 13:52:57 -03009226static void hsw_restore_lcpll(struct drm_i915_private *dev_priv)
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009227{
9228 uint32_t val;
9229
9230 val = I915_READ(LCPLL_CTL);
9231
9232 if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK |
9233 LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK)
9234 return;
9235
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009236 /*
9237 * Make sure we're not on PC8 state before disabling PC8, otherwise
9238 * we'll hang the machine. To prevent PC8 state, just enable force_wake.
Paulo Zanonia8a8bd52014-03-07 20:08:05 -03009239 */
Mika Kuoppala59bad942015-01-16 11:34:40 +02009240 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Paulo Zanoni215733f2013-08-19 13:18:07 -03009241
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009242 if (val & LCPLL_POWER_DOWN_ALLOW) {
9243 val &= ~LCPLL_POWER_DOWN_ALLOW;
9244 I915_WRITE(LCPLL_CTL, val);
Daniel Vetter35d8f2e2013-08-21 23:38:08 +02009245 POSTING_READ(LCPLL_CTL);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009246 }
9247
Paulo Zanoni9ccd5ae2014-07-04 11:59:58 -03009248 val = hsw_read_dcomp(dev_priv);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009249 val |= D_COMP_COMP_FORCE;
9250 val &= ~D_COMP_COMP_DISABLE;
Paulo Zanoni3c4c9b82014-03-07 20:12:36 -03009251 hsw_write_dcomp(dev_priv, val);
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009252
9253 val = I915_READ(LCPLL_CTL);
9254 val &= ~LCPLL_PLL_DISABLE;
9255 I915_WRITE(LCPLL_CTL, val);
9256
Chris Wilson93220c02016-06-30 15:33:08 +01009257 if (intel_wait_for_register(dev_priv,
9258 LCPLL_CTL, LCPLL_PLL_LOCK, LCPLL_PLL_LOCK,
9259 5))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009260 DRM_ERROR("LCPLL not locked yet\n");
9261
9262 if (val & LCPLL_CD_SOURCE_FCLK) {
9263 val = I915_READ(LCPLL_CTL);
9264 val &= ~LCPLL_CD_SOURCE_FCLK;
9265 I915_WRITE(LCPLL_CTL, val);
9266
Imre Deakf53dd632016-06-28 13:37:32 +03009267 if (wait_for_us((I915_READ(LCPLL_CTL) &
9268 LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1))
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009269 DRM_ERROR("Switching back to LCPLL failed\n");
9270 }
Paulo Zanoni215733f2013-08-19 13:18:07 -03009271
Mika Kuoppala59bad942015-01-16 11:34:40 +02009272 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009273
Ville Syrjälä4c75b942016-10-31 22:37:12 +02009274 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +03009275 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Paulo Zanonibe256dc2013-07-23 11:19:26 -03009276}
9277
Paulo Zanoni765dab672014-03-07 20:08:18 -03009278/*
9279 * Package states C8 and deeper are really deep PC states that can only be
9280 * reached when all the devices on the system allow it, so even if the graphics
9281 * device allows PC8+, it doesn't mean the system will actually get to these
9282 * states. Our driver only allows PC8+ when going into runtime PM.
9283 *
9284 * The requirements for PC8+ are that all the outputs are disabled, the power
9285 * well is disabled and most interrupts are disabled, and these are also
9286 * requirements for runtime PM. When these conditions are met, we manually do
9287 * the other conditions: disable the interrupts, clocks and switch LCPLL refclk
9288 * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard
9289 * hang the machine.
9290 *
9291 * When we really reach PC8 or deeper states (not just when we allow it) we lose
9292 * the state of some registers, so when we come back from PC8+ we need to
9293 * restore this state. We don't get into PC8+ if we're not in RC6, so we don't
9294 * need to take care of the registers kept by RC6. Notice that this happens even
9295 * if we don't put the device in PCI D3 state (which is what currently happens
9296 * because of the runtime PM support).
9297 *
9298 * For more, read "Display Sequences for Package C8" on the hardware
9299 * documentation.
9300 */
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009301void hsw_enable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009302{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009303 uint32_t val;
9304
Paulo Zanonic67a4702013-08-19 13:18:09 -03009305 DRM_DEBUG_KMS("Enabling package C8+\n");
9306
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009307 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009308 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9309 val &= ~PCH_LP_PARTITION_LEVEL_DISABLE;
9310 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9311 }
9312
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009313 lpt_disable_clkout_dp(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009314 hsw_disable_lcpll(dev_priv, true, true);
9315}
9316
Paulo Zanonia14cb6f2014-03-07 20:08:17 -03009317void hsw_disable_pc8(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03009318{
Paulo Zanonic67a4702013-08-19 13:18:09 -03009319 uint32_t val;
9320
Paulo Zanonic67a4702013-08-19 13:18:09 -03009321 DRM_DEBUG_KMS("Disabling package C8+\n");
9322
9323 hsw_restore_lcpll(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +02009324 lpt_init_pch_refclk(dev_priv);
Paulo Zanonic67a4702013-08-19 13:18:09 -03009325
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +01009326 if (HAS_PCH_LPT_LP(dev_priv)) {
Paulo Zanonic67a4702013-08-19 13:18:09 -03009327 val = I915_READ(SOUTH_DSPCLK_GATE_D);
9328 val |= PCH_LP_PARTITION_LEVEL_DISABLE;
9329 I915_WRITE(SOUTH_DSPCLK_GATE_D, val);
9330 }
Paulo Zanonic67a4702013-08-19 13:18:09 -03009331}
9332
Ander Conselvan de Oliveira190f68c2015-01-15 14:55:23 +02009333static int haswell_crtc_compute_clock(struct intel_crtc *crtc,
9334 struct intel_crtc_state *crtc_state)
Paulo Zanoni09b4ddf2012-10-05 12:05:55 -03009335{
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009336 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009337 struct intel_atomic_state *state =
9338 to_intel_atomic_state(crtc_state->base.state);
9339
Madhav Chauhan70a057b2018-11-29 16:12:18 +02009340 if (!intel_crtc_has_type(crtc_state, INTEL_OUTPUT_DSI) ||
9341 IS_ICELAKE(dev_priv)) {
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009342 struct intel_encoder *encoder =
Ville Syrjälä5a0b3852018-05-18 18:29:27 +03009343 intel_get_crtc_new_encoder(state, crtc_state);
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009344
9345 if (!intel_get_shared_dpll(crtc, crtc_state, encoder)) {
Chris Wilson43031782018-09-13 14:16:26 +01009346 DRM_DEBUG_KMS("failed to find PLL for pipe %c\n",
9347 pipe_name(crtc->pipe));
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009348 return -EINVAL;
Paulo Zanoni44a126b2017-03-22 15:58:45 -03009349 }
Mika Kaholaaf3997b2016-02-05 13:29:28 +02009350 }
Daniel Vetter716c2e52014-06-25 22:02:02 +03009351
Daniel Vetterc8f7a0d2014-04-24 23:55:04 +02009352 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009353}
9354
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009355static void cannonlake_get_ddi_pll(struct drm_i915_private *dev_priv,
9356 enum port port,
9357 struct intel_crtc_state *pipe_config)
9358{
9359 enum intel_dpll_id id;
9360 u32 temp;
9361
9362 temp = I915_READ(DPCLKA_CFGCR0) & DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
Paulo Zanonidfbd4502017-08-25 16:40:04 -03009363 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009364
9365 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL2))
9366 return;
9367
9368 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9369}
9370
Paulo Zanoni970888e2018-05-21 17:25:44 -07009371static void icelake_get_ddi_pll(struct drm_i915_private *dev_priv,
9372 enum port port,
9373 struct intel_crtc_state *pipe_config)
9374{
9375 enum intel_dpll_id id;
9376 u32 temp;
9377
9378 /* TODO: TBT pll not implemented. */
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309379 if (intel_port_is_combophy(dev_priv, port)) {
Paulo Zanoni970888e2018-05-21 17:25:44 -07009380 temp = I915_READ(DPCLKA_CFGCR0_ICL) &
9381 DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port);
9382 id = temp >> DPCLKA_CFGCR0_DDI_CLK_SEL_SHIFT(port);
9383
Vandita Kulkarnia54270d2018-10-03 12:52:00 +05309384 if (WARN_ON(!intel_dpll_is_combophy(id)))
Paulo Zanoni970888e2018-05-21 17:25:44 -07009385 return;
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309386 } else if (intel_port_is_tc(dev_priv, port)) {
Vandita Kulkarnicb6caf72018-10-03 12:51:58 +05309387 id = icl_port_to_mg_pll_id(port);
Vandita Kulkarni8ea59e62018-10-03 12:51:59 +05309388 } else {
9389 WARN(1, "Invalid port %x\n", port);
Paulo Zanoni970888e2018-05-21 17:25:44 -07009390 return;
9391 }
9392
9393 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
9394}
9395
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309396static void bxt_get_ddi_pll(struct drm_i915_private *dev_priv,
9397 enum port port,
9398 struct intel_crtc_state *pipe_config)
9399{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009400 enum intel_dpll_id id;
9401
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309402 switch (port) {
9403 case PORT_A:
Imre Deak08250c42016-03-14 19:55:34 +02009404 id = DPLL_ID_SKL_DPLL0;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309405 break;
9406 case PORT_B:
Imre Deak08250c42016-03-14 19:55:34 +02009407 id = DPLL_ID_SKL_DPLL1;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309408 break;
9409 case PORT_C:
Imre Deak08250c42016-03-14 19:55:34 +02009410 id = DPLL_ID_SKL_DPLL2;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309411 break;
9412 default:
9413 DRM_ERROR("Incorrect port type\n");
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009414 return;
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309415 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009416
9417 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309418}
9419
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009420static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv,
9421 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009422 struct intel_crtc_state *pipe_config)
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009423{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009424 enum intel_dpll_id id;
Ander Conselvan de Oliveiraa3c988e2016-03-08 17:46:27 +02009425 u32 temp;
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009426
9427 temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port);
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009428 id = temp >> (port * 3 + 1);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009429
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009430 if (WARN_ON(id < SKL_DPLL0 || id > SKL_DPLL3))
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009431 return;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009432
9433 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009434}
9435
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009436static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv,
9437 enum port port,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009438 struct intel_crtc_state *pipe_config)
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009439{
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009440 enum intel_dpll_id id;
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009441 uint32_t ddi_pll_sel = I915_READ(PORT_CLK_SEL(port));
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009442
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009443 switch (ddi_pll_sel) {
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009444 case PORT_CLK_SEL_WRPLL1:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009445 id = DPLL_ID_WRPLL1;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009446 break;
9447 case PORT_CLK_SEL_WRPLL2:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009448 id = DPLL_ID_WRPLL2;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009449 break;
Maarten Lankhorst00490c22015-11-16 14:42:12 +01009450 case PORT_CLK_SEL_SPLL:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009451 id = DPLL_ID_SPLL;
Ville Syrjälä79bd23d2015-12-01 23:32:07 +02009452 break;
Ander Conselvan de Oliveira9d16da62016-03-08 17:46:26 +02009453 case PORT_CLK_SEL_LCPLL_810:
9454 id = DPLL_ID_LCPLL_810;
9455 break;
9456 case PORT_CLK_SEL_LCPLL_1350:
9457 id = DPLL_ID_LCPLL_1350;
9458 break;
9459 case PORT_CLK_SEL_LCPLL_2700:
9460 id = DPLL_ID_LCPLL_2700;
9461 break;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009462 default:
Ander Conselvan de Oliveirac8560522016-09-01 15:08:07 -07009463 MISSING_CASE(ddi_pll_sel);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009464 /* fall through */
9465 case PORT_CLK_SEL_NONE:
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009466 return;
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009467 }
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009468
9469 pipe_config->shared_dpll = intel_get_shared_dpll_by_id(dev_priv, id);
Damien Lespiau7d2c8172014-07-29 18:06:18 +01009470}
9471
Jani Nikulacf304292016-03-18 17:05:41 +02009472static bool hsw_get_transcoder_state(struct intel_crtc *crtc,
9473 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009474 u64 *power_domain_mask)
Jani Nikulacf304292016-03-18 17:05:41 +02009475{
9476 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009477 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikulacf304292016-03-18 17:05:41 +02009478 enum intel_display_power_domain power_domain;
Jani Nikula07169312018-12-04 12:19:26 +02009479 unsigned long panel_transcoder_mask = BIT(TRANSCODER_EDP);
9480 unsigned long enabled_panel_transcoders = 0;
9481 enum transcoder panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009482 u32 tmp;
Jani Nikula07169312018-12-04 12:19:26 +02009483
9484 if (IS_ICELAKE(dev_priv))
9485 panel_transcoder_mask |=
9486 BIT(TRANSCODER_DSI_0) | BIT(TRANSCODER_DSI_1);
Jani Nikulacf304292016-03-18 17:05:41 +02009487
Imre Deakd9a7bc62016-05-12 16:18:50 +03009488 /*
9489 * The pipe->transcoder mapping is fixed with the exception of the eDP
Jani Nikula07169312018-12-04 12:19:26 +02009490 * and DSI transcoders handled below.
Imre Deakd9a7bc62016-05-12 16:18:50 +03009491 */
Jani Nikulacf304292016-03-18 17:05:41 +02009492 pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe;
9493
9494 /*
9495 * XXX: Do intel_display_power_get_if_enabled before reading this (for
9496 * consistency and less surprising code; it's in always on power).
9497 */
Jani Nikula07169312018-12-04 12:19:26 +02009498 for_each_set_bit(panel_transcoder, &panel_transcoder_mask, 32) {
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009499 enum pipe trans_pipe;
Jani Nikula07169312018-12-04 12:19:26 +02009500
9501 tmp = I915_READ(TRANS_DDI_FUNC_CTL(panel_transcoder));
9502 if (!(tmp & TRANS_DDI_FUNC_ENABLE))
9503 continue;
9504
9505 /*
9506 * Log all enabled ones, only use the first one.
9507 *
9508 * FIXME: This won't work for two separate DSI displays.
9509 */
9510 enabled_panel_transcoders |= BIT(panel_transcoder);
9511 if (enabled_panel_transcoders != BIT(panel_transcoder))
9512 continue;
9513
Jani Nikulacf304292016-03-18 17:05:41 +02009514 switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
9515 default:
Jani Nikula07169312018-12-04 12:19:26 +02009516 WARN(1, "unknown pipe linked to transcoder %s\n",
9517 transcoder_name(panel_transcoder));
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -05009518 /* fall through */
Jani Nikulacf304292016-03-18 17:05:41 +02009519 case TRANS_DDI_EDP_INPUT_A_ONOFF:
9520 case TRANS_DDI_EDP_INPUT_A_ON:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009521 trans_pipe = PIPE_A;
Jani Nikulacf304292016-03-18 17:05:41 +02009522 break;
9523 case TRANS_DDI_EDP_INPUT_B_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009524 trans_pipe = PIPE_B;
Jani Nikulacf304292016-03-18 17:05:41 +02009525 break;
9526 case TRANS_DDI_EDP_INPUT_C_ONOFF:
Madhav Chauhan2ca711c2018-11-29 16:12:27 +02009527 trans_pipe = PIPE_C;
Jani Nikulacf304292016-03-18 17:05:41 +02009528 break;
9529 }
9530
Jani Nikula07169312018-12-04 12:19:26 +02009531 if (trans_pipe == crtc->pipe)
9532 pipe_config->cpu_transcoder = panel_transcoder;
Jani Nikulacf304292016-03-18 17:05:41 +02009533 }
9534
Jani Nikula07169312018-12-04 12:19:26 +02009535 /*
9536 * Valid combos: none, eDP, DSI0, DSI1, DSI0+DSI1
9537 */
9538 WARN_ON((enabled_panel_transcoders & BIT(TRANSCODER_EDP)) &&
9539 enabled_panel_transcoders != BIT(TRANSCODER_EDP));
9540
Jani Nikulacf304292016-03-18 17:05:41 +02009541 power_domain = POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder);
9542 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9543 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009544 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikulacf304292016-03-18 17:05:41 +02009545
9546 tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder));
9547
9548 return tmp & PIPECONF_ENABLE;
9549}
9550
Jani Nikula4d1de972016-03-18 17:05:42 +02009551static bool bxt_get_dsi_transcoder_state(struct intel_crtc *crtc,
9552 struct intel_crtc_state *pipe_config,
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009553 u64 *power_domain_mask)
Jani Nikula4d1de972016-03-18 17:05:42 +02009554{
9555 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01009556 struct drm_i915_private *dev_priv = to_i915(dev);
Jani Nikula4d1de972016-03-18 17:05:42 +02009557 enum intel_display_power_domain power_domain;
9558 enum port port;
9559 enum transcoder cpu_transcoder;
9560 u32 tmp;
9561
Jani Nikula4d1de972016-03-18 17:05:42 +02009562 for_each_port_masked(port, BIT(PORT_A) | BIT(PORT_C)) {
9563 if (port == PORT_A)
9564 cpu_transcoder = TRANSCODER_DSI_A;
9565 else
9566 cpu_transcoder = TRANSCODER_DSI_C;
9567
9568 power_domain = POWER_DOMAIN_TRANSCODER(cpu_transcoder);
9569 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9570 continue;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009571 *power_domain_mask |= BIT_ULL(power_domain);
Jani Nikula4d1de972016-03-18 17:05:42 +02009572
Imre Deakdb18b6a2016-03-24 12:41:40 +02009573 /*
9574 * The PLL needs to be enabled with a valid divider
9575 * configuration, otherwise accessing DSI registers will hang
9576 * the machine. See BSpec North Display Engine
9577 * registers/MIPI[BXT]. We can break out here early, since we
9578 * need the same DSI PLL to be enabled for both DSI ports.
9579 */
Jani Nikulae5186342018-07-05 16:25:08 +03009580 if (!bxt_dsi_pll_is_enabled(dev_priv))
Imre Deakdb18b6a2016-03-24 12:41:40 +02009581 break;
9582
Jani Nikula4d1de972016-03-18 17:05:42 +02009583 /* XXX: this works for video mode only */
9584 tmp = I915_READ(BXT_MIPI_PORT_CTRL(port));
9585 if (!(tmp & DPI_ENABLE))
9586 continue;
9587
9588 tmp = I915_READ(MIPI_CTRL(port));
9589 if ((tmp & BXT_PIPE_SELECT_MASK) != BXT_PIPE_SELECT(crtc->pipe))
9590 continue;
9591
9592 pipe_config->cpu_transcoder = cpu_transcoder;
Jani Nikula4d1de972016-03-18 17:05:42 +02009593 break;
9594 }
9595
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009596 return transcoder_is_dsi(pipe_config->cpu_transcoder);
Jani Nikula4d1de972016-03-18 17:05:42 +02009597}
9598
Daniel Vetter26804af2014-06-25 22:01:55 +03009599static void haswell_get_ddi_port_state(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009600 struct intel_crtc_state *pipe_config)
Daniel Vetter26804af2014-06-25 22:01:55 +03009601{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009602 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009603 struct intel_shared_dpll *pll;
Daniel Vetter26804af2014-06-25 22:01:55 +03009604 enum port port;
9605 uint32_t tmp;
9606
9607 tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder));
9608
9609 port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT;
9610
Paulo Zanoni970888e2018-05-21 17:25:44 -07009611 if (IS_ICELAKE(dev_priv))
9612 icelake_get_ddi_pll(dev_priv, port, pipe_config);
9613 else if (IS_CANNONLAKE(dev_priv))
Kahola, Mika8b0f7e02017-06-09 15:26:03 -07009614 cannonlake_get_ddi_pll(dev_priv, port, pipe_config);
9615 else if (IS_GEN9_BC(dev_priv))
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009616 skylake_get_ddi_pll(dev_priv, port, pipe_config);
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009617 else if (IS_GEN9_LP(dev_priv))
Satheeshakrishna M3760b592014-08-22 09:49:11 +05309618 bxt_get_ddi_pll(dev_priv, port, pipe_config);
Satheeshakrishna M96b7dfb2014-11-13 14:55:17 +00009619 else
9620 haswell_get_ddi_pll(dev_priv, port, pipe_config);
Daniel Vetter9cd86932014-06-25 22:01:57 +03009621
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009622 pll = pipe_config->shared_dpll;
9623 if (pll) {
Lucas De Marchiee1398b2018-03-20 15:06:33 -07009624 WARN_ON(!pll->info->funcs->get_hw_state(dev_priv, pll,
9625 &pipe_config->dpll_hw_state));
Daniel Vetterd452c5b2014-07-04 11:27:39 -03009626 }
9627
Daniel Vetter26804af2014-06-25 22:01:55 +03009628 /*
9629 * Haswell has only FDI/PCH transcoder A. It is which is connected to
9630 * DDI E. So just check whether this pipe is wired to DDI E and whether
9631 * the PCH transcoder is on.
9632 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009633 if (INTEL_GEN(dev_priv) < 9 &&
Damien Lespiauca370452013-12-03 13:56:24 +00009634 (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) {
Daniel Vetter26804af2014-06-25 22:01:55 +03009635 pipe_config->has_pch_encoder = true;
9636
9637 tmp = I915_READ(FDI_RX_CTL(PIPE_A));
9638 pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >>
9639 FDI_DP_PORT_WIDTH_SHIFT) + 1;
9640
9641 ironlake_get_fdi_m_n_config(crtc, pipe_config);
9642 }
9643}
9644
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009645static bool haswell_get_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +02009646 struct intel_crtc_state *pipe_config)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009647{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009648 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Imre Deak17290502016-02-12 18:55:11 +02009649 enum intel_display_power_domain power_domain;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009650 u64 power_domain_mask;
Jani Nikulacf304292016-03-18 17:05:41 +02009651 bool active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009652
Imre Deake79dfb52017-07-20 01:50:57 +03009653 intel_crtc_init_scalers(crtc, pipe_config);
Imre Deak5fb9dad2017-07-20 14:28:20 +03009654
Imre Deak17290502016-02-12 18:55:11 +02009655 power_domain = POWER_DOMAIN_PIPE(crtc->pipe);
9656 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
Imre Deakb5482bd2014-03-05 16:20:55 +02009657 return false;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009658 power_domain_mask = BIT_ULL(power_domain);
Imre Deak17290502016-02-12 18:55:11 +02009659
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +02009660 pipe_config->shared_dpll = NULL;
Daniel Vetterc0d43d62013-06-07 23:11:08 +02009661
Jani Nikulacf304292016-03-18 17:05:41 +02009662 active = hsw_get_transcoder_state(crtc, pipe_config, &power_domain_mask);
Daniel Vettereccb1402013-05-22 00:50:22 +02009663
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02009664 if (IS_GEN9_LP(dev_priv) &&
Ville Syrjäläd7edc4e2016-06-22 21:57:07 +03009665 bxt_get_dsi_transcoder_state(crtc, pipe_config, &power_domain_mask)) {
9666 WARN_ON(active);
9667 active = true;
Jani Nikula4d1de972016-03-18 17:05:42 +02009668 }
9669
Jani Nikulacf304292016-03-18 17:05:41 +02009670 if (!active)
Imre Deak17290502016-02-12 18:55:11 +02009671 goto out;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009672
Madhav Chauhan2eae5d62018-11-29 16:12:28 +02009673 if (!transcoder_is_dsi(pipe_config->cpu_transcoder) ||
9674 IS_ICELAKE(dev_priv)) {
Jani Nikula4d1de972016-03-18 17:05:42 +02009675 haswell_get_ddi_port_state(crtc, pipe_config);
9676 intel_get_pipe_timings(crtc, pipe_config);
9677 }
Daniel Vetter627eb5a2013-04-29 19:33:42 +02009678
Jani Nikulabc58be62016-03-18 17:05:39 +02009679 intel_get_pipe_src_size(crtc, pipe_config);
Shashank Sharma33b7f3e2018-10-12 11:53:08 +05309680 intel_get_crtc_ycbcr_config(crtc, pipe_config);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +02009681
Lionel Landwerlin05dc6982016-03-16 10:57:15 +00009682 pipe_config->gamma_mode =
9683 I915_READ(GAMMA_MODE(crtc->pipe)) & GAMMA_MODE_MODE_MASK;
9684
Imre Deak17290502016-02-12 18:55:11 +02009685 power_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe);
9686 if (intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +02009687 power_domain_mask |= BIT_ULL(power_domain);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +00009688 if (INTEL_GEN(dev_priv) >= 9)
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009689 skylake_get_pfit_config(crtc, pipe_config);
Jesse Barnesff6d9f52015-01-21 17:19:54 -08009690 else
Rodrigo Vivi1c132b42015-09-02 15:19:26 -07009691 ironlake_get_pfit_config(crtc, pipe_config);
Jesse Barnesbd2e2442014-11-13 17:51:47 +00009692 }
Daniel Vetter88adfff2013-03-28 10:42:01 +01009693
Maarten Lankhorst24f28452017-11-22 19:39:01 +01009694 if (hsw_crtc_supports_ips(crtc)) {
9695 if (IS_HASWELL(dev_priv))
9696 pipe_config->ips_enabled = I915_READ(IPS_CTL) & IPS_ENABLE;
9697 else {
9698 /*
9699 * We cannot readout IPS state on broadwell, set to
9700 * true so we can set it to a defined state on first
9701 * commit.
9702 */
9703 pipe_config->ips_enabled = true;
9704 }
9705 }
9706
Jani Nikula4d1de972016-03-18 17:05:42 +02009707 if (pipe_config->cpu_transcoder != TRANSCODER_EDP &&
9708 !transcoder_is_dsi(pipe_config->cpu_transcoder)) {
Clint Taylorebb69c92014-09-30 10:30:22 -07009709 pipe_config->pixel_multiplier =
9710 I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1;
9711 } else {
9712 pipe_config->pixel_multiplier = 1;
9713 }
Daniel Vetter6c49f242013-06-06 12:45:25 +02009714
Imre Deak17290502016-02-12 18:55:11 +02009715out:
9716 for_each_power_domain(power_domain, power_domain_mask)
9717 intel_display_power_put(dev_priv, power_domain);
9718
Jani Nikulacf304292016-03-18 17:05:41 +02009719 return active;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +01009720}
9721
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009722static u32 intel_cursor_base(const struct intel_plane_state *plane_state)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009723{
9724 struct drm_i915_private *dev_priv =
9725 to_i915(plane_state->base.plane->dev);
9726 const struct drm_framebuffer *fb = plane_state->base.fb;
9727 const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
9728 u32 base;
9729
José Roberto de Souzad53db442018-11-30 15:20:48 -08009730 if (INTEL_INFO(dev_priv)->display.cursor_needs_physical)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009731 base = obj->phys_handle->busaddr;
9732 else
9733 base = intel_plane_ggtt_offset(plane_state);
9734
Ville Syrjäläc11ada02018-09-07 18:24:04 +03009735 base += plane_state->color_plane[0].offset;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009736
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009737 /* ILK+ do this automagically */
9738 if (HAS_GMCH_DISPLAY(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +10009739 plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjälä1cecc832017-03-27 21:55:34 +03009740 base += (plane_state->base.crtc_h *
9741 plane_state->base.crtc_w - 1) * fb->format->cpp[0];
9742
9743 return base;
9744}
9745
Ville Syrjäläed270222017-03-27 21:55:36 +03009746static u32 intel_cursor_position(const struct intel_plane_state *plane_state)
9747{
9748 int x = plane_state->base.crtc_x;
9749 int y = plane_state->base.crtc_y;
9750 u32 pos = 0;
9751
9752 if (x < 0) {
9753 pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
9754 x = -x;
9755 }
9756 pos |= x << CURSOR_X_SHIFT;
9757
9758 if (y < 0) {
9759 pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
9760 y = -y;
9761 }
9762 pos |= y << CURSOR_Y_SHIFT;
9763
9764 return pos;
9765}
9766
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009767static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
9768{
9769 const struct drm_mode_config *config =
9770 &plane_state->base.plane->dev->mode_config;
9771 int width = plane_state->base.crtc_w;
9772 int height = plane_state->base.crtc_h;
9773
9774 return width > 0 && width <= config->cursor_width &&
9775 height > 0 && height <= config->cursor_height;
9776}
9777
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009778static int intel_cursor_check_surface(struct intel_plane_state *plane_state)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009779{
9780 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009781 unsigned int rotation = plane_state->base.rotation;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009782 int src_x, src_y;
9783 u32 offset;
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009784 int ret;
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009785
9786 intel_fill_fb_ggtt_view(&plane_state->view, fb, rotation);
9787 plane_state->color_plane[0].stride = intel_fb_pitch(fb, 0, rotation);
9788
Ville Syrjäläfc3fed52018-09-18 17:02:43 +03009789 ret = intel_plane_check_stride(plane_state);
9790 if (ret)
9791 return ret;
9792
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009793 src_x = plane_state->base.src_x >> 16;
9794 src_y = plane_state->base.src_y >> 16;
9795
9796 intel_add_fb_offsets(&src_x, &src_y, plane_state, 0);
9797 offset = intel_plane_compute_aligned_offset(&src_x, &src_y,
9798 plane_state, 0);
9799
9800 if (src_x != 0 || src_y != 0) {
9801 DRM_DEBUG_KMS("Arbitrary cursor panning not supported\n");
9802 return -EINVAL;
9803 }
9804
9805 plane_state->color_plane[0].offset = offset;
9806
9807 return 0;
9808}
9809
9810static int intel_check_cursor(struct intel_crtc_state *crtc_state,
9811 struct intel_plane_state *plane_state)
9812{
9813 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009814 int ret;
9815
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009816 if (fb && fb->modifier != DRM_FORMAT_MOD_LINEAR) {
9817 DRM_DEBUG_KMS("cursor cannot be tiled\n");
9818 return -EINVAL;
9819 }
9820
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009821 ret = drm_atomic_helper_check_plane_state(&plane_state->base,
9822 &crtc_state->base,
Ville Syrjäläa01cb8b2017-11-01 22:16:19 +02009823 DRM_PLANE_HELPER_NO_SCALING,
9824 DRM_PLANE_HELPER_NO_SCALING,
9825 true, true);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009826 if (ret)
9827 return ret;
9828
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009829 if (!plane_state->base.visible)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009830 return 0;
9831
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +03009832 ret = intel_plane_check_src_coordinates(plane_state);
9833 if (ret)
9834 return ret;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009835
Ville Syrjäläfce8d232018-09-07 18:24:13 +03009836 ret = intel_cursor_check_surface(plane_state);
9837 if (ret)
9838 return ret;
Ville Syrjälä1e7b4fd2017-03-27 21:55:44 +03009839
Ville Syrjälä659056f2017-03-27 21:55:39 +03009840 return 0;
9841}
9842
Ville Syrjäläddd57132018-09-07 18:24:02 +03009843static unsigned int
9844i845_cursor_max_stride(struct intel_plane *plane,
9845 u32 pixel_format, u64 modifier,
9846 unsigned int rotation)
9847{
9848 return 2048;
9849}
9850
Ville Syrjälä292889e2017-03-17 23:18:01 +02009851static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
9852 const struct intel_plane_state *plane_state)
9853{
Ville Syrjälä292889e2017-03-17 23:18:01 +02009854 return CURSOR_ENABLE |
9855 CURSOR_GAMMA_ENABLE |
9856 CURSOR_FORMAT_ARGB |
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009857 CURSOR_STRIDE(plane_state->color_plane[0].stride);
Ville Syrjälä292889e2017-03-17 23:18:01 +02009858}
9859
Ville Syrjälä659056f2017-03-27 21:55:39 +03009860static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
9861{
Ville Syrjälä659056f2017-03-27 21:55:39 +03009862 int width = plane_state->base.crtc_w;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009863
9864 /*
9865 * 845g/865g are only limited by the width of their cursors,
9866 * the height is arbitrary up to the precision of the register.
9867 */
Ville Syrjälä3637ecf2017-03-27 21:55:40 +03009868 return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
Ville Syrjälä659056f2017-03-27 21:55:39 +03009869}
9870
Ville Syrjäläeb0f5042018-08-28 17:27:06 +03009871static int i845_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +03009872 struct intel_plane_state *plane_state)
9873{
9874 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +03009875 int ret;
9876
9877 ret = intel_check_cursor(crtc_state, plane_state);
9878 if (ret)
9879 return ret;
9880
9881 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009882 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +03009883 return 0;
9884
9885 /* Check for which cursor types we support */
9886 if (!i845_cursor_size_ok(plane_state)) {
9887 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
9888 plane_state->base.crtc_w,
9889 plane_state->base.crtc_h);
9890 return -EINVAL;
9891 }
9892
Ville Syrjälädf79cf42018-09-11 18:01:39 +03009893 WARN_ON(plane_state->base.visible &&
9894 plane_state->color_plane[0].stride != fb->pitches[0]);
9895
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009896 switch (fb->pitches[0]) {
Chris Wilson560b85b2010-08-07 11:01:38 +01009897 case 256:
9898 case 512:
9899 case 1024:
9900 case 2048:
Ville Syrjälädc41c152014-08-13 11:57:05 +03009901 break;
Ville Syrjälä1e1bb872017-03-27 21:55:41 +03009902 default:
9903 DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
9904 fb->pitches[0]);
9905 return -EINVAL;
Chris Wilson560b85b2010-08-07 11:01:38 +01009906 }
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009907
Ville Syrjälä659056f2017-03-27 21:55:39 +03009908 plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
9909
9910 return 0;
Jesse Barnes79e53942008-11-07 14:24:08 -08009911}
9912
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009913static void i845_update_cursor(struct intel_plane *plane,
9914 const struct intel_crtc_state *crtc_state,
Chris Wilson560b85b2010-08-07 11:01:38 +01009915 const struct intel_plane_state *plane_state)
9916{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +03009917 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009918 u32 cntl = 0, base = 0, pos = 0, size = 0;
9919 unsigned long irqflags;
Chris Wilson560b85b2010-08-07 11:01:38 +01009920
Ville Syrjälä936e71e2016-07-26 19:06:59 +03009921 if (plane_state && plane_state->base.visible) {
Maarten Lankhorst55a08b3f2016-01-07 11:54:10 +01009922 unsigned int width = plane_state->base.crtc_w;
9923 unsigned int height = plane_state->base.crtc_h;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009924
Ville Syrjäläa0864d52017-03-23 21:27:09 +02009925 cntl = plane_state->ctl;
Ville Syrjälädc41c152014-08-13 11:57:05 +03009926 size = (height << 12) | width;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009927
9928 base = intel_cursor_base(plane_state);
9929 pos = intel_cursor_position(plane_state);
Chris Wilson4b0e3332014-05-30 16:35:26 +03009930 }
Chris Wilson560b85b2010-08-07 11:01:38 +01009931
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009932 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
9933
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009934 /* On these chipsets we can only modify the base/size/stride
9935 * whilst the cursor is disabled.
9936 */
9937 if (plane->cursor.base != base ||
9938 plane->cursor.size != size ||
9939 plane->cursor.cntl != cntl) {
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009940 I915_WRITE_FW(CURCNTR(PIPE_A), 0);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009941 I915_WRITE_FW(CURBASE(PIPE_A), base);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009942 I915_WRITE_FW(CURSIZE, size);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009943 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädd584fc2017-03-09 17:44:33 +02009944 I915_WRITE_FW(CURCNTR(PIPE_A), cntl);
Ville Syrjälä75343a42017-03-27 21:55:38 +03009945
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +03009946 plane->cursor.base = base;
9947 plane->cursor.size = size;
9948 plane->cursor.cntl = cntl;
9949 } else {
9950 I915_WRITE_FW(CURPOS(PIPE_A), pos);
Ville Syrjälädc41c152014-08-13 11:57:05 +03009951 }
9952
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009953 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
9954}
9955
9956static void i845_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02009957 const struct intel_crtc_state *crtc_state)
Ville Syrjäläb2d03b02017-03-27 21:55:37 +03009958{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +02009959 i845_update_cursor(plane, crtc_state, NULL);
Chris Wilson560b85b2010-08-07 11:01:38 +01009960}
9961
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009962static bool i845_cursor_get_hw_state(struct intel_plane *plane,
9963 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009964{
9965 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
9966 enum intel_display_power_domain power_domain;
9967 bool ret;
9968
9969 power_domain = POWER_DOMAIN_PIPE(PIPE_A);
9970 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
9971 return false;
9972
9973 ret = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
9974
Ville Syrjäläeade6c82018-01-30 22:38:03 +02009975 *pipe = PIPE_A;
9976
Ville Syrjälä51f5a0962017-11-17 21:19:08 +02009977 intel_display_power_put(dev_priv, power_domain);
9978
9979 return ret;
9980}
9981
Ville Syrjäläddd57132018-09-07 18:24:02 +03009982static unsigned int
9983i9xx_cursor_max_stride(struct intel_plane *plane,
9984 u32 pixel_format, u64 modifier,
9985 unsigned int rotation)
9986{
9987 return plane->base.dev->mode_config.cursor_width * 4;
9988}
9989
Ville Syrjälä292889e2017-03-17 23:18:01 +02009990static u32 i9xx_cursor_ctl(const struct intel_crtc_state *crtc_state,
9991 const struct intel_plane_state *plane_state)
9992{
9993 struct drm_i915_private *dev_priv =
9994 to_i915(plane_state->base.plane->dev);
9995 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
José Roberto de Souzac894d632018-05-18 13:15:47 -07009996 u32 cntl = 0;
Ville Syrjälä292889e2017-03-17 23:18:01 +02009997
Lucas De Marchicf819ef2018-12-12 10:10:43 -08009998 if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv))
Ville Syrjäläe876b782018-01-30 22:38:05 +02009999 cntl |= MCURSOR_TRICKLE_FEED_DISABLE;
10000
José Roberto de Souzac894d632018-05-18 13:15:47 -070010001 if (INTEL_GEN(dev_priv) <= 10) {
10002 cntl |= MCURSOR_GAMMA_ENABLE;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010003
José Roberto de Souzac894d632018-05-18 13:15:47 -070010004 if (HAS_DDI(dev_priv))
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010005 cntl |= MCURSOR_PIPE_CSC_ENABLE;
José Roberto de Souzac894d632018-05-18 13:15:47 -070010006 }
Ville Syrjälä292889e2017-03-17 23:18:01 +020010007
Ville Syrjälä32ea06b2018-01-30 22:38:01 +020010008 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
10009 cntl |= MCURSOR_PIPE_SELECT(crtc->pipe);
Ville Syrjälä292889e2017-03-17 23:18:01 +020010010
10011 switch (plane_state->base.crtc_w) {
10012 case 64:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010013 cntl |= MCURSOR_MODE_64_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010014 break;
10015 case 128:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010016 cntl |= MCURSOR_MODE_128_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010017 break;
10018 case 256:
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010019 cntl |= MCURSOR_MODE_256_ARGB_AX;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010020 break;
10021 default:
10022 MISSING_CASE(plane_state->base.crtc_w);
10023 return 0;
10024 }
10025
Robert Fossc2c446a2017-05-19 16:50:17 -040010026 if (plane_state->base.rotation & DRM_MODE_ROTATE_180)
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010027 cntl |= MCURSOR_ROTATE_180;
Ville Syrjälä292889e2017-03-17 23:18:01 +020010028
10029 return cntl;
10030}
10031
Ville Syrjälä659056f2017-03-27 21:55:39 +030010032static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
Chris Wilson560b85b2010-08-07 11:01:38 +010010033{
Ville Syrjälä024faac2017-03-27 21:55:42 +030010034 struct drm_i915_private *dev_priv =
10035 to_i915(plane_state->base.plane->dev);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010036 int width = plane_state->base.crtc_w;
10037 int height = plane_state->base.crtc_h;
Chris Wilson560b85b2010-08-07 11:01:38 +010010038
Ville Syrjälä3637ecf2017-03-27 21:55:40 +030010039 if (!intel_cursor_size_ok(plane_state))
Ville Syrjälädc41c152014-08-13 11:57:05 +030010040 return false;
10041
Ville Syrjälä024faac2017-03-27 21:55:42 +030010042 /* Cursor width is limited to a few power-of-two sizes */
10043 switch (width) {
Ville Syrjälä659056f2017-03-27 21:55:39 +030010044 case 256:
10045 case 128:
Ville Syrjälä659056f2017-03-27 21:55:39 +030010046 case 64:
10047 break;
10048 default:
10049 return false;
10050 }
10051
Ville Syrjälädc41c152014-08-13 11:57:05 +030010052 /*
Ville Syrjälä024faac2017-03-27 21:55:42 +030010053 * IVB+ have CUR_FBC_CTL which allows an arbitrary cursor
10054 * height from 8 lines up to the cursor width, when the
10055 * cursor is not rotated. Everything else requires square
10056 * cursors.
Ville Syrjälädc41c152014-08-13 11:57:05 +030010057 */
Ville Syrjälä024faac2017-03-27 21:55:42 +030010058 if (HAS_CUR_FBC(dev_priv) &&
Dave Airliea82256b2017-05-30 15:25:28 +100010059 plane_state->base.rotation & DRM_MODE_ROTATE_0) {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010060 if (height < 8 || height > width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010061 return false;
10062 } else {
Ville Syrjälä024faac2017-03-27 21:55:42 +030010063 if (height != width)
Ville Syrjälädc41c152014-08-13 11:57:05 +030010064 return false;
Ville Syrjälädc41c152014-08-13 11:57:05 +030010065 }
10066
10067 return true;
10068}
10069
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010070static int i9xx_check_cursor(struct intel_crtc_state *crtc_state,
Ville Syrjälä659056f2017-03-27 21:55:39 +030010071 struct intel_plane_state *plane_state)
10072{
Ville Syrjäläeb0f5042018-08-28 17:27:06 +030010073 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
Ville Syrjälä659056f2017-03-27 21:55:39 +030010074 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10075 const struct drm_framebuffer *fb = plane_state->base.fb;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010076 enum pipe pipe = plane->pipe;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010077 int ret;
10078
10079 ret = intel_check_cursor(crtc_state, plane_state);
10080 if (ret)
10081 return ret;
10082
10083 /* if we want to turn off the cursor ignore width and height */
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010084 if (!fb)
Ville Syrjälä659056f2017-03-27 21:55:39 +030010085 return 0;
10086
10087 /* Check for which cursor types we support */
10088 if (!i9xx_cursor_size_ok(plane_state)) {
10089 DRM_DEBUG("Cursor dimension %dx%d not supported\n",
10090 plane_state->base.crtc_w,
10091 plane_state->base.crtc_h);
10092 return -EINVAL;
10093 }
10094
Ville Syrjälädf79cf42018-09-11 18:01:39 +030010095 WARN_ON(plane_state->base.visible &&
10096 plane_state->color_plane[0].stride != fb->pitches[0]);
10097
Ville Syrjälä1e1bb872017-03-27 21:55:41 +030010098 if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
10099 DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
10100 fb->pitches[0], plane_state->base.crtc_w);
10101 return -EINVAL;
Ville Syrjälä659056f2017-03-27 21:55:39 +030010102 }
10103
10104 /*
10105 * There's something wrong with the cursor on CHV pipe C.
10106 * If it straddles the left edge of the screen then
10107 * moving it away from the edge or disabling it often
10108 * results in a pipe underrun, and often that can lead to
10109 * dead pipe (constant underrun reported, and it scans
10110 * out just a solid color). To recover from that, the
10111 * display power well must be turned off and on again.
10112 * Refuse the put the cursor into that compromised position.
10113 */
10114 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_C &&
10115 plane_state->base.visible && plane_state->base.crtc_x < 0) {
10116 DRM_DEBUG_KMS("CHV cursor C not allowed to straddle the left screen edge\n");
10117 return -EINVAL;
10118 }
10119
10120 plane_state->ctl = i9xx_cursor_ctl(crtc_state, plane_state);
10121
10122 return 0;
10123}
10124
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010125static void i9xx_update_cursor(struct intel_plane *plane,
10126 const struct intel_crtc_state *crtc_state,
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010127 const struct intel_plane_state *plane_state)
10128{
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030010129 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10130 enum pipe pipe = plane->pipe;
Ville Syrjälä024faac2017-03-27 21:55:42 +030010131 u32 cntl = 0, base = 0, pos = 0, fbc_ctl = 0;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010132 unsigned long irqflags;
Sagar Kamble4726e0b2014-03-10 17:06:23 +053010133
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010134 if (plane_state && plane_state->base.visible) {
Ville Syrjäläa0864d52017-03-23 21:27:09 +020010135 cntl = plane_state->ctl;
Chris Wilson4b0e3332014-05-30 16:35:26 +030010136
Ville Syrjälä024faac2017-03-27 21:55:42 +030010137 if (plane_state->base.crtc_h != plane_state->base.crtc_w)
10138 fbc_ctl = CUR_FBC_CTL_EN | (plane_state->base.crtc_h - 1);
10139
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010140 base = intel_cursor_base(plane_state);
10141 pos = intel_cursor_position(plane_state);
10142 }
10143
10144 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
10145
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010146 /*
10147 * On some platforms writing CURCNTR first will also
10148 * cause CURPOS to be armed by the CURBASE write.
10149 * Without the CURCNTR write the CURPOS write would
Ville Syrjälä83234d12018-11-14 23:07:17 +020010150 * arm itself. Thus we always update CURCNTR before
10151 * CURPOS.
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010152 *
10153 * On other platforms CURPOS always requires the
10154 * CURBASE write to arm the update. Additonally
10155 * a write to any of the cursor register will cancel
10156 * an already armed cursor update. Thus leaving out
10157 * the CURBASE write after CURPOS could lead to a
10158 * cursor that doesn't appear to move, or even change
10159 * shape. Thus we always write CURBASE.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010160 *
Ville Syrjälä83234d12018-11-14 23:07:17 +020010161 * The other registers are armed by by the CURBASE write
10162 * except when the plane is getting enabled at which time
10163 * the CURCNTR write arms the update.
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010164 */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020010165
10166 if (INTEL_GEN(dev_priv) >= 9)
10167 skl_write_cursor_wm(plane, crtc_state);
10168
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010169 if (plane->cursor.base != base ||
Ville Syrjälä024faac2017-03-27 21:55:42 +030010170 plane->cursor.size != fbc_ctl ||
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010171 plane->cursor.cntl != cntl) {
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010172 if (HAS_CUR_FBC(dev_priv))
10173 I915_WRITE_FW(CUR_FBC_CTL(pipe), fbc_ctl);
Ville Syrjälä83234d12018-11-14 23:07:17 +020010174 I915_WRITE_FW(CURCNTR(pipe), cntl);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010175 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä75343a42017-03-27 21:55:38 +030010176 I915_WRITE_FW(CURBASE(pipe), base);
10177
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010178 plane->cursor.base = base;
10179 plane->cursor.size = fbc_ctl;
10180 plane->cursor.cntl = cntl;
10181 } else {
10182 I915_WRITE_FW(CURPOS(pipe), pos);
Ville Syrjälä8753d2b2017-07-14 18:52:27 +030010183 I915_WRITE_FW(CURBASE(pipe), base);
Ville Syrjäläe11ffdd2017-03-27 21:55:46 +030010184 }
10185
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010186 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
Jesse Barnes65a21cd2011-10-12 11:10:21 -070010187}
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030010188
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030010189static void i9xx_disable_cursor(struct intel_plane *plane,
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010190 const struct intel_crtc_state *crtc_state)
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010191{
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020010192 i9xx_update_cursor(plane, crtc_state, NULL);
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010193}
Ville Syrjäläd6e4db12013-09-04 18:25:31 +030010194
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010195static bool i9xx_cursor_get_hw_state(struct intel_plane *plane,
10196 enum pipe *pipe)
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010197{
10198 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
10199 enum intel_display_power_domain power_domain;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010200 bool ret;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010201 u32 val;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010202
10203 /*
10204 * Not 100% correct for planes that can move between pipes,
10205 * but that's only the case for gen2-3 which don't have any
10206 * display power wells.
10207 */
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010208 power_domain = POWER_DOMAIN_PIPE(plane->pipe);
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010209 if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
10210 return false;
10211
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010212 val = I915_READ(CURCNTR(plane->pipe));
10213
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020010214 ret = val & MCURSOR_MODE;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020010215
10216 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
10217 *pipe = plane->pipe;
10218 else
10219 *pipe = (val & MCURSOR_PIPE_SELECT_MASK) >>
10220 MCURSOR_PIPE_SELECT_SHIFT;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020010221
10222 intel_display_power_put(dev_priv, power_domain);
10223
10224 return ret;
10225}
Chris Wilsoncda4b7d2010-07-09 08:45:04 +010010226
Jesse Barnes79e53942008-11-07 14:24:08 -080010227/* VESA 640x480x72Hz mode to set on the pipe */
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010228static const struct drm_display_mode load_detect_mode = {
Jesse Barnes79e53942008-11-07 14:24:08 -080010229 DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
10230 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
10231};
10232
Daniel Vettera8bb6812014-02-10 18:00:39 +010010233struct drm_framebuffer *
Chris Wilson24dbf512017-02-15 10:59:18 +000010234intel_framebuffer_create(struct drm_i915_gem_object *obj,
10235 struct drm_mode_fb_cmd2 *mode_cmd)
Chris Wilsond2dff872011-04-19 08:36:26 +010010236{
10237 struct intel_framebuffer *intel_fb;
10238 int ret;
10239
10240 intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010241 if (!intel_fb)
Chris Wilsond2dff872011-04-19 08:36:26 +010010242 return ERR_PTR(-ENOMEM);
Chris Wilsond2dff872011-04-19 08:36:26 +010010243
Chris Wilson24dbf512017-02-15 10:59:18 +000010244 ret = intel_framebuffer_init(intel_fb, obj, mode_cmd);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010245 if (ret)
10246 goto err;
Chris Wilsond2dff872011-04-19 08:36:26 +010010247
10248 return &intel_fb->base;
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010249
Lukas Wunnerdcb13942015-07-04 11:50:58 +020010250err:
10251 kfree(intel_fb);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020010252 return ERR_PTR(ret);
Chris Wilsond2dff872011-04-19 08:36:26 +010010253}
10254
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010255static int intel_modeset_disable_planes(struct drm_atomic_state *state,
10256 struct drm_crtc *crtc)
Chris Wilsond2dff872011-04-19 08:36:26 +010010257{
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010258 struct drm_plane *plane;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010259 struct drm_plane_state *plane_state;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010260 int ret, i;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010261
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010262 ret = drm_atomic_add_affected_planes(state, crtc);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010263 if (ret)
10264 return ret;
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010265
10266 for_each_new_plane_in_state(state, plane, plane_state, i) {
10267 if (plane_state->crtc != crtc)
10268 continue;
10269
10270 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
10271 if (ret)
10272 return ret;
10273
10274 drm_atomic_set_fb_for_plane(plane_state, NULL);
10275 }
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010276
10277 return 0;
10278}
10279
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010280int intel_get_load_detect_pipe(struct drm_connector *connector,
Ville Syrjäläbacdcd52017-05-18 22:38:37 +030010281 const struct drm_display_mode *mode,
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010282 struct intel_load_detect_pipe *old,
10283 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010284{
10285 struct intel_crtc *intel_crtc;
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010286 struct intel_encoder *intel_encoder =
10287 intel_attached_encoder(connector);
Jesse Barnes79e53942008-11-07 14:24:08 -080010288 struct drm_crtc *possible_crtc;
Chris Wilson4ef69c72010-09-09 15:14:28 +010010289 struct drm_encoder *encoder = &intel_encoder->base;
Jesse Barnes79e53942008-11-07 14:24:08 -080010290 struct drm_crtc *crtc = NULL;
10291 struct drm_device *dev = encoder->dev;
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010292 struct drm_i915_private *dev_priv = to_i915(dev);
Rob Clark51fd3712013-11-19 12:10:12 -050010293 struct drm_mode_config *config = &dev->mode_config;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010294 struct drm_atomic_state *state = NULL, *restore_state = NULL;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010295 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010296 struct intel_crtc_state *crtc_state;
Rob Clark51fd3712013-11-19 12:10:12 -050010297 int ret, i = -1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010298
Chris Wilsond2dff872011-04-19 08:36:26 +010010299 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010300 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010301 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010302
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010303 old->restore_state = NULL;
10304
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010305 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +020010306
Jesse Barnes79e53942008-11-07 14:24:08 -080010307 /*
10308 * Algorithm gets a little messy:
Chris Wilson7a5e4802011-04-19 23:21:12 +010010309 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010310 * - if the connector already has an assigned crtc, use it (but make
10311 * sure it's on first)
Chris Wilson7a5e4802011-04-19 23:21:12 +010010312 *
Jesse Barnes79e53942008-11-07 14:24:08 -080010313 * - try to find the first unused crtc that can drive this connector,
10314 * and use that if we find one
Jesse Barnes79e53942008-11-07 14:24:08 -080010315 */
10316
10317 /* See if we already have a CRTC for this connector */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010318 if (connector->state->crtc) {
10319 crtc = connector->state->crtc;
Chris Wilson8261b192011-04-19 23:18:09 +010010320
Rob Clark51fd3712013-11-19 12:10:12 -050010321 ret = drm_modeset_lock(&crtc->mutex, ctx);
10322 if (ret)
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010323 goto fail;
Chris Wilson8261b192011-04-19 23:18:09 +010010324
10325 /* Make sure the crtc and connector are running */
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010326 goto found;
Jesse Barnes79e53942008-11-07 14:24:08 -080010327 }
10328
10329 /* Find an unused one (if possible) */
Damien Lespiau70e1e0e2014-05-13 23:32:24 +010010330 for_each_crtc(dev, possible_crtc) {
Jesse Barnes79e53942008-11-07 14:24:08 -080010331 i++;
10332 if (!(encoder->possible_crtcs & (1 << i)))
10333 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010334
10335 ret = drm_modeset_lock(&possible_crtc->mutex, ctx);
10336 if (ret)
10337 goto fail;
10338
10339 if (possible_crtc->state->enable) {
10340 drm_modeset_unlock(&possible_crtc->mutex);
Ville Syrjäläa4592492014-08-11 13:15:36 +030010341 continue;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010342 }
Ville Syrjäläa4592492014-08-11 13:15:36 +030010343
10344 crtc = possible_crtc;
10345 break;
Jesse Barnes79e53942008-11-07 14:24:08 -080010346 }
10347
10348 /*
10349 * If we didn't find an unused CRTC, don't use any.
10350 */
10351 if (!crtc) {
Chris Wilson71731882011-04-19 23:10:58 +010010352 DRM_DEBUG_KMS("no pipe available for load-detect\n");
Dan Carpenterf4bf77b2017-04-14 22:54:25 +030010353 ret = -ENODEV;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010354 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010355 }
10356
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010357found:
10358 intel_crtc = to_intel_crtc(crtc);
10359
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010360 state = drm_atomic_state_alloc(dev);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010361 restore_state = drm_atomic_state_alloc(dev);
10362 if (!state || !restore_state) {
10363 ret = -ENOMEM;
10364 goto fail;
10365 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010366
10367 state->acquire_ctx = ctx;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010368 restore_state->acquire_ctx = ctx;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010369
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010370 connector_state = drm_atomic_get_connector_state(state, connector);
10371 if (IS_ERR(connector_state)) {
10372 ret = PTR_ERR(connector_state);
10373 goto fail;
10374 }
10375
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010376 ret = drm_atomic_set_crtc_for_connector(connector_state, crtc);
10377 if (ret)
10378 goto fail;
Ander Conselvan de Oliveira944b0c72015-03-20 16:18:07 +020010379
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010380 crtc_state = intel_atomic_get_crtc_state(state, intel_crtc);
10381 if (IS_ERR(crtc_state)) {
10382 ret = PTR_ERR(crtc_state);
10383 goto fail;
10384 }
10385
Maarten Lankhorst49d6fa22015-05-11 10:45:15 +020010386 crtc_state->base.active = crtc_state->base.enable = true;
Ander Conselvan de Oliveira4be07312015-04-21 17:13:01 +030010387
Chris Wilson64927112011-04-20 07:25:26 +010010388 if (!mode)
10389 mode = &load_detect_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -080010390
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010391 ret = drm_atomic_set_mode_for_crtc(&crtc_state->base, mode);
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010392 if (ret)
10393 goto fail;
10394
Ville Syrjälä20bdc112017-12-20 10:35:45 +010010395 ret = intel_modeset_disable_planes(state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010396 if (ret)
10397 goto fail;
10398
10399 ret = PTR_ERR_OR_ZERO(drm_atomic_get_connector_state(restore_state, connector));
10400 if (!ret)
10401 ret = PTR_ERR_OR_ZERO(drm_atomic_get_crtc_state(restore_state, crtc));
Ville Syrjäläbe90cc32018-03-22 17:23:12 +020010402 if (!ret)
10403 ret = drm_atomic_add_affected_planes(restore_state, crtc);
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010404 if (ret) {
10405 DRM_DEBUG_KMS("Failed to create a copy of old state to restore: %i\n", ret);
10406 goto fail;
10407 }
Ander Conselvan de Oliveira8c7b5cc2015-04-21 17:13:19 +030010408
Maarten Lankhorst3ba86072016-02-29 09:18:57 +010010409 ret = drm_atomic_commit(state);
10410 if (ret) {
Chris Wilson64927112011-04-20 07:25:26 +010010411 DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010412 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080010413 }
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010414
10415 old->restore_state = restore_state;
Chris Wilson7abbd112017-01-19 11:37:49 +000010416 drm_atomic_state_put(state);
Chris Wilson71731882011-04-19 23:10:58 +010010417
Jesse Barnes79e53942008-11-07 14:24:08 -080010418 /* let the connector get through one full cycle before testing */
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020010419 intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
Chris Wilson71731882011-04-19 23:10:58 +010010420 return true;
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010421
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020010422fail:
Chris Wilson7fb71c82016-10-19 12:37:43 +010010423 if (state) {
10424 drm_atomic_state_put(state);
10425 state = NULL;
10426 }
10427 if (restore_state) {
10428 drm_atomic_state_put(restore_state);
10429 restore_state = NULL;
10430 }
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020010431
Maarten Lankhorst6c5ed5a2017-04-06 20:55:20 +020010432 if (ret == -EDEADLK)
10433 return ret;
Rob Clark51fd3712013-11-19 12:10:12 -050010434
Ville Syrjälä412b61d2014-01-17 15:59:39 +020010435 return false;
Jesse Barnes79e53942008-11-07 14:24:08 -080010436}
10437
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010438void intel_release_load_detect_pipe(struct drm_connector *connector,
Ander Conselvan de Oliveira49172fe2015-03-20 16:18:02 +020010439 struct intel_load_detect_pipe *old,
10440 struct drm_modeset_acquire_ctx *ctx)
Jesse Barnes79e53942008-11-07 14:24:08 -080010441{
Daniel Vetterd2434ab2012-08-12 21:20:10 +020010442 struct intel_encoder *intel_encoder =
10443 intel_attached_encoder(connector);
Chris Wilson4ef69c72010-09-09 15:14:28 +010010444 struct drm_encoder *encoder = &intel_encoder->base;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010445 struct drm_atomic_state *state = old->restore_state;
Ander Conselvan de Oliveirad3a40d12015-04-21 17:13:09 +030010446 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080010447
Chris Wilsond2dff872011-04-19 08:36:26 +010010448 DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
Jani Nikulac23cc412014-06-03 14:56:17 +030010449 connector->base.id, connector->name,
Jani Nikula8e329a032014-06-03 14:56:21 +030010450 encoder->base.id, encoder->name);
Chris Wilsond2dff872011-04-19 08:36:26 +010010451
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010452 if (!state)
Chris Wilson0622a532011-04-21 09:32:11 +010010453 return;
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010454
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010010455 ret = drm_atomic_helper_commit_duplicated_state(state, ctx);
Chris Wilson08536952016-10-14 13:18:18 +010010456 if (ret)
Maarten Lankhorstedde3612016-02-17 09:18:35 +010010457 DRM_DEBUG_KMS("Couldn't release load detect pipe: %i\n", ret);
Chris Wilson08536952016-10-14 13:18:18 +010010458 drm_atomic_state_put(state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010459}
10460
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010461static int i9xx_pll_refclk(struct drm_device *dev,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010462 const struct intel_crtc_state *pipe_config)
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010463{
Chris Wilsonfac5e232016-07-04 11:34:36 +010010464 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010465 u32 dpll = pipe_config->dpll_hw_state.dpll;
10466
10467 if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN)
Ville Syrjäläe91e9412013-12-09 18:54:16 +020010468 return dev_priv->vbt.lvds_ssc_freq;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010010469 else if (HAS_PCH_SPLIT(dev_priv))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010470 return 120000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010471 else if (!IS_GEN(dev_priv, 2))
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010472 return 96000;
10473 else
10474 return 48000;
10475}
10476
Jesse Barnes79e53942008-11-07 14:24:08 -080010477/* Returns the clock of the currently programmed mode of the given pipe. */
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010478static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010479 struct intel_crtc_state *pipe_config)
Jesse Barnes79e53942008-11-07 14:24:08 -080010480{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010481 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010010482 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010483 int pipe = pipe_config->cpu_transcoder;
Ville Syrjälä293623f2013-09-13 16:18:46 +030010484 u32 dpll = pipe_config->dpll_hw_state.dpll;
Jesse Barnes79e53942008-11-07 14:24:08 -080010485 u32 fp;
Ander Conselvan de Oliveira9e2c8472016-05-04 12:11:57 +030010486 struct dpll clock;
Imre Deakdccbea32015-06-22 23:35:51 +030010487 int port_clock;
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010488 int refclk = i9xx_pll_refclk(dev, pipe_config);
Jesse Barnes79e53942008-11-07 14:24:08 -080010489
10490 if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
Ville Syrjälä293623f2013-09-13 16:18:46 +030010491 fp = pipe_config->dpll_hw_state.fp0;
Jesse Barnes79e53942008-11-07 14:24:08 -080010492 else
Ville Syrjälä293623f2013-09-13 16:18:46 +030010493 fp = pipe_config->dpll_hw_state.fp1;
Jesse Barnes79e53942008-11-07 14:24:08 -080010494
10495 clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010496 if (IS_PINEVIEW(dev_priv)) {
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010497 clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
10498 clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
Shaohua Li21778322009-02-23 15:19:16 +080010499 } else {
10500 clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
10501 clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
10502 }
10503
Lucas De Marchicf819ef2018-12-12 10:10:43 -080010504 if (!IS_GEN(dev_priv, 2)) {
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010505 if (IS_PINEVIEW(dev_priv))
Adam Jacksonf2b115e2009-12-03 17:14:42 -050010506 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
10507 DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
Shaohua Li21778322009-02-23 15:19:16 +080010508 else
10509 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
Jesse Barnes79e53942008-11-07 14:24:08 -080010510 DPLL_FPA01_P1_POST_DIV_SHIFT);
10511
10512 switch (dpll & DPLL_MODE_MASK) {
10513 case DPLLB_MODE_DAC_SERIAL:
10514 clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
10515 5 : 10;
10516 break;
10517 case DPLLB_MODE_LVDS:
10518 clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
10519 7 : 14;
10520 break;
10521 default:
Zhao Yakui28c97732009-10-09 11:39:41 +080010522 DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
Jesse Barnes79e53942008-11-07 14:24:08 -080010523 "mode\n", (int)(dpll & DPLL_MODE_MASK));
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010524 return;
Jesse Barnes79e53942008-11-07 14:24:08 -080010525 }
10526
Ville Syrjälä9b1e14f2016-10-31 22:37:15 +020010527 if (IS_PINEVIEW(dev_priv))
Imre Deakdccbea32015-06-22 23:35:51 +030010528 port_clock = pnv_calc_dpll_params(refclk, &clock);
Daniel Vetterac58c3f2013-06-01 17:16:17 +020010529 else
Imre Deakdccbea32015-06-22 23:35:51 +030010530 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010531 } else {
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010010532 u32 lvds = IS_I830(dev_priv) ? 0 : I915_READ(LVDS);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010533 bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN);
Jesse Barnes79e53942008-11-07 14:24:08 -080010534
10535 if (is_lvds) {
10536 clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
10537 DPLL_FPA01_P1_POST_DIV_SHIFT);
Ville Syrjäläb1c560d2013-12-09 18:54:13 +020010538
10539 if (lvds & LVDS_CLKB_POWER_UP)
10540 clock.p2 = 7;
10541 else
10542 clock.p2 = 14;
Jesse Barnes79e53942008-11-07 14:24:08 -080010543 } else {
10544 if (dpll & PLL_P1_DIVIDE_BY_TWO)
10545 clock.p1 = 2;
10546 else {
10547 clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
10548 DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
10549 }
10550 if (dpll & PLL_P2_DIVIDE_BY_4)
10551 clock.p2 = 4;
10552 else
10553 clock.p2 = 2;
Jesse Barnes79e53942008-11-07 14:24:08 -080010554 }
Ville Syrjäläda4a1ef2013-09-09 14:06:37 +030010555
Imre Deakdccbea32015-06-22 23:35:51 +030010556 port_clock = i9xx_calc_dpll_params(refclk, &clock);
Jesse Barnes79e53942008-11-07 14:24:08 -080010557 }
10558
Ville Syrjälä18442d02013-09-13 16:00:08 +030010559 /*
10560 * This value includes pixel_multiplier. We will use
Damien Lespiau241bfc32013-09-25 16:45:37 +010010561 * port_clock to compute adjusted_mode.crtc_clock in the
Ville Syrjälä18442d02013-09-13 16:00:08 +030010562 * encoder's get_config() function.
10563 */
Imre Deakdccbea32015-06-22 23:35:51 +030010564 pipe_config->port_clock = port_clock;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010565}
10566
Ville Syrjälä6878da02013-09-13 15:59:11 +030010567int intel_dotclock_calculate(int link_freq,
10568 const struct intel_link_m_n *m_n)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010569{
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010570 /*
10571 * The calculation for the data clock is:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010572 * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010573 * But we want to avoid losing precison if possible, so:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010574 * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp))
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010575 *
10576 * and the link clock is simpler:
Ville Syrjälä1041a022013-09-06 23:28:58 +030010577 * link_clock = (m * link_clock) / n
Jesse Barnes79e53942008-11-07 14:24:08 -080010578 */
10579
Ville Syrjälä6878da02013-09-13 15:59:11 +030010580 if (!m_n->link_n)
10581 return 0;
10582
Chris Wilson31236982017-09-13 11:51:53 +010010583 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 +030010584}
10585
Ville Syrjälä18442d02013-09-13 16:00:08 +030010586static void ironlake_pch_clock_get(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020010587 struct intel_crtc_state *pipe_config)
Ville Syrjälä6878da02013-09-13 15:59:11 +030010588{
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010589 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä18442d02013-09-13 16:00:08 +030010590
10591 /* read out port_clock from the DPLL */
10592 i9xx_crtc_clock_get(crtc, pipe_config);
Ville Syrjälä6878da02013-09-13 15:59:11 +030010593
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010594 /*
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020010595 * In case there is an active pipe without active ports,
10596 * we may need some idea for the dotclock anyway.
10597 * Calculate one based on the FDI configuration.
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010598 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020010599 pipe_config->base.adjusted_mode.crtc_clock =
Ville Syrjälä21a727b2016-02-17 21:41:10 +020010600 intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjälä18442d02013-09-13 16:00:08 +030010601 &pipe_config->fdi_m_n);
Jesse Barnes79e53942008-11-07 14:24:08 -080010602}
10603
Ville Syrjäläde330812017-10-09 19:19:50 +030010604/* Returns the currently programmed mode of the given encoder. */
10605struct drm_display_mode *
10606intel_encoder_current_mode(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080010607{
Ville Syrjäläde330812017-10-09 19:19:50 +030010608 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
10609 struct intel_crtc_state *crtc_state;
Jesse Barnes79e53942008-11-07 14:24:08 -080010610 struct drm_display_mode *mode;
Ville Syrjäläde330812017-10-09 19:19:50 +030010611 struct intel_crtc *crtc;
10612 enum pipe pipe;
10613
10614 if (!encoder->get_hw_state(encoder, &pipe))
10615 return NULL;
10616
10617 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Jesse Barnes79e53942008-11-07 14:24:08 -080010618
10619 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
10620 if (!mode)
10621 return NULL;
10622
Ville Syrjäläde330812017-10-09 19:19:50 +030010623 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
10624 if (!crtc_state) {
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010625 kfree(mode);
10626 return NULL;
10627 }
10628
Ville Syrjäläde330812017-10-09 19:19:50 +030010629 crtc_state->base.crtc = &crtc->base;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030010630
Ville Syrjäläde330812017-10-09 19:19:50 +030010631 if (!dev_priv->display.get_pipe_config(crtc, crtc_state)) {
10632 kfree(crtc_state);
10633 kfree(mode);
10634 return NULL;
10635 }
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010636
Ville Syrjäläde330812017-10-09 19:19:50 +030010637 encoder->get_config(encoder, crtc_state);
Ville Syrjäläe30a1542016-04-01 18:37:25 +030010638
Ville Syrjäläde330812017-10-09 19:19:50 +030010639 intel_mode_from_pipe_config(mode, crtc_state);
Jesse Barnes79e53942008-11-07 14:24:08 -080010640
Ville Syrjäläde330812017-10-09 19:19:50 +030010641 kfree(crtc_state);
Tvrtko Ursulin3f36b932016-01-19 15:25:17 +000010642
Jesse Barnes79e53942008-11-07 14:24:08 -080010643 return mode;
10644}
10645
10646static void intel_crtc_destroy(struct drm_crtc *crtc)
10647{
10648 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
10649
10650 drm_crtc_cleanup(crtc);
10651 kfree(intel_crtc);
10652}
10653
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010654/**
10655 * intel_wm_need_update - Check whether watermarks need updating
10656 * @plane: drm plane
10657 * @state: new plane state
10658 *
10659 * Check current plane state versus the new one to determine whether
10660 * watermarks need to be recalculated.
10661 *
10662 * Returns true or false.
10663 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010664static bool intel_wm_need_update(struct intel_plane_state *cur,
10665 struct intel_plane_state *new)
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010666{
Matt Roperd21fbe82015-09-24 15:53:12 -070010667 /* Update watermarks on tiling or size changes. */
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010668 if (new->base.visible != cur->base.visible)
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010669 return true;
10670
10671 if (!cur->base.fb || !new->base.fb)
10672 return false;
10673
Ville Syrjäläbae781b2016-11-16 13:33:16 +020010674 if (cur->base.fb->modifier != new->base.fb->modifier ||
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010675 cur->base.rotation != new->base.rotation ||
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010676 drm_rect_width(&new->base.src) != drm_rect_width(&cur->base.src) ||
10677 drm_rect_height(&new->base.src) != drm_rect_height(&cur->base.src) ||
10678 drm_rect_width(&new->base.dst) != drm_rect_width(&cur->base.dst) ||
10679 drm_rect_height(&new->base.dst) != drm_rect_height(&cur->base.dst))
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010680 return true;
10681
10682 return false;
10683}
10684
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010685static bool needs_scaling(const struct intel_plane_state *state)
Matt Roperd21fbe82015-09-24 15:53:12 -070010686{
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010687 int src_w = drm_rect_width(&state->base.src) >> 16;
10688 int src_h = drm_rect_height(&state->base.src) >> 16;
10689 int dst_w = drm_rect_width(&state->base.dst);
10690 int dst_h = drm_rect_height(&state->base.dst);
Matt Roperd21fbe82015-09-24 15:53:12 -070010691
10692 return (src_w != dst_w || src_h != dst_h);
10693}
10694
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010695int intel_plane_atomic_calc_changes(const struct intel_crtc_state *old_crtc_state,
10696 struct drm_crtc_state *crtc_state,
10697 const struct intel_plane_state *old_plane_state,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010698 struct drm_plane_state *plane_state)
10699{
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010700 struct intel_crtc_state *pipe_config = to_intel_crtc_state(crtc_state);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010701 struct drm_crtc *crtc = crtc_state->crtc;
10702 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010703 struct intel_plane *plane = to_intel_plane(plane_state->plane);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010704 struct drm_device *dev = crtc->dev;
Matt Ropered4a6a72016-02-23 17:20:13 -080010705 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010706 bool mode_changed = needs_modeset(crtc_state);
Ville Syrjäläb2b55502017-08-23 18:22:23 +030010707 bool was_crtc_enabled = old_crtc_state->base.active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010708 bool is_crtc_enabled = crtc_state->active;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010709 bool turn_off, turn_on, visible, was_visible;
10710 struct drm_framebuffer *fb = plane_state->fb;
Ville Syrjälä78108b72016-05-27 20:59:19 +030010711 int ret;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010712
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010713 if (INTEL_GEN(dev_priv) >= 9 && plane->id != PLANE_CURSOR) {
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010714 ret = skl_update_scaler_plane(
10715 to_intel_crtc_state(crtc_state),
10716 to_intel_plane_state(plane_state));
10717 if (ret)
10718 return ret;
10719 }
10720
Ville Syrjälä936e71e2016-07-26 19:06:59 +030010721 was_visible = old_plane_state->base.visible;
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010722 visible = plane_state->visible;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010723
10724 if (!was_crtc_enabled && WARN_ON(was_visible))
10725 was_visible = false;
10726
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010727 /*
10728 * Visibility is calculated as if the crtc was on, but
10729 * after scaler setup everything depends on it being off
10730 * when the crtc isn't active.
Ville Syrjäläf818ffe2016-04-29 17:31:18 +030010731 *
10732 * FIXME this is wrong for watermarks. Watermarks should also
10733 * be computed as if the pipe would be active. Perhaps move
10734 * per-plane wm computation to the .check_plane() hook, and
10735 * only combine the results from all planes in the current place?
Maarten Lankhorst35c08f42015-12-03 14:31:07 +010010736 */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010737 if (!is_crtc_enabled) {
Maarten Lankhorst1d4258d2017-01-12 10:43:45 +010010738 plane_state->visible = visible = false;
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010739 to_intel_crtc_state(crtc_state)->active_planes &= ~BIT(plane->id);
10740 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010741
10742 if (!was_visible && !visible)
10743 return 0;
10744
Maarten Lankhorste8861672016-02-24 11:24:26 +010010745 if (fb != old_plane_state->base.fb)
10746 pipe_config->fb_changed = true;
10747
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010748 turn_off = was_visible && (!visible || mode_changed);
10749 turn_on = visible && (!was_visible || mode_changed);
10750
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010751 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] has [PLANE:%d:%s] with fb %i\n",
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010752 intel_crtc->base.base.id, intel_crtc->base.name,
10753 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010754 fb ? fb->base.id : -1);
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010755
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010756 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 +020010757 plane->base.base.id, plane->base.name,
Ville Syrjälä72660ce2016-05-27 20:59:20 +030010758 was_visible, visible,
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010759 turn_off, turn_on, mode_changed);
10760
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010761 if (turn_on) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010762 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010763 pipe_config->update_wm_pre = true;
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010764
10765 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010766 if (plane->id != PLANE_CURSOR)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010767 pipe_config->disable_cxsr = true;
10768 } else if (turn_off) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010769 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010770 pipe_config->update_wm_post = true;
Maarten Lankhorst92826fc2015-12-03 13:49:13 +010010771
Ville Syrjälä852eb002015-06-24 22:00:07 +030010772 /* must disable cxsr around plane enable/disable */
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010773 if (plane->id != PLANE_CURSOR)
Maarten Lankhorstab1d3a02015-11-19 16:07:14 +010010774 pipe_config->disable_cxsr = true;
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010775 } else if (intel_wm_need_update(to_intel_plane_state(plane->base.state),
10776 to_intel_plane_state(plane_state))) {
Ville Syrjälä04548cb2017-04-21 21:14:29 +030010777 if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv)) {
Ville Syrjäläb4ede6d2017-03-02 19:15:01 +020010778 /* FIXME bollocks */
10779 pipe_config->update_wm_pre = true;
10780 pipe_config->update_wm_post = true;
10781 }
Ville Syrjälä852eb002015-06-24 22:00:07 +030010782 }
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010783
Rodrigo Vivi8be6ca82015-08-24 16:38:23 -070010784 if (visible || was_visible)
Ville Syrjäläe9728bd2017-03-02 19:14:51 +020010785 pipe_config->fb_bits |= plane->frontbuffer_bit;
Ville Syrjäläa9ff8712015-06-24 21:59:34 +030010786
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010787 /*
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010788 * ILK/SNB DVSACNTR/Sprite Enable
10789 * IVB SPR_CTL/Sprite Enable
10790 * "When in Self Refresh Big FIFO mode, a write to enable the
10791 * plane will be internally buffered and delayed while Big FIFO
10792 * mode is exiting."
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010793 *
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010794 * Which means that enabling the sprite can take an extra frame
10795 * when we start in big FIFO mode (LP1+). Thus we need to drop
10796 * down to LP0 and wait for vblank in order to make sure the
10797 * sprite gets enabled on the next vblank after the register write.
10798 * Doing otherwise would risk enabling the sprite one frame after
10799 * we've already signalled flip completion. We can resume LP1+
10800 * once the sprite has been enabled.
10801 *
10802 *
10803 * WaCxSRDisabledForSpriteScaling:ivb
10804 * IVB SPR_SCALE/Scaling Enable
10805 * "Low Power watermarks must be disabled for at least one
10806 * frame before enabling sprite scaling, and kept disabled
10807 * until sprite scaling is disabled."
10808 *
10809 * ILK/SNB DVSASCALE/Scaling Enable
10810 * "When in Self Refresh Big FIFO mode, scaling enable will be
10811 * masked off while Big FIFO mode is exiting."
10812 *
10813 * Despite the w/a only being listed for IVB we assume that
10814 * the ILK/SNB note has similar ramifications, hence we apply
10815 * the w/a on all three platforms.
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010816 */
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010817 if (plane->id == PLANE_SPRITE0 &&
Lucas De Marchif3ce44a2018-12-12 10:10:44 -080010818 (IS_GEN_RANGE(dev_priv, 5, 6) ||
Ville Syrjälä8e7a4422018-10-04 15:15:27 +030010819 IS_IVYBRIDGE(dev_priv)) &&
10820 (turn_on || (!needs_scaling(old_plane_state) &&
10821 needs_scaling(to_intel_plane_state(plane_state)))))
Maarten Lankhorst31ae71f2016-03-09 10:35:45 +010010822 pipe_config->disable_lp_wm = true;
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010823
Maarten Lankhorstda20eab2015-06-15 12:33:44 +020010824 return 0;
10825}
10826
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010827static bool encoders_cloneable(const struct intel_encoder *a,
10828 const struct intel_encoder *b)
10829{
10830 /* masks could be asymmetric, so check both ways */
10831 return a == b || (a->cloneable & (1 << b->type) &&
10832 b->cloneable & (1 << a->type));
10833}
10834
10835static bool check_single_encoder_cloning(struct drm_atomic_state *state,
10836 struct intel_crtc *crtc,
10837 struct intel_encoder *encoder)
10838{
10839 struct intel_encoder *source_encoder;
10840 struct drm_connector *connector;
10841 struct drm_connector_state *connector_state;
10842 int i;
10843
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010010844 for_each_new_connector_in_state(state, connector, connector_state, i) {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010845 if (connector_state->crtc != &crtc->base)
10846 continue;
10847
10848 source_encoder =
10849 to_intel_encoder(connector_state->best_encoder);
10850 if (!encoders_cloneable(encoder, source_encoder))
10851 return false;
10852 }
10853
10854 return true;
10855}
10856
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010857static int icl_add_linked_planes(struct intel_atomic_state *state)
10858{
10859 struct intel_plane *plane, *linked;
10860 struct intel_plane_state *plane_state, *linked_plane_state;
10861 int i;
10862
10863 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10864 linked = plane_state->linked_plane;
10865
10866 if (!linked)
10867 continue;
10868
10869 linked_plane_state = intel_atomic_get_plane_state(state, linked);
10870 if (IS_ERR(linked_plane_state))
10871 return PTR_ERR(linked_plane_state);
10872
10873 WARN_ON(linked_plane_state->linked_plane != plane);
10874 WARN_ON(linked_plane_state->slave == plane_state->slave);
10875 }
10876
10877 return 0;
10878}
10879
10880static int icl_check_nv12_planes(struct intel_crtc_state *crtc_state)
10881{
10882 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
10883 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
10884 struct intel_atomic_state *state = to_intel_atomic_state(crtc_state->base.state);
10885 struct intel_plane *plane, *linked;
10886 struct intel_plane_state *plane_state;
10887 int i;
10888
10889 if (INTEL_GEN(dev_priv) < 11)
10890 return 0;
10891
10892 /*
10893 * Destroy all old plane links and make the slave plane invisible
10894 * in the crtc_state->active_planes mask.
10895 */
10896 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10897 if (plane->pipe != crtc->pipe || !plane_state->linked_plane)
10898 continue;
10899
10900 plane_state->linked_plane = NULL;
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010901 if (plane_state->slave && !plane_state->base.visible) {
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010902 crtc_state->active_planes &= ~BIT(plane->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010903 crtc_state->update_planes |= BIT(plane->id);
10904 }
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010905
10906 plane_state->slave = false;
10907 }
10908
10909 if (!crtc_state->nv12_planes)
10910 return 0;
10911
10912 for_each_new_intel_plane_in_state(state, plane, plane_state, i) {
10913 struct intel_plane_state *linked_state = NULL;
10914
10915 if (plane->pipe != crtc->pipe ||
10916 !(crtc_state->nv12_planes & BIT(plane->id)))
10917 continue;
10918
10919 for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, linked) {
10920 if (!icl_is_nv12_y_plane(linked->id))
10921 continue;
10922
10923 if (crtc_state->active_planes & BIT(linked->id))
10924 continue;
10925
10926 linked_state = intel_atomic_get_plane_state(state, linked);
10927 if (IS_ERR(linked_state))
10928 return PTR_ERR(linked_state);
10929
10930 break;
10931 }
10932
10933 if (!linked_state) {
10934 DRM_DEBUG_KMS("Need %d free Y planes for NV12\n",
10935 hweight8(crtc_state->nv12_planes));
10936
10937 return -EINVAL;
10938 }
10939
10940 plane_state->linked_plane = linked;
10941
10942 linked_state->slave = true;
10943 linked_state->linked_plane = plane;
10944 crtc_state->active_planes |= BIT(linked->id);
Ville Syrjäläafbd8a72018-11-27 18:37:42 +020010945 crtc_state->update_planes |= BIT(linked->id);
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020010946 DRM_DEBUG_KMS("Using %s as Y plane for %s\n", linked->base.name, plane->base.name);
10947 }
10948
10949 return 0;
10950}
10951
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010952static int intel_crtc_atomic_check(struct drm_crtc *crtc,
10953 struct drm_crtc_state *crtc_state)
10954{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080010955 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010956 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstcf5a15b2015-06-15 12:33:41 +020010957 struct intel_crtc_state *pipe_config =
10958 to_intel_crtc_state(crtc_state);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020010959 int ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020010960 bool mode_changed = needs_modeset(crtc_state);
10961
Ville Syrjälä852eb002015-06-24 22:00:07 +030010962 if (mode_changed && !crtc_state->active)
Ville Syrjäläcaed3612016-03-09 19:07:25 +020010963 pipe_config->update_wm_post = true;
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020010964
Maarten Lankhorstad421372015-06-15 12:33:42 +020010965 if (mode_changed && crtc_state->enable &&
10966 dev_priv->display.crtc_compute_clock &&
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020010967 !WARN_ON(pipe_config->shared_dpll)) {
Maarten Lankhorstad421372015-06-15 12:33:42 +020010968 ret = dev_priv->display.crtc_compute_clock(intel_crtc,
10969 pipe_config);
10970 if (ret)
10971 return ret;
10972 }
10973
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010974 if (crtc_state->color_mgmt_changed) {
Matt Roper302da0c2018-12-10 13:54:15 -080010975 ret = intel_color_check(pipe_config);
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010976 if (ret)
10977 return ret;
Lionel Landwerline7852a42016-05-25 14:30:41 +010010978
10979 /*
10980 * Changing color management on Intel hardware is
10981 * handled as part of planes update.
10982 */
10983 crtc_state->planes_changed = true;
Lionel Landwerlin82cf4352016-03-16 10:57:16 +000010984 }
10985
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020010986 ret = 0;
Matt Roper86c8bbb2015-09-24 15:53:16 -070010987 if (dev_priv->display.compute_pipe_wm) {
Maarten Lankhorste3bddde2016-03-01 11:07:22 +010010988 ret = dev_priv->display.compute_pipe_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080010989 if (ret) {
10990 DRM_DEBUG_KMS("Target pipe watermarks are invalid\n");
Matt Roper86c8bbb2015-09-24 15:53:16 -070010991 return ret;
Matt Ropered4a6a72016-02-23 17:20:13 -080010992 }
10993 }
10994
Ville Syrjäläf255c622018-11-08 17:10:13 +020010995 if (dev_priv->display.compute_intermediate_wm) {
Matt Ropered4a6a72016-02-23 17:20:13 -080010996 if (WARN_ON(!dev_priv->display.compute_pipe_wm))
10997 return 0;
10998
10999 /*
11000 * Calculate 'intermediate' watermarks that satisfy both the
11001 * old state and the new state. We can program these
11002 * immediately.
11003 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011004 ret = dev_priv->display.compute_intermediate_wm(pipe_config);
Matt Ropered4a6a72016-02-23 17:20:13 -080011005 if (ret) {
11006 DRM_DEBUG_KMS("No valid intermediate pipe watermarks are possible\n");
11007 return ret;
11008 }
Matt Roper86c8bbb2015-09-24 15:53:16 -070011009 }
11010
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011011 if (INTEL_GEN(dev_priv) >= 9) {
Hans de Goede2c5c4152018-12-17 15:19:03 +010011012 if (mode_changed || pipe_config->update_pipe)
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011013 ret = skl_update_scaler_crtc(pipe_config);
11014
11015 if (!ret)
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020011016 ret = icl_check_nv12_planes(pipe_config);
11017 if (!ret)
Mahesh Kumar73b0ca82017-05-26 20:45:46 +053011018 ret = skl_check_pipe_max_pixel_rate(intel_crtc,
11019 pipe_config);
11020 if (!ret)
Ander Conselvan de Oliveira6ebc6922017-02-23 09:15:59 +020011021 ret = intel_atomic_setup_scalers(dev_priv, intel_crtc,
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011022 pipe_config);
11023 }
11024
Maarten Lankhorst24f28452017-11-22 19:39:01 +010011025 if (HAS_IPS(dev_priv))
11026 pipe_config->ips_enabled = hsw_compute_ips_config(pipe_config);
11027
Maarten Lankhorste435d6e2015-07-13 16:30:15 +020011028 return ret;
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011029}
11030
Jani Nikula65b38e02015-04-13 11:26:56 +030011031static const struct drm_crtc_helper_funcs intel_helper_funcs = {
Maarten Lankhorst6d3a1ce2015-06-15 12:33:40 +020011032 .atomic_check = intel_crtc_atomic_check,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010011033};
11034
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011035static void intel_modeset_update_connector_atomic_state(struct drm_device *dev)
11036{
11037 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011038 struct drm_connector_list_iter conn_iter;
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011039
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011040 drm_connector_list_iter_begin(dev, &conn_iter);
11041 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter8863dc72016-05-06 15:39:03 +020011042 if (connector->base.state->crtc)
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011043 drm_connector_put(&connector->base);
Daniel Vetter8863dc72016-05-06 15:39:03 +020011044
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011045 if (connector->base.encoder) {
11046 connector->base.state->best_encoder =
11047 connector->base.encoder;
11048 connector->base.state->crtc =
11049 connector->base.encoder->crtc;
Daniel Vetter8863dc72016-05-06 15:39:03 +020011050
Thomas Zimmermannef196b52018-06-18 13:01:50 +020011051 drm_connector_get(&connector->base);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011052 } else {
11053 connector->base.state->best_encoder = NULL;
11054 connector->base.state->crtc = NULL;
11055 }
11056 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010011057 drm_connector_list_iter_end(&conn_iter);
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020011058}
11059
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011060static int
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011061compute_sink_pipe_bpp(const struct drm_connector_state *conn_state,
11062 struct intel_crtc_state *pipe_config)
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011063{
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011064 struct drm_connector *connector = conn_state->connector;
11065 const struct drm_display_info *info = &connector->display_info;
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011066 int bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011067
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011068 switch (conn_state->max_bpc) {
11069 case 6 ... 7:
11070 bpp = 6 * 3;
11071 break;
11072 case 8 ... 9:
11073 bpp = 8 * 3;
11074 break;
11075 case 10 ... 11:
11076 bpp = 10 * 3;
11077 break;
11078 case 12:
11079 bpp = 12 * 3;
11080 break;
11081 default:
11082 return -EINVAL;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011083 }
11084
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011085 if (bpp < pipe_config->pipe_bpp) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011086 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] Limiting display bpp to %d instead of "
11087 "EDID bpp %d, requested bpp %d, max platform bpp %d\n",
11088 connector->base.id, connector->name,
11089 bpp, 3 * info->bpc, 3 * conn_state->max_requested_bpc,
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011090 pipe_config->pipe_bpp);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011091
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011092 pipe_config->pipe_bpp = bpp;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011093 }
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011094
Radhakrishna Sripadaf1a12172018-10-22 18:44:00 -070011095 return 0;
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011096}
11097
11098static int
11099compute_baseline_pipe_bpp(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011100 struct intel_crtc_state *pipe_config)
Daniel Vetter050f7ae2013-06-02 13:26:23 +020011101{
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011102 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011103 struct drm_atomic_state *state = pipe_config->base.state;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011104 struct drm_connector *connector;
11105 struct drm_connector_state *connector_state;
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011106 int bpp, i;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011107
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011108 if ((IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
11109 IS_CHERRYVIEW(dev_priv)))
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011110 bpp = 10*3;
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011111 else if (INTEL_GEN(dev_priv) >= 5)
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011112 bpp = 12*3;
11113 else
11114 bpp = 8*3;
11115
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011116 pipe_config->pipe_bpp = bpp;
11117
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011118 /* Clamp display bpp to connector max bpp */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011119 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011120 int ret;
11121
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011122 if (connector_state->crtc != &crtc->base)
Ander Conselvan de Oliveira14860172015-03-20 16:18:09 +020011123 continue;
11124
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011125 ret = compute_sink_pipe_bpp(connector_state, pipe_config);
11126 if (ret)
11127 return ret;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011128 }
11129
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011130 return 0;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011131}
11132
Daniel Vetter644db712013-09-19 14:53:58 +020011133static void intel_dump_crtc_timings(const struct drm_display_mode *mode)
11134{
11135 DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, "
11136 "type: 0x%x flags: 0x%x\n",
Damien Lespiau13428302013-09-25 16:45:36 +010011137 mode->crtc_clock,
Daniel Vetter644db712013-09-19 14:53:58 +020011138 mode->crtc_hdisplay, mode->crtc_hsync_start,
11139 mode->crtc_hsync_end, mode->crtc_htotal,
11140 mode->crtc_vdisplay, mode->crtc_vsync_start,
11141 mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags);
11142}
11143
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011144static inline void
11145intel_dump_m_n_config(struct intel_crtc_state *pipe_config, char *id,
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011146 unsigned int lane_count, struct intel_link_m_n *m_n)
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011147{
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011148 DRM_DEBUG_KMS("%s: lanes: %i; gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n",
11149 id, lane_count,
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011150 m_n->gmch_m, m_n->gmch_n,
11151 m_n->link_m, m_n->link_n, m_n->tu);
11152}
11153
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011154#define OUTPUT_TYPE(x) [INTEL_OUTPUT_ ## x] = #x
11155
11156static const char * const output_type_str[] = {
11157 OUTPUT_TYPE(UNUSED),
11158 OUTPUT_TYPE(ANALOG),
11159 OUTPUT_TYPE(DVO),
11160 OUTPUT_TYPE(SDVO),
11161 OUTPUT_TYPE(LVDS),
11162 OUTPUT_TYPE(TVOUT),
11163 OUTPUT_TYPE(HDMI),
11164 OUTPUT_TYPE(DP),
11165 OUTPUT_TYPE(EDP),
11166 OUTPUT_TYPE(DSI),
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011167 OUTPUT_TYPE(DDI),
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011168 OUTPUT_TYPE(DP_MST),
11169};
11170
11171#undef OUTPUT_TYPE
11172
11173static void snprintf_output_types(char *buf, size_t len,
11174 unsigned int output_types)
11175{
11176 char *str = buf;
11177 int i;
11178
11179 str[0] = '\0';
11180
11181 for (i = 0; i < ARRAY_SIZE(output_type_str); i++) {
11182 int r;
11183
11184 if ((output_types & BIT(i)) == 0)
11185 continue;
11186
11187 r = snprintf(str, len, "%s%s",
11188 str != buf ? "," : "", output_type_str[i]);
11189 if (r >= len)
11190 break;
11191 str += r;
11192 len -= r;
11193
11194 output_types &= ~BIT(i);
11195 }
11196
11197 WARN_ON_ONCE(output_types != 0);
11198}
11199
Shashank Sharmad9facae2018-10-12 11:53:07 +053011200static const char * const output_format_str[] = {
11201 [INTEL_OUTPUT_FORMAT_INVALID] = "Invalid",
11202 [INTEL_OUTPUT_FORMAT_RGB] = "RGB",
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011203 [INTEL_OUTPUT_FORMAT_YCBCR420] = "YCBCR4:2:0",
Shashank Sharma8c79f842018-10-12 11:53:09 +053011204 [INTEL_OUTPUT_FORMAT_YCBCR444] = "YCBCR4:4:4",
Shashank Sharmad9facae2018-10-12 11:53:07 +053011205};
11206
11207static const char *output_formats(enum intel_output_format format)
11208{
Shashank Sharma33b7f3e2018-10-12 11:53:08 +053011209 if (format >= ARRAY_SIZE(output_format_str))
Shashank Sharmad9facae2018-10-12 11:53:07 +053011210 format = INTEL_OUTPUT_FORMAT_INVALID;
11211 return output_format_str[format];
11212}
11213
Daniel Vetterc0b03412013-05-28 12:05:54 +020011214static void intel_dump_pipe_config(struct intel_crtc *crtc,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011215 struct intel_crtc_state *pipe_config,
Daniel Vetterc0b03412013-05-28 12:05:54 +020011216 const char *context)
11217{
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011218 struct drm_device *dev = crtc->base.dev;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011219 struct drm_i915_private *dev_priv = to_i915(dev);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011220 struct drm_plane *plane;
11221 struct intel_plane *intel_plane;
11222 struct intel_plane_state *state;
11223 struct drm_framebuffer *fb;
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011224 char buf[64];
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011225
Tvrtko Ursulin66766e42016-11-17 12:30:10 +000011226 DRM_DEBUG_KMS("[CRTC:%d:%s]%s\n",
11227 crtc->base.base.id, crtc->base.name, context);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011228
Ville Syrjälä40b2be42017-10-10 15:11:59 +030011229 snprintf_output_types(buf, sizeof(buf), pipe_config->output_types);
11230 DRM_DEBUG_KMS("output_types: %s (0x%x)\n",
11231 buf, pipe_config->output_types);
11232
Shashank Sharmad9facae2018-10-12 11:53:07 +053011233 DRM_DEBUG_KMS("output format: %s\n",
11234 output_formats(pipe_config->output_format));
11235
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011236 DRM_DEBUG_KMS("cpu_transcoder: %s, pipe bpp: %i, dithering: %i\n",
11237 transcoder_name(pipe_config->cpu_transcoder),
Daniel Vetterc0b03412013-05-28 12:05:54 +020011238 pipe_config->pipe_bpp, pipe_config->dither);
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011239
11240 if (pipe_config->has_pch_encoder)
11241 intel_dump_m_n_config(pipe_config, "fdi",
11242 pipe_config->fdi_lanes,
11243 &pipe_config->fdi_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011244
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011245 if (intel_crtc_has_dp_encoder(pipe_config)) {
Tvrtko Ursulina4309652016-11-17 12:30:09 +000011246 intel_dump_m_n_config(pipe_config, "dp m_n",
11247 pipe_config->lane_count, &pipe_config->dp_m_n);
Tvrtko Ursulind806e682016-11-17 15:44:09 +000011248 if (pipe_config->has_drrs)
11249 intel_dump_m_n_config(pipe_config, "dp m2_n2",
11250 pipe_config->lane_count,
11251 &pipe_config->dp_m2_n2);
Tvrtko Ursulinf6982332016-11-17 12:30:08 +000011252 }
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011253
Daniel Vetter55072d12014-11-20 16:10:28 +010011254 DRM_DEBUG_KMS("audio: %i, infoframes: %i\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011255 pipe_config->has_audio, pipe_config->has_infoframe);
Daniel Vetter55072d12014-11-20 16:10:28 +010011256
Daniel Vetterc0b03412013-05-28 12:05:54 +020011257 DRM_DEBUG_KMS("requested mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011258 drm_mode_debug_printmodeline(&pipe_config->base.mode);
Daniel Vetterc0b03412013-05-28 12:05:54 +020011259 DRM_DEBUG_KMS("adjusted mode:\n");
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011260 drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode);
11261 intel_dump_crtc_timings(&pipe_config->base.adjusted_mode);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011262 DRM_DEBUG_KMS("port clock: %d, pipe src size: %dx%d, pixel rate %d\n",
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011263 pipe_config->port_clock,
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011264 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
11265 pipe_config->pixel_rate);
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011266
11267 if (INTEL_GEN(dev_priv) >= 9)
11268 DRM_DEBUG_KMS("num_scalers: %d, scaler_users: 0x%x, scaler_id: %d\n",
11269 crtc->num_scalers,
11270 pipe_config->scaler_state.scaler_users,
11271 pipe_config->scaler_state.scaler_id);
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011272
11273 if (HAS_GMCH_DISPLAY(dev_priv))
11274 DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n",
11275 pipe_config->gmch_pfit.control,
11276 pipe_config->gmch_pfit.pgm_ratios,
11277 pipe_config->gmch_pfit.lvds_border_bits);
11278 else
11279 DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n",
11280 pipe_config->pch_pfit.pos,
11281 pipe_config->pch_pfit.size,
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000011282 enableddisabled(pipe_config->pch_pfit.enabled));
Tvrtko Ursulina74f8372016-11-17 12:30:13 +000011283
Tvrtko Ursulin2c894292016-11-17 12:30:11 +000011284 DRM_DEBUG_KMS("ips: %i, double wide: %i\n",
11285 pipe_config->ips_enabled, pipe_config->double_wide);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011286
Ander Conselvan de Oliveiraf50b79f2016-12-29 17:22:12 +020011287 intel_dpll_dump_hw_state(dev_priv, &pipe_config->dpll_hw_state);
Tvrtko Ursulin415ff0f2015-05-14 13:38:31 +010011288
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011289 DRM_DEBUG_KMS("planes on this crtc\n");
11290 list_for_each_entry(plane, &dev->mode_config.plane_list, head) {
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011291 struct drm_format_name_buf format_name;
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011292 intel_plane = to_intel_plane(plane);
11293 if (intel_plane->pipe != crtc->pipe)
11294 continue;
11295
11296 state = to_intel_plane_state(plane->state);
11297 fb = state->base.fb;
11298 if (!fb) {
Ville Syrjälä1d577e02016-05-27 20:59:25 +030011299 DRM_DEBUG_KMS("[PLANE:%d:%s] disabled, scaler_id = %d\n",
11300 plane->base.id, plane->name, state->scaler_id);
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011301 continue;
11302 }
11303
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011304 DRM_DEBUG_KMS("[PLANE:%d:%s] FB:%d, fb = %ux%u format = %s\n",
11305 plane->base.id, plane->name,
Eric Engestromb3c11ac2016-11-12 01:12:56 +000011306 fb->base.id, fb->width, fb->height,
Ville Syrjälä438b74a2016-12-14 23:32:55 +020011307 drm_get_format_name(fb->format->format, &format_name));
Tvrtko Ursulindd2f6162016-11-17 12:30:12 +000011308 if (INTEL_GEN(dev_priv) >= 9)
11309 DRM_DEBUG_KMS("\tscaler:%d src %dx%d+%d+%d dst %dx%d+%d+%d\n",
11310 state->scaler_id,
11311 state->base.src.x1 >> 16,
11312 state->base.src.y1 >> 16,
11313 drm_rect_width(&state->base.src) >> 16,
11314 drm_rect_height(&state->base.src) >> 16,
11315 state->base.dst.x1, state->base.dst.y1,
11316 drm_rect_width(&state->base.dst),
11317 drm_rect_height(&state->base.dst));
Chandra Konduru6a60cd82015-04-07 15:28:40 -070011318 }
Daniel Vetterc0b03412013-05-28 12:05:54 +020011319}
11320
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011321static bool check_digital_port_conflicts(struct drm_atomic_state *state)
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011322{
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011323 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011324 struct drm_connector *connector;
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011325 struct drm_connector_list_iter conn_iter;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011326 unsigned int used_ports = 0;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011327 unsigned int used_mst_ports = 0;
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011328 bool ret = true;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011329
11330 /*
11331 * Walk the connector list instead of the encoder
11332 * list to detect the problem on ddi platforms
11333 * where there's just one encoder per digital port.
11334 */
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011335 drm_connector_list_iter_begin(dev, &conn_iter);
11336 drm_for_each_connector_iter(connector, &conn_iter) {
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011337 struct drm_connector_state *connector_state;
11338 struct intel_encoder *encoder;
11339
Maarten Lankhorst8b694492018-04-09 14:46:55 +020011340 connector_state = drm_atomic_get_new_connector_state(state, connector);
Ville Syrjälä0bff4852015-12-10 18:22:31 +020011341 if (!connector_state)
11342 connector_state = connector->state;
11343
Ander Conselvan de Oliveira5448a002015-04-02 14:47:59 +030011344 if (!connector_state->best_encoder)
11345 continue;
11346
11347 encoder = to_intel_encoder(connector_state->best_encoder);
11348
11349 WARN_ON(!connector_state->crtc);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011350
11351 switch (encoder->type) {
11352 unsigned int port_mask;
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011353 case INTEL_OUTPUT_DDI:
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010011354 if (WARN_ON(!HAS_DDI(to_i915(dev))))
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011355 break;
Gustavo A. R. Silvaf0d759f2018-06-28 17:35:41 -050011356 /* else: fall through */
Ville Syrjäläcca05022016-06-22 21:57:06 +030011357 case INTEL_OUTPUT_DP:
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011358 case INTEL_OUTPUT_HDMI:
11359 case INTEL_OUTPUT_EDP:
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011360 port_mask = 1 << encoder->port;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011361
11362 /* the same port mustn't appear more than once */
11363 if (used_ports & port_mask)
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011364 ret = false;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011365
11366 used_ports |= port_mask;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011367 break;
11368 case INTEL_OUTPUT_DP_MST:
11369 used_mst_ports |=
Ville Syrjälä8f4f2792017-11-09 17:24:34 +020011370 1 << encoder->port;
Ville Syrjälä477321e2016-07-28 17:50:40 +030011371 break;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011372 default:
11373 break;
11374 }
11375 }
Gustavo Padovan2fd96b42017-05-11 16:10:44 -030011376 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011377
Ville Syrjälä477321e2016-07-28 17:50:40 +030011378 /* can't mix MST and SST/HDMI on the same port */
11379 if (used_ports & used_mst_ports)
11380 return false;
11381
Maarten Lankhorstbd67a8c2018-02-15 10:14:25 +010011382 return ret;
Ville Syrjälä00f0b372014-12-02 14:10:46 +020011383}
11384
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011385static void
11386clear_intel_crtc_state(struct intel_crtc_state *crtc_state)
11387{
Ville Syrjäläff32c542017-03-02 19:14:57 +020011388 struct drm_i915_private *dev_priv =
11389 to_i915(crtc_state->base.crtc->dev);
Chandra Konduru663a3642015-04-07 15:28:41 -070011390 struct intel_crtc_scaler_state scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011391 struct intel_dpll_hw_state dpll_hw_state;
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011392 struct intel_shared_dpll *shared_dpll;
Ville Syrjäläff32c542017-03-02 19:14:57 +020011393 struct intel_crtc_wm_state wm_state;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011394 bool force_thru, ips_force_disable;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011395
Ander Conselvan de Oliveira7546a382015-05-20 09:03:27 +030011396 /* FIXME: before the switch to atomic started, a new pipe_config was
11397 * kzalloc'd. Code that depends on any field being zero should be
11398 * fixed, so that the crtc_state can be safely duplicated. For now,
11399 * only fields that are know to not cause problems are preserved. */
11400
Chandra Konduru663a3642015-04-07 15:28:41 -070011401 scaler_state = crtc_state->scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011402 shared_dpll = crtc_state->shared_dpll;
11403 dpll_hw_state = crtc_state->dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011404 force_thru = crtc_state->pch_pfit.force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011405 ips_force_disable = crtc_state->ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011406 if (IS_G4X(dev_priv) ||
11407 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011408 wm_state = crtc_state->wm;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011409
Chris Wilsond2fa80a2017-03-03 15:46:44 +000011410 /* Keep base drm_crtc_state intact, only clear our extended struct */
11411 BUILD_BUG_ON(offsetof(struct intel_crtc_state, base));
11412 memset(&crtc_state->base + 1, 0,
11413 sizeof(*crtc_state) - sizeof(crtc_state->base));
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011414
Chandra Konduru663a3642015-04-07 15:28:41 -070011415 crtc_state->scaler_state = scaler_state;
Ander Conselvan de Oliveira4978cc92015-04-21 17:13:21 +030011416 crtc_state->shared_dpll = shared_dpll;
11417 crtc_state->dpll_hw_state = dpll_hw_state;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +020011418 crtc_state->pch_pfit.force_thru = force_thru;
Ville Syrjälä6e644622017-08-17 17:55:09 +030011419 crtc_state->ips_force_disable = ips_force_disable;
Ville Syrjälä04548cb2017-04-21 21:14:29 +030011420 if (IS_G4X(dev_priv) ||
11421 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Ville Syrjäläff32c542017-03-02 19:14:57 +020011422 crtc_state->wm = wm_state;
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011423}
11424
Ander Conselvan de Oliveira548ee152015-04-21 17:13:02 +030011425static int
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011426intel_modeset_pipe_config(struct drm_crtc *crtc,
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011427 struct intel_crtc_state *pipe_config)
Daniel Vetter7758a112012-07-08 19:40:39 +020011428{
Maarten Lankhorstb3592832015-06-15 12:33:38 +020011429 struct drm_atomic_state *state = pipe_config->base.state;
Daniel Vetter7758a112012-07-08 19:40:39 +020011430 struct intel_encoder *encoder;
Ander Conselvan de Oliveirada3ced2982015-04-21 17:12:59 +030011431 struct drm_connector *connector;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011432 struct drm_connector_state *connector_state;
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011433 int base_bpp, ret;
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011434 int i;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011435 bool retry = true;
Daniel Vetter7758a112012-07-08 19:40:39 +020011436
Ander Conselvan de Oliveira83a57152015-03-20 16:18:03 +020011437 clear_intel_crtc_state(pipe_config);
Daniel Vetter7758a112012-07-08 19:40:39 +020011438
Daniel Vettere143a212013-07-04 12:01:15 +020011439 pipe_config->cpu_transcoder =
11440 (enum transcoder) to_intel_crtc(crtc)->pipe;
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010011441
Imre Deak2960bc92013-07-30 13:36:32 +030011442 /*
11443 * Sanitize sync polarity flags based on requested ones. If neither
11444 * positive or negative polarity is requested, treat this as meaning
11445 * negative polarity.
11446 */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011447 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011448 (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011449 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011450
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011451 if (!(pipe_config->base.adjusted_mode.flags &
Imre Deak2960bc92013-07-30 13:36:32 +030011452 (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC)))
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011453 pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC;
Imre Deak2960bc92013-07-30 13:36:32 +030011454
Ville Syrjäläbcce8d82018-11-07 23:35:22 +020011455 ret = compute_baseline_pipe_bpp(to_intel_crtc(crtc),
11456 pipe_config);
11457 if (ret)
11458 return ret;
11459
11460 base_bpp = pipe_config->pipe_bpp;
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011461
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011462 /*
11463 * Determine the real pipe dimensions. Note that stereo modes can
11464 * increase the actual pipe size due to the frame doubling and
11465 * insertion of additional space for blanks between the frame. This
11466 * is stored in the crtc timings. We use the requested mode to do this
11467 * computation to clearly distinguish it from the adjusted mode, which
11468 * can be changed by the connectors in the below retry loop.
11469 */
Daniel Vetter196cd5d2017-01-25 07:26:56 +010011470 drm_mode_get_hv_timing(&pipe_config->base.mode,
Gustavo Padovanecb7e162014-12-01 15:40:09 -080011471 &pipe_config->pipe_src_w,
11472 &pipe_config->pipe_src_h);
Ville Syrjäläe41a56b2013-10-01 22:52:14 +030011473
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011474 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011475 if (connector_state->crtc != crtc)
11476 continue;
11477
11478 encoder = to_intel_encoder(connector_state->best_encoder);
11479
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011480 if (!check_single_encoder_cloning(state, to_intel_crtc(crtc), encoder)) {
11481 DRM_DEBUG_KMS("rejecting invalid cloning configuration\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011482 return -EINVAL;
Ville Syrjäläe25148d2016-06-22 21:57:09 +030011483 }
11484
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011485 /*
11486 * Determine output_types before calling the .compute_config()
11487 * hooks so that the hooks can use this information safely.
11488 */
Ville Syrjälä7e732ca2017-10-27 22:31:24 +030011489 if (encoder->compute_output_type)
11490 pipe_config->output_types |=
11491 BIT(encoder->compute_output_type(encoder, pipe_config,
11492 connector_state));
11493 else
11494 pipe_config->output_types |= BIT(encoder->type);
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011495 }
11496
Daniel Vettere29c22c2013-02-21 00:00:16 +010011497encoder_retry:
Daniel Vetteref1b4602013-06-01 17:17:04 +020011498 /* Ensure the port clock defaults are reset when retrying. */
Daniel Vetterff9a6752013-06-01 17:16:21 +020011499 pipe_config->port_clock = 0;
Daniel Vetteref1b4602013-06-01 17:17:04 +020011500 pipe_config->pixel_multiplier = 1;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011501
Daniel Vetter135c81b2013-07-21 21:37:09 +020011502 /* Fill in default crtc timings, allow encoders to overwrite them. */
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011503 drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode,
11504 CRTC_STEREO_DOUBLE);
Daniel Vetter135c81b2013-07-21 21:37:09 +020011505
Daniel Vetter7758a112012-07-08 19:40:39 +020011506 /* Pass our mode to the connectors and the CRTC to give them a chance to
11507 * adjust it according to limitations or connector properties, and also
11508 * a chance to reject the mode entirely.
11509 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010011510 for_each_new_connector_in_state(state, connector, connector_state, i) {
Ander Conselvan de Oliveira0b901872015-03-20 16:18:08 +020011511 if (connector_state->crtc != crtc)
11512 continue;
11513
11514 encoder = to_intel_encoder(connector_state->best_encoder);
11515
Maarten Lankhorst0a478c22016-08-09 17:04:05 +020011516 if (!(encoder->compute_config(encoder, pipe_config, connector_state))) {
Daniel Vetterefea6e82013-07-21 21:36:59 +020011517 DRM_DEBUG_KMS("Encoder config failure\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011518 return -EINVAL;
Daniel Vetter7758a112012-07-08 19:40:39 +020011519 }
11520 }
11521
Daniel Vetterff9a6752013-06-01 17:16:21 +020011522 /* Set default port clock if not overwritten by the encoder. Needs to be
11523 * done afterwards in case the encoder adjusts the mode. */
11524 if (!pipe_config->port_clock)
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011525 pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock
Damien Lespiau241bfc32013-09-25 16:45:37 +010011526 * pipe_config->pixel_multiplier;
Daniel Vetterff9a6752013-06-01 17:16:21 +020011527
Daniel Vettera43f6e02013-06-07 23:10:32 +020011528 ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020011529 if (ret == -EDEADLK)
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011530 return ret;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011531 if (ret < 0) {
Daniel Vetter7758a112012-07-08 19:40:39 +020011532 DRM_DEBUG_KMS("CRTC fixup failed\n");
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011533 return ret;
Daniel Vetter7758a112012-07-08 19:40:39 +020011534 }
Daniel Vettere29c22c2013-02-21 00:00:16 +010011535
11536 if (ret == RETRY) {
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011537 if (WARN(!retry, "loop in pipe configuration computation\n"))
11538 return -EINVAL;
Daniel Vettere29c22c2013-02-21 00:00:16 +010011539
11540 DRM_DEBUG_KMS("CRTC bw constrained, retrying\n");
11541 retry = false;
11542 goto encoder_retry;
11543 }
11544
Daniel Vettere8fa4272015-08-12 11:43:34 +020011545 /* Dithering seems to not pass-through bits correctly when it should, so
Manasi Navare611032b2017-01-24 08:21:49 -080011546 * only enable it on 6bpc panels and when its not a compliance
11547 * test requesting 6bpc video pattern.
11548 */
11549 pipe_config->dither = (pipe_config->pipe_bpp == 6*3) &&
11550 !pipe_config->dither_force_disable;
Daniel Vetter62f0ace2015-08-26 18:57:26 +020011551 DRM_DEBUG_KMS("hw max bpp: %i, pipe bpp: %i, dithering: %i\n",
Daniel Vetterd328c9d2015-04-10 16:22:37 +020011552 base_bpp, pipe_config->pipe_bpp, pipe_config->dither);
Daniel Vetter4e53c2e2013-03-27 00:44:58 +010011553
Ville Syrjäläd26592c2018-11-07 23:35:21 +020011554 return 0;
Daniel Vetter7758a112012-07-08 19:40:39 +020011555}
11556
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011557static bool intel_fuzzy_clock_check(int clock1, int clock2)
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011558{
Ville Syrjälä3bd26262013-09-06 23:29:02 +030011559 int diff;
Jesse Barnesf1f644d2013-06-27 00:39:25 +030011560
11561 if (clock1 == clock2)
11562 return true;
11563
11564 if (!clock1 || !clock2)
11565 return false;
11566
11567 diff = abs(clock1 - clock2);
11568
11569 if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105)
11570 return true;
11571
11572 return false;
11573}
11574
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011575static bool
11576intel_compare_m_n(unsigned int m, unsigned int n,
11577 unsigned int m2, unsigned int n2,
11578 bool exact)
11579{
11580 if (m == m2 && n == n2)
11581 return true;
11582
11583 if (exact || !m || !n || !m2 || !n2)
11584 return false;
11585
11586 BUILD_BUG_ON(DATA_LINK_M_N_MASK > INT_MAX);
11587
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011588 if (n > n2) {
11589 while (n > n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011590 m2 <<= 1;
11591 n2 <<= 1;
11592 }
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011593 } else if (n < n2) {
11594 while (n < n2) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011595 m <<= 1;
11596 n <<= 1;
11597 }
11598 }
11599
Maarten Lankhorst31d10b52016-01-06 13:54:43 +010011600 if (n != n2)
11601 return false;
11602
11603 return intel_fuzzy_clock_check(m, m2);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011604}
11605
11606static bool
11607intel_compare_link_m_n(const struct intel_link_m_n *m_n,
11608 struct intel_link_m_n *m2_n2,
11609 bool adjust)
11610{
11611 if (m_n->tu == m2_n2->tu &&
11612 intel_compare_m_n(m_n->gmch_m, m_n->gmch_n,
11613 m2_n2->gmch_m, m2_n2->gmch_n, !adjust) &&
11614 intel_compare_m_n(m_n->link_m, m_n->link_n,
11615 m2_n2->link_m, m2_n2->link_n, !adjust)) {
11616 if (adjust)
11617 *m2_n2 = *m_n;
11618
11619 return true;
11620 }
11621
11622 return false;
11623}
11624
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011625static void __printf(3, 4)
11626pipe_config_err(bool adjust, const char *name, const char *format, ...)
11627{
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011628 struct va_format vaf;
11629 va_list args;
11630
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011631 va_start(args, format);
11632 vaf.fmt = format;
11633 vaf.va = &args;
11634
Joe Perches99a95482018-03-13 15:02:15 -070011635 if (adjust)
11636 drm_dbg(DRM_UT_KMS, "mismatch in %s %pV", name, &vaf);
11637 else
11638 drm_err("mismatch in %s %pV", name, &vaf);
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011639
11640 va_end(args);
11641}
11642
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011643static bool
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011644intel_pipe_config_compare(struct drm_i915_private *dev_priv,
Ander Conselvan de Oliveira5cec2582015-01-15 14:55:21 +020011645 struct intel_crtc_state *current_config,
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011646 struct intel_crtc_state *pipe_config,
11647 bool adjust)
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011648{
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011649 bool ret = true;
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011650 bool fixup_inherited = adjust &&
11651 (current_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED) &&
11652 !(pipe_config->base.mode.private_flags & I915_MODE_FLAG_INHERITED);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011653
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011654#define PIPE_CONF_CHECK_X(name) do { \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011655 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011656 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter66e985c2013-06-05 13:34:20 +020011657 "(expected 0x%08x, found 0x%08x)\n", \
11658 current_config->name, \
11659 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011660 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011661 } \
11662} while (0)
Daniel Vetter66e985c2013-06-05 13:34:20 +020011663
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011664#define PIPE_CONF_CHECK_I(name) do { \
Daniel Vetter08a24032013-04-19 11:25:34 +020011665 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011666 pipe_config_err(adjust, __stringify(name), \
Daniel Vetter08a24032013-04-19 11:25:34 +020011667 "(expected %i, found %i)\n", \
11668 current_config->name, \
11669 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011670 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011671 } \
11672} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011673
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011674#define PIPE_CONF_CHECK_BOOL(name) do { \
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011675 if (current_config->name != pipe_config->name) { \
11676 pipe_config_err(adjust, __stringify(name), \
11677 "(expected %s, found %s)\n", \
11678 yesno(current_config->name), \
11679 yesno(pipe_config->name)); \
11680 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011681 } \
11682} while (0)
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011683
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011684/*
11685 * Checks state where we only read out the enabling, but not the entire
11686 * state itself (like full infoframes or ELD for audio). These states
11687 * require a full modeset on bootup to fix up.
11688 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011689#define PIPE_CONF_CHECK_BOOL_INCOMPLETE(name) do { \
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011690 if (!fixup_inherited || (!current_config->name && !pipe_config->name)) { \
11691 PIPE_CONF_CHECK_BOOL(name); \
11692 } else { \
11693 pipe_config_err(adjust, __stringify(name), \
11694 "unable to verify whether state matches exactly, forcing modeset (expected %s, found %s)\n", \
11695 yesno(current_config->name), \
11696 yesno(pipe_config->name)); \
11697 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011698 } \
11699} while (0)
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011700
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011701#define PIPE_CONF_CHECK_P(name) do { \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011702 if (current_config->name != pipe_config->name) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011703 pipe_config_err(adjust, __stringify(name), \
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011704 "(expected %p, found %p)\n", \
11705 current_config->name, \
11706 pipe_config->name); \
11707 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011708 } \
11709} while (0)
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011710
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011711#define PIPE_CONF_CHECK_M_N(name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011712 if (!intel_compare_link_m_n(&current_config->name, \
11713 &pipe_config->name,\
11714 adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011715 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011716 "(expected tu %i gmch %i/%i link %i/%i, " \
11717 "found tu %i, gmch %i/%i link %i/%i)\n", \
11718 current_config->name.tu, \
11719 current_config->name.gmch_m, \
11720 current_config->name.gmch_n, \
11721 current_config->name.link_m, \
11722 current_config->name.link_n, \
11723 pipe_config->name.tu, \
11724 pipe_config->name.gmch_m, \
11725 pipe_config->name.gmch_n, \
11726 pipe_config->name.link_m, \
11727 pipe_config->name.link_n); \
11728 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011729 } \
11730} while (0)
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011731
Daniel Vetter55c561a2016-03-30 11:34:36 +020011732/* This is required for BDW+ where there is only one set of registers for
11733 * switching between high and low RR.
11734 * This macro can be used whenever a comparison has to be made between one
11735 * hw state and multiple sw state variables.
11736 */
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011737#define PIPE_CONF_CHECK_M_N_ALT(name, alt_name) do { \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011738 if (!intel_compare_link_m_n(&current_config->name, \
11739 &pipe_config->name, adjust) && \
11740 !intel_compare_link_m_n(&current_config->alt_name, \
11741 &pipe_config->name, adjust)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011742 pipe_config_err(adjust, __stringify(name), \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011743 "(expected tu %i gmch %i/%i link %i/%i, " \
11744 "or tu %i gmch %i/%i link %i/%i, " \
11745 "found tu %i, gmch %i/%i link %i/%i)\n", \
11746 current_config->name.tu, \
11747 current_config->name.gmch_m, \
11748 current_config->name.gmch_n, \
11749 current_config->name.link_m, \
11750 current_config->name.link_n, \
11751 current_config->alt_name.tu, \
11752 current_config->alt_name.gmch_m, \
11753 current_config->alt_name.gmch_n, \
11754 current_config->alt_name.link_m, \
11755 current_config->alt_name.link_n, \
11756 pipe_config->name.tu, \
11757 pipe_config->name.gmch_m, \
11758 pipe_config->name.gmch_n, \
11759 pipe_config->name.link_m, \
11760 pipe_config->name.link_n); \
11761 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011762 } \
11763} while (0)
Daniel Vetter88adfff2013-03-28 10:42:01 +010011764
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011765#define PIPE_CONF_CHECK_FLAGS(name, mask) do { \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011766 if ((current_config->name ^ pipe_config->name) & (mask)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011767 pipe_config_err(adjust, __stringify(name), \
11768 "(%x) (expected %i, found %i)\n", \
11769 (mask), \
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011770 current_config->name & (mask), \
11771 pipe_config->name & (mask)); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011772 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011773 } \
11774} while (0)
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011775
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011776#define PIPE_CONF_CHECK_CLOCK_FUZZY(name) do { \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011777 if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \
Tvrtko Ursulin4e8048f2016-12-06 10:50:20 +000011778 pipe_config_err(adjust, __stringify(name), \
Ville Syrjälä5e550652013-09-06 23:29:07 +030011779 "(expected %i, found %i)\n", \
11780 current_config->name, \
11781 pipe_config->name); \
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011782 ret = false; \
Ville Syrjäläeadd2722018-03-16 20:36:25 +020011783 } \
11784} while (0)
Ville Syrjälä5e550652013-09-06 23:29:07 +030011785
Daniel Vetterbb760062013-06-06 14:55:52 +020011786#define PIPE_CONF_QUIRK(quirk) \
11787 ((current_config->quirks | pipe_config->quirks) & (quirk))
11788
Daniel Vettereccb1402013-05-22 00:50:22 +020011789 PIPE_CONF_CHECK_I(cpu_transcoder);
11790
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011791 PIPE_CONF_CHECK_BOOL(has_pch_encoder);
Daniel Vetter08a24032013-04-19 11:25:34 +020011792 PIPE_CONF_CHECK_I(fdi_lanes);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011793 PIPE_CONF_CHECK_M_N(fdi_m_n);
Daniel Vetter08a24032013-04-19 11:25:34 +020011794
Ville Syrjälä90a6b7b2015-07-06 16:39:15 +030011795 PIPE_CONF_CHECK_I(lane_count);
Imre Deak95a7a2a2016-06-13 16:44:35 +030011796 PIPE_CONF_CHECK_X(lane_lat_optim_mask);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011797
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011798 if (INTEL_GEN(dev_priv) < 8) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011799 PIPE_CONF_CHECK_M_N(dp_m_n);
Vandana Kannanb95af8b2014-08-05 07:51:23 -070011800
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011801 if (current_config->has_drrs)
11802 PIPE_CONF_CHECK_M_N(dp_m2_n2);
11803 } else
11804 PIPE_CONF_CHECK_M_N_ALT(dp_m_n, dp_m2_n2);
Ville Syrjäläeb14cb72013-09-10 17:02:54 +030011805
Ville Syrjälä253c84c2016-06-22 21:57:01 +030011806 PIPE_CONF_CHECK_X(output_types);
Jani Nikulaa65347b2015-11-27 12:21:46 +020011807
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011808 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay);
11809 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal);
11810 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start);
11811 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end);
11812 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start);
11813 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011814
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011815 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay);
11816 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal);
11817 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start);
11818 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end);
11819 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start);
11820 PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end);
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011821
Daniel Vetterc93f54c2013-06-27 19:47:19 +020011822 PIPE_CONF_CHECK_I(pixel_multiplier);
Shashank Sharmad9facae2018-10-12 11:53:07 +053011823 PIPE_CONF_CHECK_I(output_format);
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011824 PIPE_CONF_CHECK_BOOL(has_hdmi_sink);
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010011825 if ((INTEL_GEN(dev_priv) < 8 && !IS_HASWELL(dev_priv)) ||
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010011826 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011827 PIPE_CONF_CHECK_BOOL(limited_color_range);
Shashank Sharma15953632017-03-13 16:54:03 +053011828
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011829 PIPE_CONF_CHECK_BOOL(hdmi_scrambling);
11830 PIPE_CONF_CHECK_BOOL(hdmi_high_tmds_clock_ratio);
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011831 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_infoframe);
Daniel Vetter6c49f242013-06-06 12:45:25 +020011832
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011833 PIPE_CONF_CHECK_BOOL_INCOMPLETE(has_audio);
Daniel Vetter9ed109a2014-04-24 23:54:52 +020011834
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011835 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011836 DRM_MODE_FLAG_INTERLACE);
11837
Daniel Vetterbb760062013-06-06 14:55:52 +020011838 if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) {
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011839 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011840 DRM_MODE_FLAG_PHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011841 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011842 DRM_MODE_FLAG_NHSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011843 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011844 DRM_MODE_FLAG_PVSYNC);
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011845 PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags,
Daniel Vetterbb760062013-06-06 14:55:52 +020011846 DRM_MODE_FLAG_NVSYNC);
11847 }
Jesse Barnes045ac3b2013-05-14 17:08:26 -070011848
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011849 PIPE_CONF_CHECK_X(gmch_pfit.control);
Daniel Vettere2ff2d42015-07-15 14:15:50 +020011850 /* pfit ratios are autocomputed by the hw on gen4+ */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011851 if (INTEL_GEN(dev_priv) < 4)
Ville Syrjälä7f7d8dd2016-03-15 16:40:07 +020011852 PIPE_CONF_CHECK_X(gmch_pfit.pgm_ratios);
Ville Syrjälä333b8ca2015-09-03 21:50:16 +030011853 PIPE_CONF_CHECK_X(gmch_pfit.lvds_border_bits);
Daniel Vetter99535992014-04-13 12:00:33 +020011854
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011855 if (!adjust) {
11856 PIPE_CONF_CHECK_I(pipe_src_w);
11857 PIPE_CONF_CHECK_I(pipe_src_h);
11858
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011859 PIPE_CONF_CHECK_BOOL(pch_pfit.enabled);
Maarten Lankhorstbfd16b22015-08-27 15:44:05 +020011860 if (current_config->pch_pfit.enabled) {
11861 PIPE_CONF_CHECK_X(pch_pfit.pos);
11862 PIPE_CONF_CHECK_X(pch_pfit.size);
11863 }
Daniel Vetter2fa2fe92013-05-07 23:34:16 +020011864
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011865 PIPE_CONF_CHECK_I(scaler_state.scaler_id);
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020011866 PIPE_CONF_CHECK_CLOCK_FUZZY(pixel_rate);
Maarten Lankhorst7aefe2b2015-09-14 11:30:10 +020011867 }
Chandra Kondurua1b22782015-04-07 15:28:45 -070011868
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011869 PIPE_CONF_CHECK_BOOL(double_wide);
Ville Syrjälä282740f2013-09-04 18:30:03 +030011870
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011871 PIPE_CONF_CHECK_P(shared_dpll);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011872 PIPE_CONF_CHECK_X(dpll_hw_state.dpll);
Daniel Vetter8bcc2792013-06-05 13:34:28 +020011873 PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md);
Daniel Vetter66e985c2013-06-05 13:34:20 +020011874 PIPE_CONF_CHECK_X(dpll_hw_state.fp0);
11875 PIPE_CONF_CHECK_X(dpll_hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -030011876 PIPE_CONF_CHECK_X(dpll_hw_state.wrpll);
Maarten Lankhorst00490c22015-11-16 14:42:12 +010011877 PIPE_CONF_CHECK_X(dpll_hw_state.spll);
Damien Lespiau3f4cd192014-11-13 14:55:21 +000011878 PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1);
11879 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1);
11880 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2);
Paulo Zanoni2de38132017-09-22 17:53:42 -030011881 PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr0);
11882 PIPE_CONF_CHECK_X(dpll_hw_state.ebb0);
11883 PIPE_CONF_CHECK_X(dpll_hw_state.ebb4);
11884 PIPE_CONF_CHECK_X(dpll_hw_state.pll0);
11885 PIPE_CONF_CHECK_X(dpll_hw_state.pll1);
11886 PIPE_CONF_CHECK_X(dpll_hw_state.pll2);
11887 PIPE_CONF_CHECK_X(dpll_hw_state.pll3);
11888 PIPE_CONF_CHECK_X(dpll_hw_state.pll6);
11889 PIPE_CONF_CHECK_X(dpll_hw_state.pll8);
11890 PIPE_CONF_CHECK_X(dpll_hw_state.pll9);
11891 PIPE_CONF_CHECK_X(dpll_hw_state.pll10);
11892 PIPE_CONF_CHECK_X(dpll_hw_state.pcsdw12);
Paulo Zanonic27e9172018-04-27 16:14:36 -070011893 PIPE_CONF_CHECK_X(dpll_hw_state.mg_refclkin_ctl);
11894 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_coreclkctl1);
11895 PIPE_CONF_CHECK_X(dpll_hw_state.mg_clktop2_hsclkctl);
11896 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div0);
11897 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_div1);
11898 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_lf);
11899 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_frac_lock);
11900 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_ssc);
11901 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_bias);
11902 PIPE_CONF_CHECK_X(dpll_hw_state.mg_pll_tdc_coldst_bias);
Daniel Vetterc0d43d62013-06-07 23:11:08 +020011903
Ville Syrjälä47eacba2016-04-12 22:14:35 +030011904 PIPE_CONF_CHECK_X(dsi_pll.ctrl);
11905 PIPE_CONF_CHECK_X(dsi_pll.div);
11906
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010011907 if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5)
Ville Syrjälä42571ae2013-09-06 23:29:00 +030011908 PIPE_CONF_CHECK_I(pipe_bpp);
11909
Ander Conselvan de Oliveira2d112de2015-01-15 14:55:22 +020011910 PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock);
Jesse Barnesa9a7e982014-01-20 14:18:04 -080011911 PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock);
Ville Syrjälä5e550652013-09-06 23:29:07 +030011912
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030011913 PIPE_CONF_CHECK_I(min_voltage_level);
11914
Daniel Vetter66e985c2013-06-05 13:34:20 +020011915#undef PIPE_CONF_CHECK_X
Daniel Vetter08a24032013-04-19 11:25:34 +020011916#undef PIPE_CONF_CHECK_I
Maarten Lankhorstd640bf72017-11-10 12:34:55 +010011917#undef PIPE_CONF_CHECK_BOOL
Maarten Lankhorst4493e092017-11-10 12:34:56 +010011918#undef PIPE_CONF_CHECK_BOOL_INCOMPLETE
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020011919#undef PIPE_CONF_CHECK_P
Daniel Vetter1bd1bd82013-04-29 21:56:12 +020011920#undef PIPE_CONF_CHECK_FLAGS
Ville Syrjälä5e550652013-09-06 23:29:07 +030011921#undef PIPE_CONF_CHECK_CLOCK_FUZZY
Daniel Vetterbb760062013-06-06 14:55:52 +020011922#undef PIPE_CONF_QUIRK
Daniel Vetter627eb5a2013-04-29 19:33:42 +020011923
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020011924 return ret;
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010011925}
11926
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011927static void intel_pipe_config_sanity_check(struct drm_i915_private *dev_priv,
11928 const struct intel_crtc_state *pipe_config)
11929{
11930 if (pipe_config->has_pch_encoder) {
Ville Syrjälä21a727b2016-02-17 21:41:10 +020011931 int fdi_dotclock = intel_dotclock_calculate(intel_fdi_link_freq(dev_priv, pipe_config),
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020011932 &pipe_config->fdi_m_n);
11933 int dotclock = pipe_config->base.adjusted_mode.crtc_clock;
11934
11935 /*
11936 * FDI already provided one idea for the dotclock.
11937 * Yell if the encoder disagrees.
11938 */
11939 WARN(!intel_fuzzy_clock_check(fdi_dotclock, dotclock),
11940 "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n",
11941 fdi_dotclock, dotclock);
11942 }
11943}
11944
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020011945static void verify_wm_state(struct drm_crtc *crtc,
11946 struct drm_crtc_state *new_state)
Damien Lespiau08db6652014-11-04 17:06:52 +000011947{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011948 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
Damien Lespiau08db6652014-11-04 17:06:52 +000011949 struct skl_ddb_allocation hw_ddb, *sw_ddb;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011950 struct skl_pipe_wm hw_wm, *sw_wm;
11951 struct skl_plane_wm *hw_plane_wm, *sw_plane_wm;
11952 struct skl_ddb_entry *hw_ddb_entry, *sw_ddb_entry;
Ville Syrjäläff43bc32018-11-27 18:59:00 +020011953 struct skl_ddb_entry hw_ddb_y[I915_MAX_PLANES];
11954 struct skl_ddb_entry hw_ddb_uv[I915_MAX_PLANES];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011955 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11956 const enum pipe pipe = intel_crtc->pipe;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011957 int plane, level, max_level = ilk_wm_max_level(dev_priv);
Damien Lespiau08db6652014-11-04 17:06:52 +000011958
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000011959 if (INTEL_GEN(dev_priv) < 9 || !new_state->active)
Damien Lespiau08db6652014-11-04 17:06:52 +000011960 return;
11961
Matt Ropercd1d3ee2018-12-10 13:54:14 -080011962 skl_pipe_wm_get_hw_state(intel_crtc, &hw_wm);
Maarten Lankhorst03af79e2016-10-26 15:41:36 +020011963 sw_wm = &to_intel_crtc_state(new_state)->wm.skl.optimal;
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011964
Ville Syrjäläff43bc32018-11-27 18:59:00 +020011965 skl_pipe_ddb_get_hw_state(intel_crtc, hw_ddb_y, hw_ddb_uv);
11966
Damien Lespiau08db6652014-11-04 17:06:52 +000011967 skl_ddb_get_hw_state(dev_priv, &hw_ddb);
11968 sw_ddb = &dev_priv->wm.skl_hw.ddb;
11969
Mahesh Kumar74bd8002018-04-26 19:55:15 +053011970 if (INTEL_GEN(dev_priv) >= 11)
11971 if (hw_ddb.enabled_slices != sw_ddb->enabled_slices)
11972 DRM_ERROR("mismatch in DBUF Slices (expected %u, got %u)\n",
11973 sw_ddb->enabled_slices,
11974 hw_ddb.enabled_slices);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010011975 /* planes */
Matt Roper8b364b42016-10-26 15:51:28 -070011976 for_each_universal_plane(dev_priv, pipe, plane) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011977 hw_plane_wm = &hw_wm.planes[plane];
11978 sw_plane_wm = &sw_wm->planes[plane];
Damien Lespiau08db6652014-11-04 17:06:52 +000011979
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011980 /* Watermarks */
11981 for (level = 0; level <= max_level; level++) {
11982 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
11983 &sw_plane_wm->wm[level]))
11984 continue;
Damien Lespiau08db6652014-11-04 17:06:52 +000011985
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040011986 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",
11987 pipe_name(pipe), plane + 1, level,
11988 sw_plane_wm->wm[level].plane_en,
11989 sw_plane_wm->wm[level].plane_res_b,
11990 sw_plane_wm->wm[level].plane_res_l,
11991 hw_plane_wm->wm[level].plane_en,
11992 hw_plane_wm->wm[level].plane_res_b,
11993 hw_plane_wm->wm[level].plane_res_l);
11994 }
11995
11996 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
11997 &sw_plane_wm->trans_wm)) {
11998 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",
11999 pipe_name(pipe), plane + 1,
12000 sw_plane_wm->trans_wm.plane_en,
12001 sw_plane_wm->trans_wm.plane_res_b,
12002 sw_plane_wm->trans_wm.plane_res_l,
12003 hw_plane_wm->trans_wm.plane_en,
12004 hw_plane_wm->trans_wm.plane_res_b,
12005 hw_plane_wm->trans_wm.plane_res_l);
12006 }
12007
12008 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012009 hw_ddb_entry = &hw_ddb_y[plane];
12010 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[plane];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012011
12012 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012013 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 -040012014 pipe_name(pipe), plane + 1,
12015 sw_ddb_entry->start, sw_ddb_entry->end,
12016 hw_ddb_entry->start, hw_ddb_entry->end);
12017 }
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012018 }
12019
Lyude27082492016-08-24 07:48:10 +020012020 /*
12021 * cursor
12022 * If the cursor plane isn't active, we may not have updated it's ddb
12023 * allocation. In that case since the ddb allocation will be updated
12024 * once the plane becomes visible, we can skip this check
12025 */
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030012026 if (1) {
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012027 hw_plane_wm = &hw_wm.planes[PLANE_CURSOR];
12028 sw_plane_wm = &sw_wm->planes[PLANE_CURSOR];
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012029
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012030 /* Watermarks */
12031 for (level = 0; level <= max_level; level++) {
12032 if (skl_wm_level_equals(&hw_plane_wm->wm[level],
12033 &sw_plane_wm->wm[level]))
12034 continue;
12035
12036 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",
12037 pipe_name(pipe), level,
12038 sw_plane_wm->wm[level].plane_en,
12039 sw_plane_wm->wm[level].plane_res_b,
12040 sw_plane_wm->wm[level].plane_res_l,
12041 hw_plane_wm->wm[level].plane_en,
12042 hw_plane_wm->wm[level].plane_res_b,
12043 hw_plane_wm->wm[level].plane_res_l);
12044 }
12045
12046 if (!skl_wm_level_equals(&hw_plane_wm->trans_wm,
12047 &sw_plane_wm->trans_wm)) {
12048 DRM_ERROR("mismatch in trans WM pipe %c cursor (expected e=%d b=%u l=%u, got e=%d b=%u l=%u)\n",
12049 pipe_name(pipe),
12050 sw_plane_wm->trans_wm.plane_en,
12051 sw_plane_wm->trans_wm.plane_res_b,
12052 sw_plane_wm->trans_wm.plane_res_l,
12053 hw_plane_wm->trans_wm.plane_en,
12054 hw_plane_wm->trans_wm.plane_res_b,
12055 hw_plane_wm->trans_wm.plane_res_l);
12056 }
12057
12058 /* DDB */
Ville Syrjäläff43bc32018-11-27 18:59:00 +020012059 hw_ddb_entry = &hw_ddb_y[PLANE_CURSOR];
12060 sw_ddb_entry = &to_intel_crtc_state(new_state)->wm.skl.plane_ddb_y[PLANE_CURSOR];
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012061
12062 if (!skl_ddb_entry_equal(hw_ddb_entry, sw_ddb_entry)) {
cpaul@redhat.comfaccd992016-10-14 17:31:58 -040012063 DRM_ERROR("mismatch in DDB state pipe %c cursor (expected (%u,%u), found (%u,%u))\n",
Lyude27082492016-08-24 07:48:10 +020012064 pipe_name(pipe),
cpaul@redhat.com3de8a142016-10-14 17:31:57 -040012065 sw_ddb_entry->start, sw_ddb_entry->end,
12066 hw_ddb_entry->start, hw_ddb_entry->end);
Lyude27082492016-08-24 07:48:10 +020012067 }
Damien Lespiau08db6652014-11-04 17:06:52 +000012068 }
12069}
12070
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012071static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012072verify_connector_state(struct drm_device *dev,
12073 struct drm_atomic_state *state,
12074 struct drm_crtc *crtc)
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012075{
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012076 struct drm_connector *connector;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012077 struct drm_connector_state *new_conn_state;
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012078 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012079
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012080 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012081 struct drm_encoder *encoder = connector->encoder;
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012082 struct drm_crtc_state *crtc_state = NULL;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012083
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012084 if (new_conn_state->crtc != crtc)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012085 continue;
12086
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012087 if (crtc)
12088 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc);
12089
12090 intel_connector_verify_state(crtc_state, new_conn_state);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012091
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012092 I915_STATE_WARN(new_conn_state->best_encoder != encoder,
Maarten Lankhorst35dd3c62015-08-06 13:49:22 +020012093 "connector's atomic encoder doesn't match legacy encoder\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012094 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012095}
12096
12097static void
Daniel Vetter86b04262017-03-01 10:52:26 +010012098verify_encoder_state(struct drm_device *dev, struct drm_atomic_state *state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012099{
12100 struct intel_encoder *encoder;
Daniel Vetter86b04262017-03-01 10:52:26 +010012101 struct drm_connector *connector;
12102 struct drm_connector_state *old_conn_state, *new_conn_state;
12103 int i;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012104
Damien Lespiaub2784e12014-08-05 11:29:37 +010012105 for_each_intel_encoder(dev, encoder) {
Daniel Vetter86b04262017-03-01 10:52:26 +010012106 bool enabled = false, found = false;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012107 enum pipe pipe;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012108
12109 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
12110 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030012111 encoder->base.name);
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012112
Daniel Vetter86b04262017-03-01 10:52:26 +010012113 for_each_oldnew_connector_in_state(state, connector, old_conn_state,
12114 new_conn_state, i) {
12115 if (old_conn_state->best_encoder == &encoder->base)
12116 found = true;
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012117
Daniel Vetter86b04262017-03-01 10:52:26 +010012118 if (new_conn_state->best_encoder != &encoder->base)
12119 continue;
12120 found = enabled = true;
12121
12122 I915_STATE_WARN(new_conn_state->crtc !=
Maarten Lankhorstad3c5582015-07-13 16:30:26 +020012123 encoder->base.crtc,
12124 "connector's crtc doesn't match encoder crtc\n");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012125 }
Daniel Vetter86b04262017-03-01 10:52:26 +010012126
12127 if (!found)
12128 continue;
Dave Airlie0e32b392014-05-02 14:02:48 +100012129
Rob Clarke2c719b2014-12-15 13:56:32 -050012130 I915_STATE_WARN(!!encoder->base.crtc != enabled,
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012131 "encoder's enabled state mismatch "
12132 "(expected %i, found %i)\n",
12133 !!encoder->base.crtc, enabled);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012134
12135 if (!encoder->base.crtc) {
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012136 bool active;
12137
12138 active = encoder->get_hw_state(encoder, &pipe);
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012139 I915_STATE_WARN(active,
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012140 "encoder detached but still enabled on pipe %c.\n",
12141 pipe_name(pipe));
Maarten Lankhorst7c60d192015-08-05 12:37:04 +020012142 }
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012143 }
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012144}
12145
12146static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012147verify_crtc_state(struct drm_crtc *crtc,
12148 struct drm_crtc_state *old_crtc_state,
12149 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012150{
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012151 struct drm_device *dev = crtc->dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010012152 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012153 struct intel_encoder *encoder;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012154 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
12155 struct intel_crtc_state *pipe_config, *sw_config;
12156 struct drm_atomic_state *old_state;
12157 bool active;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012158
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012159 old_state = old_crtc_state->state;
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020012160 __drm_atomic_helper_crtc_destroy_state(old_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012161 pipe_config = to_intel_crtc_state(old_crtc_state);
12162 memset(pipe_config, 0, sizeof(*pipe_config));
12163 pipe_config->base.crtc = crtc;
12164 pipe_config->base.state = old_state;
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012165
Ville Syrjälä78108b72016-05-27 20:59:19 +030012166 DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name);
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012167
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012168 active = dev_priv->display.get_pipe_config(intel_crtc, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012169
Ville Syrjäläe56134b2017-06-01 17:36:19 +030012170 /* we keep both pipes enabled on 830 */
12171 if (IS_I830(dev_priv))
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012172 active = new_crtc_state->active;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012173
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012174 I915_STATE_WARN(new_crtc_state->active != active,
12175 "crtc active state doesn't match with hw state "
12176 "(expected %i, found %i)\n", new_crtc_state->active, active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012177
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012178 I915_STATE_WARN(intel_crtc->active != new_crtc_state->active,
12179 "transitional active state does not match atomic hw state "
12180 "(expected %i, found %i)\n", new_crtc_state->active, intel_crtc->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012181
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012182 for_each_encoder_on_crtc(dev, crtc, encoder) {
12183 enum pipe pipe;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012184
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012185 active = encoder->get_hw_state(encoder, &pipe);
12186 I915_STATE_WARN(active != new_crtc_state->active,
12187 "[ENCODER:%i] active %i with crtc active %i\n",
12188 encoder->base.base.id, active, new_crtc_state->active);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012189
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012190 I915_STATE_WARN(active && intel_crtc->pipe != pipe,
12191 "Encoder connected to wrong pipe %c\n",
12192 pipe_name(pipe));
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012193
Ville Syrjäläe1214b92017-10-27 22:31:23 +030012194 if (active)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012195 encoder->get_config(encoder, pipe_config);
12196 }
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012197
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020012198 intel_crtc_compute_pixel_rate(pipe_config);
12199
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012200 if (!new_crtc_state->active)
12201 return;
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012202
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012203 intel_pipe_config_sanity_check(dev_priv, pipe_config);
Maarten Lankhorst4d20cd82015-08-05 12:37:05 +020012204
Maarten Lankhorst749d98b2017-05-11 10:28:43 +020012205 sw_config = to_intel_crtc_state(new_crtc_state);
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012206 if (!intel_pipe_config_compare(dev_priv, sw_config,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012207 pipe_config, false)) {
12208 I915_STATE_WARN(1, "pipe state doesn't match!\n");
12209 intel_dump_pipe_config(intel_crtc, pipe_config,
12210 "[hw state]");
12211 intel_dump_pipe_config(intel_crtc, sw_config,
12212 "[sw state]");
Daniel Vetter8af6cf82012-07-10 09:50:11 +020012213 }
12214}
12215
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012216static void
Ville Syrjäläcff109f2017-11-17 21:19:17 +020012217intel_verify_planes(struct intel_atomic_state *state)
12218{
12219 struct intel_plane *plane;
12220 const struct intel_plane_state *plane_state;
12221 int i;
12222
12223 for_each_new_intel_plane_in_state(state, plane,
12224 plane_state, i)
12225 assert_plane(plane, plane_state->base.visible);
12226}
12227
12228static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012229verify_single_dpll_state(struct drm_i915_private *dev_priv,
12230 struct intel_shared_dpll *pll,
12231 struct drm_crtc *crtc,
12232 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012233{
12234 struct intel_dpll_hw_state dpll_hw_state;
Ville Syrjälä40560e22018-06-26 22:47:11 +030012235 unsigned int crtc_mask;
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012236 bool active;
12237
12238 memset(&dpll_hw_state, 0, sizeof(dpll_hw_state));
12239
Lucas De Marchi72f775f2018-03-20 15:06:34 -070012240 DRM_DEBUG_KMS("%s\n", pll->info->name);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012241
Lucas De Marchiee1398b2018-03-20 15:06:33 -070012242 active = pll->info->funcs->get_hw_state(dev_priv, pll, &dpll_hw_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012243
Lucas De Marchi5cd281f2018-03-20 15:06:36 -070012244 if (!(pll->info->flags & INTEL_DPLL_ALWAYS_ON)) {
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012245 I915_STATE_WARN(!pll->on && pll->active_mask,
12246 "pll in active use but not on in sw tracking\n");
12247 I915_STATE_WARN(pll->on && !pll->active_mask,
12248 "pll is on but not used by any active crtc\n");
12249 I915_STATE_WARN(pll->on != active,
12250 "pll on state mismatch (expected %i, found %i)\n",
12251 pll->on, active);
12252 }
12253
12254 if (!crtc) {
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012255 I915_STATE_WARN(pll->active_mask & ~pll->state.crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012256 "more active pll users than references: %x vs %x\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012257 pll->active_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012258
12259 return;
12260 }
12261
Ville Syrjälä40560e22018-06-26 22:47:11 +030012262 crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012263
12264 if (new_state->active)
12265 I915_STATE_WARN(!(pll->active_mask & crtc_mask),
12266 "pll active mismatch (expected pipe %c in active mask 0x%02x)\n",
12267 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12268 else
12269 I915_STATE_WARN(pll->active_mask & crtc_mask,
12270 "pll active mismatch (didn't expect pipe %c in active mask 0x%02x)\n",
12271 pipe_name(drm_crtc_index(crtc)), pll->active_mask);
12272
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012273 I915_STATE_WARN(!(pll->state.crtc_mask & crtc_mask),
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012274 "pll enabled crtcs mismatch (expected 0x%x in 0x%02x)\n",
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012275 crtc_mask, pll->state.crtc_mask);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012276
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012277 I915_STATE_WARN(pll->on && memcmp(&pll->state.hw_state,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012278 &dpll_hw_state,
12279 sizeof(dpll_hw_state)),
12280 "pll hw state mismatch\n");
12281}
12282
12283static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012284verify_shared_dpll_state(struct drm_device *dev, struct drm_crtc *crtc,
12285 struct drm_crtc_state *old_crtc_state,
12286 struct drm_crtc_state *new_crtc_state)
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012287{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012288 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012289 struct intel_crtc_state *old_state = to_intel_crtc_state(old_crtc_state);
12290 struct intel_crtc_state *new_state = to_intel_crtc_state(new_crtc_state);
12291
12292 if (new_state->shared_dpll)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012293 verify_single_dpll_state(dev_priv, new_state->shared_dpll, crtc, new_crtc_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012294
12295 if (old_state->shared_dpll &&
12296 old_state->shared_dpll != new_state->shared_dpll) {
Ville Syrjälä40560e22018-06-26 22:47:11 +030012297 unsigned int crtc_mask = drm_crtc_mask(crtc);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012298 struct intel_shared_dpll *pll = old_state->shared_dpll;
12299
12300 I915_STATE_WARN(pll->active_mask & crtc_mask,
12301 "pll active mismatch (didn't expect pipe %c in active mask)\n",
12302 pipe_name(drm_crtc_index(crtc)));
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020012303 I915_STATE_WARN(pll->state.crtc_mask & crtc_mask,
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012304 "pll enabled crtcs mismatch (found %x in enabled mask)\n",
12305 pipe_name(drm_crtc_index(crtc)));
12306 }
12307}
12308
12309static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012310intel_modeset_verify_crtc(struct drm_crtc *crtc,
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012311 struct drm_atomic_state *state,
12312 struct drm_crtc_state *old_state,
12313 struct drm_crtc_state *new_state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012314{
Daniel Vetter5a21b662016-05-24 17:13:53 +020012315 if (!needs_modeset(new_state) &&
12316 !to_intel_crtc_state(new_state)->update_pipe)
12317 return;
12318
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012319 verify_wm_state(crtc, new_state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012320 verify_connector_state(crtc->dev, state, crtc);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012321 verify_crtc_state(crtc, old_state, new_state);
12322 verify_shared_dpll_state(crtc->dev, crtc, old_state, new_state);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012323}
12324
12325static void
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012326verify_disabled_dpll_state(struct drm_device *dev)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012327{
Chris Wilsonfac5e232016-07-04 11:34:36 +010012328 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter91d1b4b2013-06-05 13:34:18 +020012329 int i;
Daniel Vetter53589012013-06-05 13:34:16 +020012330
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012331 for (i = 0; i < dev_priv->num_shared_dpll; i++)
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012332 verify_single_dpll_state(dev_priv, &dev_priv->shared_dplls[i], NULL, NULL);
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012333}
Daniel Vetter53589012013-06-05 13:34:16 +020012334
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012335static void
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012336intel_modeset_verify_disabled(struct drm_device *dev,
12337 struct drm_atomic_state *state)
Maarten Lankhorste7c84542016-03-23 14:58:06 +010012338{
Daniel Vetter86b04262017-03-01 10:52:26 +010012339 verify_encoder_state(dev, state);
Maarten Lankhorst677100c2016-11-08 13:55:41 +010012340 verify_connector_state(dev, state, NULL);
Maarten Lankhorstc0ead702016-03-30 10:00:05 +020012341 verify_disabled_dpll_state(dev);
Daniel Vetter25c5b262012-07-08 22:08:04 +020012342}
12343
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012344static void update_scanline_offset(const struct intel_crtc_state *crtc_state)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012345{
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012346 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012347 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjälä80715b22014-05-15 20:23:23 +030012348
12349 /*
12350 * The scanline counter increments at the leading edge of hsync.
12351 *
12352 * On most platforms it starts counting from vtotal-1 on the
12353 * first active line. That means the scanline counter value is
12354 * always one less than what we would expect. Ie. just after
12355 * start of vblank, which also occurs at start of hsync (on the
12356 * last active line), the scanline counter will read vblank_start-1.
12357 *
12358 * On gen2 the scanline counter starts counting from 1 instead
12359 * of vtotal-1, so we have to subtract one (or rather add vtotal-1
12360 * to keep the value positive), instead of adding one.
12361 *
12362 * On HSW+ the behaviour of the scanline counter depends on the output
12363 * type. For DP ports it behaves like most other platforms, but on HDMI
12364 * there's an extra 1 line difference. So we need to add two instead of
12365 * one to the value.
Ville Syrjäläec1b4ee2016-12-15 19:47:34 +020012366 *
12367 * On VLV/CHV DSI the scanline counter would appear to increment
12368 * approx. 1/3 of a scanline before start of vblank. Unfortunately
12369 * that means we can't tell whether we're in vblank or not while
12370 * we're on that particular line. We must still set scanline_offset
12371 * to 1 so that the vblank timestamps come out correct when we query
12372 * the scanline counter from within the vblank interrupt handler.
12373 * However if queried just before the start of vblank we'll get an
12374 * answer that's slightly in the future.
Ville Syrjälä80715b22014-05-15 20:23:23 +030012375 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080012376 if (IS_GEN(dev_priv, 2)) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012377 const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
Ville Syrjälä80715b22014-05-15 20:23:23 +030012378 int vtotal;
12379
Ville Syrjälä124abe02015-09-08 13:40:45 +030012380 vtotal = adjusted_mode->crtc_vtotal;
12381 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
Ville Syrjälä80715b22014-05-15 20:23:23 +030012382 vtotal /= 2;
12383
12384 crtc->scanline_offset = vtotal - 1;
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010012385 } else if (HAS_DDI(dev_priv) &&
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012386 intel_crtc_has_type(crtc_state, INTEL_OUTPUT_HDMI)) {
Ville Syrjälä80715b22014-05-15 20:23:23 +030012387 crtc->scanline_offset = 2;
12388 } else
12389 crtc->scanline_offset = 1;
12390}
12391
Maarten Lankhorstad421372015-06-15 12:33:42 +020012392static void intel_modeset_clear_plls(struct drm_atomic_state *state)
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012393{
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012394 struct drm_device *dev = state->dev;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012395 struct drm_i915_private *dev_priv = to_i915(dev);
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012396 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012397 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012398 int i;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012399
12400 if (!dev_priv->display.crtc_compute_clock)
Maarten Lankhorstad421372015-06-15 12:33:42 +020012401 return;
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012402
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012403 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012404 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012405 struct intel_shared_dpll *old_dpll =
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012406 to_intel_crtc_state(old_crtc_state)->shared_dpll;
Maarten Lankhorstad421372015-06-15 12:33:42 +020012407
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012408 if (!needs_modeset(new_crtc_state))
Ander Conselvan de Oliveira225da592015-04-02 14:47:57 +030012409 continue;
12410
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012411 to_intel_crtc_state(new_crtc_state)->shared_dpll = NULL;
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012412
Ander Conselvan de Oliveira8106ddb2016-03-08 17:46:18 +020012413 if (!old_dpll)
Maarten Lankhorstfb1a38a2016-02-09 13:02:17 +010012414 continue;
Ander Conselvan de Oliveira0a9ab302015-04-21 17:13:04 +030012415
Ander Conselvan de Oliveiraa1c414e2016-12-29 17:22:07 +020012416 intel_release_shared_dpll(old_dpll, intel_crtc, state);
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012417 }
Ander Conselvan de Oliveiraed6739e2015-01-29 16:55:08 +020012418}
12419
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012420/*
12421 * This implements the workaround described in the "notes" section of the mode
12422 * set sequence documentation. When going from no pipes or single pipe to
12423 * multiple pipes, and planes are enabled after the pipe, we need to wait at
12424 * least 2 vblanks on the first pipe before enabling planes on the second pipe.
12425 */
12426static int haswell_mode_set_planes_workaround(struct drm_atomic_state *state)
12427{
12428 struct drm_crtc_state *crtc_state;
12429 struct intel_crtc *intel_crtc;
12430 struct drm_crtc *crtc;
12431 struct intel_crtc_state *first_crtc_state = NULL;
12432 struct intel_crtc_state *other_crtc_state = NULL;
12433 enum pipe first_pipe = INVALID_PIPE, enabled_pipe = INVALID_PIPE;
12434 int i;
12435
12436 /* look at all crtc's that are going to be enabled in during modeset */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012437 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012438 intel_crtc = to_intel_crtc(crtc);
12439
12440 if (!crtc_state->active || !needs_modeset(crtc_state))
12441 continue;
12442
12443 if (first_crtc_state) {
12444 other_crtc_state = to_intel_crtc_state(crtc_state);
12445 break;
12446 } else {
12447 first_crtc_state = to_intel_crtc_state(crtc_state);
12448 first_pipe = intel_crtc->pipe;
12449 }
12450 }
12451
12452 /* No workaround needed? */
12453 if (!first_crtc_state)
12454 return 0;
12455
12456 /* w/a possibly needed, check how many crtc's are already enabled. */
12457 for_each_intel_crtc(state->dev, intel_crtc) {
12458 struct intel_crtc_state *pipe_config;
12459
12460 pipe_config = intel_atomic_get_crtc_state(state, intel_crtc);
12461 if (IS_ERR(pipe_config))
12462 return PTR_ERR(pipe_config);
12463
12464 pipe_config->hsw_workaround_pipe = INVALID_PIPE;
12465
12466 if (!pipe_config->base.active ||
12467 needs_modeset(&pipe_config->base))
12468 continue;
12469
12470 /* 2 or more enabled crtcs means no need for w/a */
12471 if (enabled_pipe != INVALID_PIPE)
12472 return 0;
12473
12474 enabled_pipe = intel_crtc->pipe;
12475 }
12476
12477 if (enabled_pipe != INVALID_PIPE)
12478 first_crtc_state->hsw_workaround_pipe = enabled_pipe;
12479 else if (other_crtc_state)
12480 other_crtc_state->hsw_workaround_pipe = first_pipe;
12481
12482 return 0;
12483}
12484
Ville Syrjälä8d965612016-11-14 18:35:10 +020012485static int intel_lock_all_pipes(struct drm_atomic_state *state)
12486{
12487 struct drm_crtc *crtc;
12488
12489 /* Add all pipes to the state */
12490 for_each_crtc(state->dev, crtc) {
12491 struct drm_crtc_state *crtc_state;
12492
12493 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12494 if (IS_ERR(crtc_state))
12495 return PTR_ERR(crtc_state);
12496 }
12497
12498 return 0;
12499}
12500
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012501static int intel_modeset_all_pipes(struct drm_atomic_state *state)
12502{
12503 struct drm_crtc *crtc;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012504
Ville Syrjälä8d965612016-11-14 18:35:10 +020012505 /*
12506 * Add all pipes to the state, and force
12507 * a modeset on all the active ones.
12508 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012509 for_each_crtc(state->dev, crtc) {
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012510 struct drm_crtc_state *crtc_state;
12511 int ret;
12512
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012513 crtc_state = drm_atomic_get_crtc_state(state, crtc);
12514 if (IS_ERR(crtc_state))
12515 return PTR_ERR(crtc_state);
12516
12517 if (!crtc_state->active || needs_modeset(crtc_state))
12518 continue;
12519
12520 crtc_state->mode_changed = true;
12521
12522 ret = drm_atomic_add_affected_connectors(state, crtc);
12523 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012524 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012525
12526 ret = drm_atomic_add_affected_planes(state, crtc);
12527 if (ret)
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012528 return ret;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012529 }
12530
Ville Syrjälä9780aad2016-11-14 18:35:11 +020012531 return 0;
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012532}
12533
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012534static int intel_modeset_checks(struct drm_atomic_state *state)
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012535{
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012536 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012537 struct drm_i915_private *dev_priv = to_i915(state->dev);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012538 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012539 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012540 int ret = 0, i;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012541
Maarten Lankhorstb3592832015-06-15 12:33:38 +020012542 if (!check_digital_port_conflicts(state)) {
12543 DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n");
12544 return -EINVAL;
12545 }
12546
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012547 intel_state->modeset = true;
12548 intel_state->active_crtcs = dev_priv->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012549 intel_state->cdclk.logical = dev_priv->cdclk.logical;
12550 intel_state->cdclk.actual = dev_priv->cdclk.actual;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012551
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012552 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12553 if (new_crtc_state->active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012554 intel_state->active_crtcs |= 1 << i;
12555 else
12556 intel_state->active_crtcs &= ~(1 << i);
Matt Roper8b4a7d02016-05-12 07:06:00 -070012557
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012558 if (old_crtc_state->active != new_crtc_state->active)
Matt Roper8b4a7d02016-05-12 07:06:00 -070012559 intel_state->active_pipe_changes |= drm_crtc_mask(crtc);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012560 }
12561
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012562 /*
12563 * See if the config requires any additional preparation, e.g.
12564 * to adjust global state with pipes off. We need to do this
12565 * here so we can get the modeset_pipe updated config for the new
12566 * mode set on this crtc. For other crtcs we need to use the
12567 * adjusted_mode bits in the crtc directly.
12568 */
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012569 if (dev_priv->display.modeset_calc_cdclk) {
Clint Taylorc89e39f2016-05-13 23:41:21 +030012570 ret = dev_priv->display.modeset_calc_cdclk(state);
12571 if (ret < 0)
12572 return ret;
12573
Ville Syrjälä8d965612016-11-14 18:35:10 +020012574 /*
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012575 * Writes to dev_priv->cdclk.logical must protected by
Ville Syrjälä8d965612016-11-14 18:35:10 +020012576 * holding all the crtc locks, even if we don't end up
12577 * touching the hardware
12578 */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012579 if (intel_cdclk_changed(&dev_priv->cdclk.logical,
12580 &intel_state->cdclk.logical)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012581 ret = intel_lock_all_pipes(state);
12582 if (ret < 0)
12583 return ret;
12584 }
Maarten Lankhorst27c329e2015-06-15 12:33:56 +020012585
Ville Syrjälä8d965612016-11-14 18:35:10 +020012586 /* All pipes must be switched off while we change the cdclk. */
Ville Syrjälä64600bd2017-10-24 12:52:08 +030012587 if (intel_cdclk_needs_modeset(&dev_priv->cdclk.actual,
12588 &intel_state->cdclk.actual)) {
Ville Syrjälä8d965612016-11-14 18:35:10 +020012589 ret = intel_modeset_all_pipes(state);
12590 if (ret < 0)
12591 return ret;
12592 }
Maarten Lankhorste8788cb2016-02-16 10:25:11 +010012593
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012594 DRM_DEBUG_KMS("New cdclk calculated to be logical %u kHz, actual %u kHz\n",
12595 intel_state->cdclk.logical.cdclk,
12596 intel_state->cdclk.actual.cdclk);
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030012597 DRM_DEBUG_KMS("New voltage level calculated to be logical %u, actual %u\n",
12598 intel_state->cdclk.logical.voltage_level,
12599 intel_state->cdclk.actual.voltage_level);
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012600 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012601 to_intel_atomic_state(state)->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012602 }
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012603
Maarten Lankhorstad421372015-06-15 12:33:42 +020012604 intel_modeset_clear_plls(state);
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012605
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012606 if (IS_HASWELL(dev_priv))
Maarten Lankhorstad421372015-06-15 12:33:42 +020012607 return haswell_mode_set_planes_workaround(state);
Maarten Lankhorst99d736a2015-06-01 12:50:09 +020012608
Maarten Lankhorstad421372015-06-15 12:33:42 +020012609 return 0;
Ander Conselvan de Oliveira054518d2015-04-21 17:13:06 +030012610}
12611
Matt Roperaa363132015-09-24 15:53:18 -070012612/*
12613 * Handle calculation of various watermark data at the end of the atomic check
12614 * phase. The code here should be run after the per-crtc and per-plane 'check'
12615 * handlers to ensure that all derived state has been updated.
12616 */
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012617static int calc_watermark_data(struct intel_atomic_state *state)
Matt Roperaa363132015-09-24 15:53:18 -070012618{
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012619 struct drm_device *dev = state->base.dev;
Matt Roper98d39492016-05-12 07:06:03 -070012620 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roper98d39492016-05-12 07:06:03 -070012621
12622 /* Is there platform-specific watermark information to calculate? */
12623 if (dev_priv->display.compute_global_watermarks)
Matt Roper55994c22016-05-12 07:06:08 -070012624 return dev_priv->display.compute_global_watermarks(state);
12625
12626 return 0;
Matt Roperaa363132015-09-24 15:53:18 -070012627}
12628
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012629/**
12630 * intel_atomic_check - validate state object
12631 * @dev: drm device
12632 * @state: state to validate
12633 */
12634static int intel_atomic_check(struct drm_device *dev,
12635 struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012636{
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012637 struct drm_i915_private *dev_priv = to_i915(dev);
Matt Roperaa363132015-09-24 15:53:18 -070012638 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012639 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012640 struct drm_crtc_state *old_crtc_state, *crtc_state;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012641 int ret, i;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012642 bool any_ms = false;
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012643
Maarten Lankhorst8c58f732018-02-21 10:28:08 +010012644 /* Catch I915_MODE_FLAG_INHERITED */
12645 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state,
12646 crtc_state, i) {
12647 if (crtc_state->mode.private_flags !=
12648 old_crtc_state->mode.private_flags)
12649 crtc_state->mode_changed = true;
12650 }
12651
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020012652 ret = drm_atomic_helper_check_modeset(dev, state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012653 if (ret)
12654 return ret;
12655
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012656 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012657 struct intel_crtc_state *pipe_config =
12658 to_intel_crtc_state(crtc_state);
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012659
Daniel Vetter26495482015-07-15 14:15:52 +020012660 if (!needs_modeset(crtc_state))
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012661 continue;
12662
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012663 if (!crtc_state->enable) {
12664 any_ms = true;
12665 continue;
12666 }
12667
Maarten Lankhorstcfb23ed2015-07-14 12:17:40 +020012668 ret = intel_modeset_pipe_config(crtc, pipe_config);
Ville Syrjälä8e2b4df2018-11-07 23:35:20 +020012669 if (ret == -EDEADLK)
12670 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012671 if (ret) {
12672 intel_dump_pipe_config(to_intel_crtc(crtc),
12673 pipe_config, "[failed]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012674 return ret;
Maarten Lankhorst25aa1c32016-05-03 10:30:38 +020012675 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012676
Michal Wajdeczko4f044a82017-09-19 19:38:44 +000012677 if (i915_modparams.fastboot &&
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000012678 intel_pipe_config_compare(dev_priv,
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012679 to_intel_crtc_state(old_crtc_state),
Daniel Vetter1ed51de2015-07-15 14:15:51 +020012680 pipe_config, true)) {
Daniel Vetter26495482015-07-15 14:15:52 +020012681 crtc_state->mode_changed = false;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012682 pipe_config->update_pipe = true;
Daniel Vetter26495482015-07-15 14:15:52 +020012683 }
12684
Daniel Vetteraf4a8792016-05-09 09:31:25 +020012685 if (needs_modeset(crtc_state))
Daniel Vetter26495482015-07-15 14:15:52 +020012686 any_ms = true;
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012687
Daniel Vetter26495482015-07-15 14:15:52 +020012688 intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config,
12689 needs_modeset(crtc_state) ?
12690 "[modeset]" : "[fastset]");
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012691 }
12692
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012693 if (any_ms) {
12694 ret = intel_modeset_checks(state);
12695
12696 if (ret)
12697 return ret;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012698 } else {
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020012699 intel_state->cdclk.logical = dev_priv->cdclk.logical;
Ville Syrjäläe0ca7a62016-11-14 18:35:09 +020012700 }
Ander Conselvan de Oliveirac347a672015-06-01 12:50:02 +020012701
Maarten Lankhorst1ab554b2018-10-22 15:51:52 +020012702 ret = icl_add_linked_planes(intel_state);
12703 if (ret)
12704 return ret;
12705
Paulo Zanonidd8b3bd2016-01-19 11:35:49 -020012706 ret = drm_atomic_helper_check_planes(dev, state);
Matt Roperaa363132015-09-24 15:53:18 -070012707 if (ret)
12708 return ret;
12709
Ville Syrjälädd576022017-11-17 21:19:14 +020012710 intel_fbc_choose_crtc(dev_priv, intel_state);
Matt Ropercd1d3ee2018-12-10 13:54:14 -080012711 return calc_watermark_data(intel_state);
Daniel Vettera6778b32012-07-02 09:56:42 +020012712}
12713
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012714static int intel_atomic_prepare_commit(struct drm_device *dev,
Chris Wilsond07f0e52016-10-28 13:58:44 +010012715 struct drm_atomic_state *state)
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012716{
Chris Wilsonfd700752017-07-26 17:00:36 +010012717 return drm_atomic_helper_prepare_planes(dev, state);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020012718}
12719
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012720u32 intel_crtc_get_vblank_counter(struct intel_crtc *crtc)
12721{
12722 struct drm_device *dev = crtc->base.dev;
12723
12724 if (!dev->max_vblank_count)
Dhinakaran Pandiyan734cbbf2018-02-02 21:12:54 -080012725 return (u32)drm_crtc_accurate_vblank_count(&crtc->base);
Maarten Lankhorsta2991412016-05-17 15:07:48 +020012726
12727 return dev->driver->get_vblank_counter(dev, crtc->pipe);
12728}
12729
Lyude896e5bb2016-08-24 07:48:09 +020012730static void intel_update_crtc(struct drm_crtc *crtc,
12731 struct drm_atomic_state *state,
12732 struct drm_crtc_state *old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012733 struct drm_crtc_state *new_crtc_state)
Lyude896e5bb2016-08-24 07:48:09 +020012734{
12735 struct drm_device *dev = crtc->dev;
12736 struct drm_i915_private *dev_priv = to_i915(dev);
12737 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012738 struct intel_crtc_state *pipe_config = to_intel_crtc_state(new_crtc_state);
12739 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012740 struct intel_plane_state *new_plane_state =
12741 intel_atomic_get_new_plane_state(to_intel_atomic_state(state),
12742 to_intel_plane(crtc->primary));
Lyude896e5bb2016-08-24 07:48:09 +020012743
12744 if (modeset) {
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020012745 update_scanline_offset(pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012746 dev_priv->display.crtc_enable(pipe_config, state);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012747
12748 /* vblanks work again, re-enable pipe CRC. */
12749 intel_crtc_enable_pipe_crc(intel_crtc);
Lyude896e5bb2016-08-24 07:48:09 +020012750 } else {
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012751 intel_pre_plane_update(to_intel_crtc_state(old_crtc_state),
12752 pipe_config);
Lyude896e5bb2016-08-24 07:48:09 +020012753 }
12754
Maarten Lankhorst8b694492018-04-09 14:46:55 +020012755 if (new_plane_state)
12756 intel_fbc_enable(intel_crtc, pipe_config, new_plane_state);
Lyude896e5bb2016-08-24 07:48:09 +020012757
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012758 intel_begin_crtc_commit(crtc, old_crtc_state);
12759
Ville Syrjälä5f2e5112018-11-14 23:07:27 +020012760 if (INTEL_GEN(dev_priv) >= 9)
12761 skl_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
12762 else
12763 i9xx_update_planes_on_crtc(to_intel_atomic_state(state), intel_crtc);
Maarten Lankhorst6c246b82018-09-20 12:27:08 +020012764
12765 intel_finish_crtc_commit(crtc, old_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012766}
12767
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012768static void intel_update_crtcs(struct drm_atomic_state *state)
Lyude896e5bb2016-08-24 07:48:09 +020012769{
12770 struct drm_crtc *crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012771 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyude896e5bb2016-08-24 07:48:09 +020012772 int i;
12773
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012774 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
12775 if (!new_crtc_state->active)
Lyude896e5bb2016-08-24 07:48:09 +020012776 continue;
12777
12778 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012779 new_crtc_state);
Lyude896e5bb2016-08-24 07:48:09 +020012780 }
12781}
12782
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012783static void skl_update_crtcs(struct drm_atomic_state *state)
Lyude27082492016-08-24 07:48:10 +020012784{
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012785 struct drm_i915_private *dev_priv = to_i915(state->dev);
Lyude27082492016-08-24 07:48:10 +020012786 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
12787 struct drm_crtc *crtc;
Lyudece0ba282016-09-15 10:46:35 -040012788 struct intel_crtc *intel_crtc;
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012789 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Lyudece0ba282016-09-15 10:46:35 -040012790 struct intel_crtc_state *cstate;
Lyude27082492016-08-24 07:48:10 +020012791 unsigned int updated = 0;
12792 bool progress;
12793 enum pipe pipe;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012794 int i;
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012795 u8 hw_enabled_slices = dev_priv->wm.skl_hw.ddb.enabled_slices;
12796 u8 required_slices = intel_state->wm_results.ddb.enabled_slices;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012797 struct skl_ddb_entry entries[I915_MAX_PIPES] = {};
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012798
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012799 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i)
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012800 /* ignore allocations for crtc's that have been turned off. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012801 if (new_crtc_state->active)
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012802 entries[i] = to_intel_crtc_state(old_crtc_state)->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012803
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012804 /* If 2nd DBuf slice required, enable it here */
12805 if (INTEL_GEN(dev_priv) >= 11 && required_slices > hw_enabled_slices)
12806 icl_dbuf_slices_update(dev_priv, required_slices);
12807
Lyude27082492016-08-24 07:48:10 +020012808 /*
12809 * Whenever the number of active pipes changes, we need to make sure we
12810 * update the pipes in the right order so that their ddb allocations
12811 * never overlap with eachother inbetween CRTC updates. Otherwise we'll
12812 * cause pipe underruns and other bad stuff.
12813 */
12814 do {
Lyude27082492016-08-24 07:48:10 +020012815 progress = false;
12816
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012817 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Lyude27082492016-08-24 07:48:10 +020012818 bool vbl_wait = false;
12819 unsigned int cmask = drm_crtc_mask(crtc);
Lyudece0ba282016-09-15 10:46:35 -040012820
12821 intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä21794812017-08-23 18:22:26 +030012822 cstate = to_intel_crtc_state(new_crtc_state);
Lyudece0ba282016-09-15 10:46:35 -040012823 pipe = intel_crtc->pipe;
Lyude27082492016-08-24 07:48:10 +020012824
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012825 if (updated & cmask || !cstate->base.active)
Lyude27082492016-08-24 07:48:10 +020012826 continue;
Maarten Lankhorst5eff5032016-11-08 13:55:35 +010012827
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012828 if (skl_ddb_allocation_overlaps(&cstate->wm.skl.ddb,
Mika Kahola2b685042017-10-10 13:17:03 +030012829 entries,
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012830 INTEL_INFO(dev_priv)->num_pipes, i))
Lyude27082492016-08-24 07:48:10 +020012831 continue;
12832
12833 updated |= cmask;
Ville Syrjälä53cc68802018-11-01 17:05:59 +020012834 entries[i] = cstate->wm.skl.ddb;
Lyude27082492016-08-24 07:48:10 +020012835
12836 /*
12837 * If this is an already active pipe, it's DDB changed,
12838 * and this isn't the last pipe that needs updating
12839 * then we need to wait for a vblank to pass for the
12840 * new ddb allocation to take effect.
12841 */
Lyudece0ba282016-09-15 10:46:35 -040012842 if (!skl_ddb_entry_equal(&cstate->wm.skl.ddb,
Maarten Lankhorst512b5522016-11-08 13:55:34 +010012843 &to_intel_crtc_state(old_crtc_state)->wm.skl.ddb) &&
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012844 !new_crtc_state->active_changed &&
Lyude27082492016-08-24 07:48:10 +020012845 intel_state->wm_results.dirty_pipes != updated)
12846 vbl_wait = true;
12847
12848 intel_update_crtc(crtc, state, old_crtc_state,
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020012849 new_crtc_state);
Lyude27082492016-08-24 07:48:10 +020012850
12851 if (vbl_wait)
Ville Syrjälä0f0f74b2016-10-31 22:37:06 +020012852 intel_wait_for_vblank(dev_priv, pipe);
Lyude27082492016-08-24 07:48:10 +020012853
12854 progress = true;
12855 }
12856 } while (progress);
Mahesh Kumaraa9664f2018-04-26 19:55:16 +053012857
12858 /* If 2nd DBuf slice is no more required disable it */
12859 if (INTEL_GEN(dev_priv) >= 11 && required_slices < hw_enabled_slices)
12860 icl_dbuf_slices_update(dev_priv, required_slices);
Lyude27082492016-08-24 07:48:10 +020012861}
12862
Chris Wilsonba318c62017-02-02 20:47:41 +000012863static void intel_atomic_helper_free_state(struct drm_i915_private *dev_priv)
12864{
12865 struct intel_atomic_state *state, *next;
12866 struct llist_node *freed;
12867
12868 freed = llist_del_all(&dev_priv->atomic_helper.free_list);
12869 llist_for_each_entry_safe(state, next, freed, freed)
12870 drm_atomic_state_put(&state->base);
12871}
12872
12873static void intel_atomic_helper_free_state_worker(struct work_struct *work)
12874{
12875 struct drm_i915_private *dev_priv =
12876 container_of(work, typeof(*dev_priv), atomic_helper.free_work);
12877
12878 intel_atomic_helper_free_state(dev_priv);
12879}
12880
Daniel Vetter9db529a2017-08-08 10:08:28 +020012881static void intel_atomic_commit_fence_wait(struct intel_atomic_state *intel_state)
12882{
12883 struct wait_queue_entry wait_fence, wait_reset;
12884 struct drm_i915_private *dev_priv = to_i915(intel_state->base.dev);
12885
12886 init_wait_entry(&wait_fence, 0);
12887 init_wait_entry(&wait_reset, 0);
12888 for (;;) {
12889 prepare_to_wait(&intel_state->commit_ready.wait,
12890 &wait_fence, TASK_UNINTERRUPTIBLE);
12891 prepare_to_wait(&dev_priv->gpu_error.wait_queue,
12892 &wait_reset, TASK_UNINTERRUPTIBLE);
12893
12894
12895 if (i915_sw_fence_done(&intel_state->commit_ready)
12896 || test_bit(I915_RESET_MODESET, &dev_priv->gpu_error.flags))
12897 break;
12898
12899 schedule();
12900 }
12901 finish_wait(&intel_state->commit_ready.wait, &wait_fence);
12902 finish_wait(&dev_priv->gpu_error.wait_queue, &wait_reset);
12903}
12904
Chris Wilson8d52e442018-06-23 11:39:51 +010012905static void intel_atomic_cleanup_work(struct work_struct *work)
12906{
12907 struct drm_atomic_state *state =
12908 container_of(work, struct drm_atomic_state, commit_work);
12909 struct drm_i915_private *i915 = to_i915(state->dev);
12910
12911 drm_atomic_helper_cleanup_planes(&i915->drm, state);
12912 drm_atomic_helper_commit_cleanup_done(state);
12913 drm_atomic_state_put(state);
12914
12915 intel_atomic_helper_free_state(i915);
12916}
12917
Daniel Vetter94f05022016-06-14 18:01:00 +020012918static void intel_atomic_commit_tail(struct drm_atomic_state *state)
Daniel Vettera6778b32012-07-02 09:56:42 +020012919{
Daniel Vetter94f05022016-06-14 18:01:00 +020012920 struct drm_device *dev = state->dev;
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012921 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010012922 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012923 struct drm_crtc_state *old_crtc_state, *new_crtc_state;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012924 struct intel_crtc_state *new_intel_crtc_state, *old_intel_crtc_state;
Maarten Lankhorst7580d772015-08-18 13:40:06 +020012925 struct drm_crtc *crtc;
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012926 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020012927 u64 put_domains[I915_MAX_PIPES] = {};
Chris Wilsone95433c2016-10-28 13:58:27 +010012928 int i;
Daniel Vettera6778b32012-07-02 09:56:42 +020012929
Daniel Vetter9db529a2017-08-08 10:08:28 +020012930 intel_atomic_commit_fence_wait(intel_state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020012931
Daniel Vetterea0000f2016-06-13 16:13:46 +020012932 drm_atomic_helper_wait_for_dependencies(state);
12933
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010012934 if (intel_state->modeset)
Daniel Vetter5a21b662016-05-24 17:13:53 +020012935 intel_display_power_get(dev_priv, POWER_DOMAIN_MODESET);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012936
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012937 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012938 old_intel_crtc_state = to_intel_crtc_state(old_crtc_state);
12939 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
12940 intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012941
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012942 if (needs_modeset(new_crtc_state) ||
12943 to_intel_crtc_state(new_crtc_state)->update_pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020012944
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012945 put_domains[intel_crtc->pipe] =
Daniel Vetter5a21b662016-05-24 17:13:53 +020012946 modeset_get_crtc_power_domains(crtc,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012947 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020012948 }
12949
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010012950 if (!needs_modeset(new_crtc_state))
Maarten Lankhorst61333b62015-06-15 12:33:50 +020012951 continue;
12952
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012953 intel_pre_plane_update(old_intel_crtc_state, new_intel_crtc_state);
Daniel Vetter460da9162013-03-27 00:44:51 +010012954
Ville Syrjälä29ceb0e2016-03-09 19:07:27 +020012955 if (old_crtc_state->active) {
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020012956 intel_crtc_disable_planes(intel_state, intel_crtc);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +010012957
12958 /*
12959 * We need to disable pipe CRC before disabling the pipe,
12960 * or we race against vblank off.
12961 */
12962 intel_crtc_disable_pipe_crc(intel_crtc);
12963
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020012964 dev_priv->display.crtc_disable(old_intel_crtc_state, state);
Maarten Lankhorsteddfcbc2015-06-15 12:33:53 +020012965 intel_crtc->active = false;
Paulo Zanoni58f9c0b2016-01-19 11:35:51 -020012966 intel_fbc_disable(intel_crtc);
Maarten Lankhorst65c307f2018-10-05 11:52:44 +020012967 intel_disable_shared_dpll(old_intel_crtc_state);
Ville Syrjälä9bbc8258a2015-11-20 22:09:20 +020012968
12969 /*
12970 * Underruns don't always raise
12971 * interrupts, so check manually.
12972 */
12973 intel_check_cpu_fifo_underruns(dev_priv);
12974 intel_check_pch_fifo_underruns(dev_priv);
Maarten Lankhorstb9001112015-11-19 16:07:16 +010012975
Ville Syrjäläa748fae2018-10-25 16:05:36 +030012976 /* FIXME unify this for all platforms */
12977 if (!new_crtc_state->active &&
12978 !HAS_GMCH_DISPLAY(dev_priv) &&
12979 dev_priv->display.initial_watermarks)
12980 dev_priv->display.initial_watermarks(intel_state,
12981 new_intel_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020012982 }
Daniel Vetterb8cecdf2013-03-27 00:44:50 +010012983 }
Daniel Vetter7758a112012-07-08 19:40:39 +020012984
Daniel Vetter7a1530d72017-12-07 15:32:02 +010012985 /* FIXME: Eventually get rid of our intel_crtc->config pointer */
12986 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i)
12987 to_intel_crtc(crtc)->config = to_intel_crtc_state(new_crtc_state);
Daniel Vetterea9d7582012-07-10 10:42:52 +020012988
Maarten Lankhorst565602d2015-12-10 12:33:57 +010012989 if (intel_state->modeset) {
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020012990 drm_atomic_helper_update_legacy_modeset_state(state->dev, state);
Maarten Lankhorst33c8df892016-02-10 13:49:37 +010012991
Ville Syrjäläb0587e42017-01-26 21:52:01 +020012992 intel_set_cdclk(dev_priv, &dev_priv->cdclk.actual);
Maarten Lankhorstf6d19732016-03-23 14:58:07 +010012993
Lyude656d1b82016-08-17 15:55:54 -040012994 /*
12995 * SKL workaround: bspec recommends we disable the SAGV when we
12996 * have more then one pipe enabled
12997 */
Paulo Zanoni56feca92016-09-22 18:00:28 -030012998 if (!intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030012999 intel_disable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013000
Maarten Lankhorst677100c2016-11-08 13:55:41 +010013001 intel_modeset_verify_disabled(dev, state);
Maarten Lankhorst4740b0f2015-08-05 12:37:10 +020013002 }
Daniel Vetter47fab732012-10-26 10:58:18 +020013003
Lyude896e5bb2016-08-24 07:48:09 +020013004 /* Complete the events for pipes that have now been disabled */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013005 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
13006 bool modeset = needs_modeset(new_crtc_state);
Maarten Lankhorsta5392052015-06-15 12:33:52 +020013007
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013008 /* Complete events for now disable pipes here. */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013009 if (modeset && !new_crtc_state->active && new_crtc_state->event) {
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013010 spin_lock_irq(&dev->event_lock);
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013011 drm_crtc_send_vblank_event(crtc, new_crtc_state->event);
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013012 spin_unlock_irq(&dev->event_lock);
13013
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013014 new_crtc_state->event = NULL;
Daniel Vetter1f7528c2016-06-13 16:13:45 +020013015 }
Matt Ropered4a6a72016-02-23 17:20:13 -080013016 }
13017
Lyude896e5bb2016-08-24 07:48:09 +020013018 /* Now enable the clocks, plane, pipe, and connectors that we set up. */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013019 dev_priv->display.update_crtcs(state);
Lyude896e5bb2016-08-24 07:48:09 +020013020
Daniel Vetter94f05022016-06-14 18:01:00 +020013021 /* FIXME: We should call drm_atomic_helper_commit_hw_done() here
13022 * already, but still need the state for the delayed optimization. To
13023 * fix this:
13024 * - wrap the optimization/post_plane_update stuff into a per-crtc work.
13025 * - schedule that vblank worker _before_ calling hw_done
13026 * - at the start of commit_tail, cancel it _synchrously
13027 * - switch over to the vblank wait helper in the core after that since
13028 * we don't need out special handling any more.
13029 */
Maarten Lankhorstb44d5c02017-09-04 12:48:33 +020013030 drm_atomic_helper_wait_for_flip_done(dev, state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013031
13032 /*
13033 * Now that the vblank has passed, we can go ahead and program the
13034 * optimal watermarks on platforms that need two-step watermark
13035 * programming.
13036 *
13037 * TODO: Move this (and other cleanup) to an async worker eventually.
13038 */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013039 for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020013040 new_intel_crtc_state = to_intel_crtc_state(new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013041
13042 if (dev_priv->display.optimize_watermarks)
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013043 dev_priv->display.optimize_watermarks(intel_state,
Maarten Lankhorsta1cccdc2018-09-20 12:27:04 +020013044 new_intel_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013045 }
13046
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013047 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
Daniel Vetter5a21b662016-05-24 17:13:53 +020013048 intel_post_plane_update(to_intel_crtc_state(old_crtc_state));
13049
13050 if (put_domains[i])
13051 modeset_put_power_domains(dev_priv, put_domains[i]);
13052
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013053 intel_modeset_verify_crtc(crtc, state, old_crtc_state, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013054 }
13055
Ville Syrjäläcff109f2017-11-17 21:19:17 +020013056 if (intel_state->modeset)
13057 intel_verify_planes(intel_state);
13058
Paulo Zanoni56feca92016-09-22 18:00:28 -030013059 if (intel_state->modeset && intel_can_enable_sagv(state))
Paulo Zanoni16dcdc42016-09-22 18:00:27 -030013060 intel_enable_sagv(dev_priv);
Lyude656d1b82016-08-17 15:55:54 -040013061
Daniel Vetter94f05022016-06-14 18:01:00 +020013062 drm_atomic_helper_commit_hw_done(state);
13063
Chris Wilsond5553c02017-05-04 12:55:08 +010013064 if (intel_state->modeset) {
13065 /* As one of the primary mmio accessors, KMS has a high
13066 * likelihood of triggering bugs in unclaimed access. After we
13067 * finish modesetting, see if an error has been flagged, and if
13068 * so enable debugging for the next modeset - and hope we catch
13069 * the culprit.
13070 */
13071 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013072 intel_display_power_put(dev_priv, POWER_DOMAIN_MODESET);
Chris Wilsond5553c02017-05-04 12:55:08 +010013073 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013074
Chris Wilson8d52e442018-06-23 11:39:51 +010013075 /*
13076 * Defer the cleanup of the old state to a separate worker to not
13077 * impede the current task (userspace for blocking modesets) that
13078 * are executed inline. For out-of-line asynchronous modesets/flips,
13079 * deferring to a new worker seems overkill, but we would place a
13080 * schedule point (cond_resched()) here anyway to keep latencies
13081 * down.
13082 */
13083 INIT_WORK(&state->commit_work, intel_atomic_cleanup_work);
Chris Wilson41db6452018-07-12 12:57:29 +010013084 queue_work(system_highpri_wq, &state->commit_work);
Daniel Vetter94f05022016-06-14 18:01:00 +020013085}
13086
13087static void intel_atomic_commit_work(struct work_struct *work)
13088{
Chris Wilsonc004a902016-10-28 13:58:45 +010013089 struct drm_atomic_state *state =
13090 container_of(work, struct drm_atomic_state, commit_work);
13091
Daniel Vetter94f05022016-06-14 18:01:00 +020013092 intel_atomic_commit_tail(state);
13093}
13094
Chris Wilsonc004a902016-10-28 13:58:45 +010013095static int __i915_sw_fence_call
13096intel_atomic_commit_ready(struct i915_sw_fence *fence,
13097 enum i915_sw_fence_notify notify)
13098{
13099 struct intel_atomic_state *state =
13100 container_of(fence, struct intel_atomic_state, commit_ready);
13101
13102 switch (notify) {
13103 case FENCE_COMPLETE:
Daniel Vetter42b062b2017-08-08 10:08:27 +020013104 /* we do blocking waits in the worker, nothing to do here */
Chris Wilsonc004a902016-10-28 13:58:45 +010013105 break;
Chris Wilsonc004a902016-10-28 13:58:45 +010013106 case FENCE_FREE:
Chris Wilsoneb955ee2017-01-23 21:29:39 +000013107 {
13108 struct intel_atomic_helper *helper =
13109 &to_i915(state->base.dev)->atomic_helper;
13110
13111 if (llist_add(&state->freed, &helper->free_list))
13112 schedule_work(&helper->free_work);
13113 break;
13114 }
Chris Wilsonc004a902016-10-28 13:58:45 +010013115 }
13116
13117 return NOTIFY_DONE;
13118}
13119
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013120static void intel_atomic_track_fbs(struct drm_atomic_state *state)
13121{
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013122 struct drm_plane_state *old_plane_state, *new_plane_state;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013123 struct drm_plane *plane;
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013124 int i;
13125
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013126 for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i)
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013127 i915_gem_track_fb(intel_fb_obj(old_plane_state->fb),
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010013128 intel_fb_obj(new_plane_state->fb),
Chris Wilsonfaf5bf02016-08-04 16:32:37 +010013129 to_intel_plane(plane)->frontbuffer_bit);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013130}
13131
Daniel Vetter94f05022016-06-14 18:01:00 +020013132/**
13133 * intel_atomic_commit - commit validated state object
13134 * @dev: DRM device
13135 * @state: the top-level driver state object
13136 * @nonblock: nonblocking commit
13137 *
13138 * This function commits a top-level state object that has been validated
13139 * with drm_atomic_helper_check().
13140 *
Daniel Vetter94f05022016-06-14 18:01:00 +020013141 * RETURNS
13142 * Zero for success or -errno.
13143 */
13144static int intel_atomic_commit(struct drm_device *dev,
13145 struct drm_atomic_state *state,
13146 bool nonblock)
13147{
13148 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
Chris Wilsonfac5e232016-07-04 11:34:36 +010013149 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter94f05022016-06-14 18:01:00 +020013150 int ret = 0;
13151
Chris Wilsonc004a902016-10-28 13:58:45 +010013152 drm_atomic_state_get(state);
13153 i915_sw_fence_init(&intel_state->commit_ready,
13154 intel_atomic_commit_ready);
Daniel Vetter94f05022016-06-14 18:01:00 +020013155
Ville Syrjälä440df932017-03-29 17:21:23 +030013156 /*
13157 * The intel_legacy_cursor_update() fast path takes care
13158 * of avoiding the vblank waits for simple cursor
13159 * movement and flips. For cursor on/off and size changes,
13160 * we want to perform the vblank waits so that watermark
13161 * updates happen during the correct frames. Gen9+ have
13162 * double buffered watermarks and so shouldn't need this.
13163 *
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013164 * Unset state->legacy_cursor_update before the call to
13165 * drm_atomic_helper_setup_commit() because otherwise
13166 * drm_atomic_helper_wait_for_flip_done() is a noop and
13167 * we get FIFO underruns because we didn't wait
13168 * for vblank.
Ville Syrjälä440df932017-03-29 17:21:23 +030013169 *
13170 * FIXME doing watermarks and fb cleanup from a vblank worker
13171 * (assuming we had any) would solve these problems.
13172 */
Maarten Lankhorst213f1bd2017-09-19 14:14:19 +020013173 if (INTEL_GEN(dev_priv) < 9 && state->legacy_cursor_update) {
13174 struct intel_crtc_state *new_crtc_state;
13175 struct intel_crtc *crtc;
13176 int i;
13177
13178 for_each_new_intel_crtc_in_state(intel_state, crtc, new_crtc_state, i)
13179 if (new_crtc_state->wm.need_postvbl_update ||
13180 new_crtc_state->update_wm_post)
13181 state->legacy_cursor_update = false;
13182 }
Ville Syrjälä440df932017-03-29 17:21:23 +030013183
Maarten Lankhorst3cf50c62017-09-19 14:14:18 +020013184 ret = intel_atomic_prepare_commit(dev, state);
13185 if (ret) {
13186 DRM_DEBUG_ATOMIC("Preparing state failed with %i\n", ret);
13187 i915_sw_fence_commit(&intel_state->commit_ready);
13188 return ret;
13189 }
13190
13191 ret = drm_atomic_helper_setup_commit(state, nonblock);
13192 if (!ret)
13193 ret = drm_atomic_helper_swap_state(state, true);
13194
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013195 if (ret) {
13196 i915_sw_fence_commit(&intel_state->commit_ready);
13197
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013198 drm_atomic_helper_cleanup_planes(dev, state);
Maarten Lankhorst0806f4e2017-07-11 16:33:07 +020013199 return ret;
13200 }
Daniel Vetter94f05022016-06-14 18:01:00 +020013201 dev_priv->wm.distrust_bios_wm = false;
Ander Conselvan de Oliveira3c0fb582016-12-29 17:22:08 +020013202 intel_shared_dpll_swap_state(state);
Daniel Vetter6c9c1b32016-06-13 16:13:48 +020013203 intel_atomic_track_fbs(state);
Daniel Vetter94f05022016-06-14 18:01:00 +020013204
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013205 if (intel_state->modeset) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030013206 memcpy(dev_priv->min_cdclk, intel_state->min_cdclk,
13207 sizeof(intel_state->min_cdclk));
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030013208 memcpy(dev_priv->min_voltage_level,
13209 intel_state->min_voltage_level,
13210 sizeof(intel_state->min_voltage_level));
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013211 dev_priv->active_crtcs = intel_state->active_crtcs;
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020013212 dev_priv->cdclk.logical = intel_state->cdclk.logical;
13213 dev_priv->cdclk.actual = intel_state->cdclk.actual;
Maarten Lankhorstc3b32652016-11-08 13:55:40 +010013214 }
13215
Chris Wilson08536952016-10-14 13:18:18 +010013216 drm_atomic_state_get(state);
Daniel Vetter42b062b2017-08-08 10:08:27 +020013217 INIT_WORK(&state->commit_work, intel_atomic_commit_work);
Chris Wilsonc004a902016-10-28 13:58:45 +010013218
13219 i915_sw_fence_commit(&intel_state->commit_ready);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013220 if (nonblock && intel_state->modeset) {
13221 queue_work(dev_priv->modeset_wq, &state->commit_work);
13222 } else if (nonblock) {
Daniel Vetter42b062b2017-08-08 10:08:27 +020013223 queue_work(system_unbound_wq, &state->commit_work);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013224 } else {
13225 if (intel_state->modeset)
13226 flush_workqueue(dev_priv->modeset_wq);
Daniel Vetter94f05022016-06-14 18:01:00 +020013227 intel_atomic_commit_tail(state);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020013228 }
Mika Kuoppala75714942015-12-16 09:26:48 +020013229
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013230 return 0;
Daniel Vetterf30da182013-04-11 20:22:50 +020013231}
13232
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013233static const struct drm_crtc_funcs intel_crtc_funcs = {
Daniel Vetter3fab2f02017-04-03 10:32:57 +020013234 .gamma_set = drm_atomic_helper_legacy_gamma_set,
Maarten Lankhorst74c090b2015-07-13 16:30:30 +020013235 .set_config = drm_atomic_helper_set_config,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013236 .destroy = intel_crtc_destroy,
Maarten Lankhorst4c01ded2016-12-22 11:33:23 +010013237 .page_flip = drm_atomic_helper_page_flip,
Matt Roper13568372015-01-21 16:35:47 -080013238 .atomic_duplicate_state = intel_crtc_duplicate_state,
13239 .atomic_destroy_state = intel_crtc_destroy_state,
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +010013240 .set_crc_source = intel_crtc_set_crc_source,
Mahesh Kumara8c20832018-07-13 19:29:38 +053013241 .verify_crc_source = intel_crtc_verify_crc_source,
Mahesh Kumar260bc552018-07-13 19:29:39 +053013242 .get_crc_sources = intel_crtc_get_crc_sources,
Chris Wilsonf6e5b162011-04-12 18:06:51 +010013243};
13244
Chris Wilson74d290f2017-08-17 13:37:06 +010013245struct wait_rps_boost {
13246 struct wait_queue_entry wait;
13247
13248 struct drm_crtc *crtc;
Chris Wilsone61e0f52018-02-21 09:56:36 +000013249 struct i915_request *request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013250};
13251
13252static int do_rps_boost(struct wait_queue_entry *_wait,
13253 unsigned mode, int sync, void *key)
13254{
13255 struct wait_rps_boost *wait = container_of(_wait, typeof(*wait), wait);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013256 struct i915_request *rq = wait->request;
Chris Wilson74d290f2017-08-17 13:37:06 +010013257
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013258 /*
13259 * If we missed the vblank, but the request is already running it
13260 * is reasonable to assume that it will complete before the next
13261 * vblank without our intervention, so leave RPS alone.
13262 */
Chris Wilsone61e0f52018-02-21 09:56:36 +000013263 if (!i915_request_started(rq))
Chris Wilsone9af4ea2018-01-18 13:16:09 +000013264 gen6_rps_boost(rq, NULL);
Chris Wilsone61e0f52018-02-21 09:56:36 +000013265 i915_request_put(rq);
Chris Wilson74d290f2017-08-17 13:37:06 +010013266
13267 drm_crtc_vblank_put(wait->crtc);
13268
13269 list_del(&wait->wait.entry);
13270 kfree(wait);
13271 return 1;
13272}
13273
13274static void add_rps_boost_after_vblank(struct drm_crtc *crtc,
13275 struct dma_fence *fence)
13276{
13277 struct wait_rps_boost *wait;
13278
13279 if (!dma_fence_is_i915(fence))
13280 return;
13281
13282 if (INTEL_GEN(to_i915(crtc->dev)) < 6)
13283 return;
13284
13285 if (drm_crtc_vblank_get(crtc))
13286 return;
13287
13288 wait = kmalloc(sizeof(*wait), GFP_KERNEL);
13289 if (!wait) {
13290 drm_crtc_vblank_put(crtc);
13291 return;
13292 }
13293
13294 wait->request = to_request(dma_fence_get(fence));
13295 wait->crtc = crtc;
13296
13297 wait->wait.func = do_rps_boost;
13298 wait->wait.flags = 0;
13299
13300 add_wait_queue(drm_crtc_vblank_waitqueue(crtc), &wait->wait);
13301}
13302
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013303static int intel_plane_pin_fb(struct intel_plane_state *plane_state)
13304{
13305 struct intel_plane *plane = to_intel_plane(plane_state->base.plane);
13306 struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
13307 struct drm_framebuffer *fb = plane_state->base.fb;
13308 struct i915_vma *vma;
13309
13310 if (plane->id == PLANE_CURSOR &&
José Roberto de Souzad53db442018-11-30 15:20:48 -080013311 INTEL_INFO(dev_priv)->display.cursor_needs_physical) {
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013312 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
13313 const int align = intel_cursor_alignment(dev_priv);
Chris Wilson4a477652018-08-17 09:24:05 +010013314 int err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013315
Chris Wilson4a477652018-08-17 09:24:05 +010013316 err = i915_gem_object_attach_phys(obj, align);
13317 if (err)
13318 return err;
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013319 }
13320
13321 vma = intel_pin_and_fence_fb_obj(fb,
Ville Syrjäläf5929c52018-09-07 18:24:06 +030013322 &plane_state->view,
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013323 intel_plane_uses_fence(plane_state),
13324 &plane_state->flags);
13325 if (IS_ERR(vma))
13326 return PTR_ERR(vma);
13327
13328 plane_state->vma = vma;
13329
13330 return 0;
13331}
13332
13333static void intel_plane_unpin_fb(struct intel_plane_state *old_plane_state)
13334{
13335 struct i915_vma *vma;
13336
13337 vma = fetch_and_zero(&old_plane_state->vma);
13338 if (vma)
13339 intel_unpin_fb_vma(vma, old_plane_state->flags);
13340}
13341
Chris Wilsonb7268c52018-04-18 19:40:52 +010013342static void fb_obj_bump_render_priority(struct drm_i915_gem_object *obj)
13343{
13344 struct i915_sched_attr attr = {
13345 .priority = I915_PRIORITY_DISPLAY,
13346 };
13347
13348 i915_gem_object_wait_priority(obj, 0, &attr);
13349}
13350
Matt Roper6beb8c232014-12-01 15:40:14 -080013351/**
13352 * intel_prepare_plane_fb - Prepare fb for usage on plane
13353 * @plane: drm plane to prepare for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013354 * @new_state: the plane state being prepared
Matt Roper6beb8c232014-12-01 15:40:14 -080013355 *
13356 * Prepares a framebuffer for usage on a display plane. Generally this
13357 * involves pinning the underlying object and updating the frontbuffer tracking
13358 * bits. Some older platforms need special physical address handling for
13359 * cursor planes.
13360 *
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013361 * Must be called with struct_mutex held.
13362 *
Matt Roper6beb8c232014-12-01 15:40:14 -080013363 * Returns 0 on success, negative error code on failure.
13364 */
13365int
13366intel_prepare_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013367 struct drm_plane_state *new_state)
Matt Roper465c1202014-05-29 08:06:54 -070013368{
Chris Wilsonc004a902016-10-28 13:58:45 +010013369 struct intel_atomic_state *intel_state =
13370 to_intel_atomic_state(new_state->state);
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000013371 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Maarten Lankhorst844f9112015-09-02 10:42:40 +020013372 struct drm_framebuffer *fb = new_state->fb;
Matt Roper6beb8c232014-12-01 15:40:14 -080013373 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Maarten Lankhorst1ee49392015-09-23 13:27:08 +020013374 struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->state->fb);
Chris Wilsonc004a902016-10-28 13:58:45 +010013375 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013376
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013377 if (old_obj) {
13378 struct drm_crtc_state *crtc_state =
Maarten Lankhorst8b694492018-04-09 14:46:55 +020013379 drm_atomic_get_new_crtc_state(new_state->state,
13380 plane->state->crtc);
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013381
13382 /* Big Hammer, we also need to ensure that any pending
13383 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
13384 * current scanout is retired before unpinning the old
13385 * framebuffer. Note that we rely on userspace rendering
13386 * into the buffer attached to the pipe they are waiting
13387 * on. If not, userspace generates a GPU hang with IPEHR
13388 * point to the MI_WAIT_FOR_EVENT.
13389 *
13390 * This should only fail upon a hung GPU, in which case we
13391 * can safely continue.
13392 */
Chris Wilsonc004a902016-10-28 13:58:45 +010013393 if (needs_modeset(crtc_state)) {
13394 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13395 old_obj->resv, NULL,
13396 false, 0,
13397 GFP_KERNEL);
13398 if (ret < 0)
13399 return ret;
Chris Wilsonf4457ae2016-04-13 17:35:08 +010013400 }
Maarten Lankhorst5008e872015-08-18 13:40:05 +020013401 }
13402
Chris Wilsonc004a902016-10-28 13:58:45 +010013403 if (new_state->fence) { /* explicit fencing */
13404 ret = i915_sw_fence_await_dma_fence(&intel_state->commit_ready,
13405 new_state->fence,
13406 I915_FENCE_TIMEOUT,
13407 GFP_KERNEL);
13408 if (ret < 0)
13409 return ret;
13410 }
13411
Chris Wilsonc37efb92016-06-17 08:28:47 +010013412 if (!obj)
13413 return 0;
13414
Chris Wilson4d3088c2017-07-26 17:00:38 +010013415 ret = i915_gem_object_pin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013416 if (ret)
13417 return ret;
13418
Chris Wilson4d3088c2017-07-26 17:00:38 +010013419 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13420 if (ret) {
13421 i915_gem_object_unpin_pages(obj);
13422 return ret;
13423 }
13424
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013425 ret = intel_plane_pin_fb(to_intel_plane_state(new_state));
Chris Wilsonfd700752017-07-26 17:00:36 +010013426
Chris Wilsonfd700752017-07-26 17:00:36 +010013427 mutex_unlock(&dev_priv->drm.struct_mutex);
Chris Wilson4d3088c2017-07-26 17:00:38 +010013428 i915_gem_object_unpin_pages(obj);
Chris Wilsonfd700752017-07-26 17:00:36 +010013429 if (ret)
13430 return ret;
13431
Chris Wilsone2f34962018-10-01 15:47:54 +010013432 fb_obj_bump_render_priority(obj);
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013433 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
13434
Chris Wilsonc004a902016-10-28 13:58:45 +010013435 if (!new_state->fence) { /* implicit fencing */
Chris Wilson74d290f2017-08-17 13:37:06 +010013436 struct dma_fence *fence;
13437
Chris Wilsonc004a902016-10-28 13:58:45 +010013438 ret = i915_sw_fence_await_reservation(&intel_state->commit_ready,
13439 obj->resv, NULL,
13440 false, I915_FENCE_TIMEOUT,
13441 GFP_KERNEL);
13442 if (ret < 0)
13443 return ret;
Chris Wilson74d290f2017-08-17 13:37:06 +010013444
13445 fence = reservation_object_get_excl_rcu(obj->resv);
13446 if (fence) {
13447 add_rps_boost_after_vblank(new_state->crtc, fence);
13448 dma_fence_put(fence);
13449 }
13450 } else {
13451 add_rps_boost_after_vblank(new_state->crtc, new_state->fence);
Chris Wilsonc004a902016-10-28 13:58:45 +010013452 }
Daniel Vetter5a21b662016-05-24 17:13:53 +020013453
Chris Wilson60548c52018-07-31 14:26:29 +010013454 /*
13455 * We declare pageflips to be interactive and so merit a small bias
13456 * towards upclocking to deliver the frame on time. By only changing
13457 * the RPS thresholds to sample more regularly and aim for higher
13458 * clocks we can hopefully deliver low power workloads (like kodi)
13459 * that are not quite steady state without resorting to forcing
13460 * maximum clocks following a vblank miss (see do_rps_boost()).
13461 */
13462 if (!intel_state->rps_interactive) {
13463 intel_rps_mark_interactive(dev_priv, true);
13464 intel_state->rps_interactive = true;
13465 }
13466
Chris Wilsond07f0e52016-10-28 13:58:44 +010013467 return 0;
Matt Roper6beb8c232014-12-01 15:40:14 -080013468}
13469
Matt Roper38f3ce32014-12-02 07:45:25 -080013470/**
13471 * intel_cleanup_plane_fb - Cleans up an fb after plane use
13472 * @plane: drm plane to clean up for
Chris Wilsonc38c1452018-02-14 13:49:22 +000013473 * @old_state: the state from the previous modeset
Matt Roper38f3ce32014-12-02 07:45:25 -080013474 *
13475 * Cleans up a framebuffer that has just been removed from a plane.
Maarten Lankhorstf9356752015-08-18 13:40:05 +020013476 *
13477 * Must be called with struct_mutex held.
Matt Roper38f3ce32014-12-02 07:45:25 -080013478 */
13479void
13480intel_cleanup_plane_fb(struct drm_plane *plane,
Chris Wilson18320402016-08-18 19:00:16 +010013481 struct drm_plane_state *old_state)
Matt Roper38f3ce32014-12-02 07:45:25 -080013482{
Chris Wilson60548c52018-07-31 14:26:29 +010013483 struct intel_atomic_state *intel_state =
13484 to_intel_atomic_state(old_state->state);
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013485 struct drm_i915_private *dev_priv = to_i915(plane->dev);
Matt Roper38f3ce32014-12-02 07:45:25 -080013486
Chris Wilson60548c52018-07-31 14:26:29 +010013487 if (intel_state->rps_interactive) {
13488 intel_rps_mark_interactive(dev_priv, false);
13489 intel_state->rps_interactive = false;
13490 }
13491
Chris Wilsonbe1e3412017-01-16 15:21:27 +000013492 /* Should only be called after a successful intel_prepare_plane_fb()! */
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013493 mutex_lock(&dev_priv->drm.struct_mutex);
13494 intel_plane_unpin_fb(to_intel_plane_state(old_state));
13495 mutex_unlock(&dev_priv->drm.struct_mutex);
Matt Roper465c1202014-05-29 08:06:54 -070013496}
13497
Chandra Konduru6156a452015-04-27 13:48:39 -070013498int
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013499skl_max_scale(const struct intel_crtc_state *crtc_state,
13500 u32 pixel_format)
Chandra Konduru6156a452015-04-27 13:48:39 -070013501{
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013502 struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
13503 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru77224cd2018-04-09 09:11:13 +053013504 int max_scale, mult;
13505 int crtc_clock, max_dotclk, tmpclk1, tmpclk2;
Chandra Konduru6156a452015-04-27 13:48:39 -070013506
Ville Syrjälä4e0b83a2018-09-07 18:24:09 +030013507 if (!crtc_state->base.enable)
Chandra Konduru6156a452015-04-27 13:48:39 -070013508 return DRM_PLANE_HELPER_NO_SCALING;
13509
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013510 crtc_clock = crtc_state->base.adjusted_mode.crtc_clock;
13511 max_dotclk = to_intel_atomic_state(crtc_state->base.state)->cdclk.logical.cdclk;
13512
Rodrigo Vivi43037c82017-10-03 15:31:42 -070013513 if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 10)
Ander Conselvan de Oliveira5b7280f2017-02-23 09:15:58 +020013514 max_dotclk *= 2;
13515
13516 if (WARN_ON_ONCE(!crtc_clock || max_dotclk < crtc_clock))
Chandra Konduru6156a452015-04-27 13:48:39 -070013517 return DRM_PLANE_HELPER_NO_SCALING;
13518
13519 /*
13520 * skl max scale is lower of:
13521 * close to 3 but not 3, -1 is for that purpose
13522 * or
13523 * cdclk/crtc_clock
13524 */
Chandra Konduru77224cd2018-04-09 09:11:13 +053013525 mult = pixel_format == DRM_FORMAT_NV12 ? 2 : 3;
13526 tmpclk1 = (1 << 16) * mult - 1;
13527 tmpclk2 = (1 << 8) * ((max_dotclk << 8) / crtc_clock);
13528 max_scale = min(tmpclk1, tmpclk2);
Chandra Konduru6156a452015-04-27 13:48:39 -070013529
13530 return max_scale;
13531}
13532
Daniel Vetter5a21b662016-05-24 17:13:53 +020013533static void intel_begin_crtc_commit(struct drm_crtc *crtc,
13534 struct drm_crtc_state *old_crtc_state)
13535{
13536 struct drm_device *dev = crtc->dev;
Lyude62e0fb82016-08-22 12:50:08 -040013537 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013538 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013539 struct intel_crtc_state *old_intel_cstate =
Daniel Vetter5a21b662016-05-24 17:13:53 +020013540 to_intel_crtc_state(old_crtc_state);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013541 struct intel_atomic_state *old_intel_state =
13542 to_intel_atomic_state(old_crtc_state->state);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013543 struct intel_crtc_state *intel_cstate =
13544 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
13545 bool modeset = needs_modeset(&intel_cstate->base);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013546
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013547 if (!modeset &&
13548 (intel_cstate->base.color_mgmt_changed ||
13549 intel_cstate->update_pipe)) {
Matt Roper302da0c2018-12-10 13:54:15 -080013550 intel_color_set_csc(intel_cstate);
13551 intel_color_load_luts(intel_cstate);
Maarten Lankhorst567f0792017-02-28 15:28:47 +010013552 }
13553
Daniel Vetter5a21b662016-05-24 17:13:53 +020013554 /* Perform vblank evasion around commit operation */
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013555 intel_pipe_update_start(intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013556
13557 if (modeset)
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013558 goto out;
Daniel Vetter5a21b662016-05-24 17:13:53 +020013559
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013560 if (intel_cstate->update_pipe)
Ville Syrjälä1a15b772017-08-23 18:22:25 +030013561 intel_update_pipe_config(old_intel_cstate, intel_cstate);
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013562 else if (INTEL_GEN(dev_priv) >= 9)
Maarten Lankhorst15cbe5d2018-10-04 11:45:56 +020013563 skl_detach_scalers(intel_cstate);
Lyude62e0fb82016-08-22 12:50:08 -040013564
Maarten Lankhorste62929b2016-11-08 13:55:33 +010013565out:
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010013566 if (dev_priv->display.atomic_update_watermarks)
13567 dev_priv->display.atomic_update_watermarks(old_intel_state,
13568 intel_cstate);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013569}
13570
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013571void intel_crtc_arm_fifo_underrun(struct intel_crtc *crtc,
13572 struct intel_crtc_state *crtc_state)
13573{
13574 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
13575
Lucas De Marchicf819ef2018-12-12 10:10:43 -080013576 if (!IS_GEN(dev_priv, 2))
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013577 intel_set_cpu_fifo_underrun_reporting(dev_priv, crtc->pipe, true);
13578
13579 if (crtc_state->has_pch_encoder) {
13580 enum pipe pch_transcoder =
13581 intel_crtc_pch_transcoder(crtc);
13582
13583 intel_set_pch_fifo_underrun_reporting(dev_priv, pch_transcoder, true);
13584 }
13585}
13586
Daniel Vetter5a21b662016-05-24 17:13:53 +020013587static void intel_finish_crtc_commit(struct drm_crtc *crtc,
13588 struct drm_crtc_state *old_crtc_state)
13589{
13590 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013591 struct intel_atomic_state *old_intel_state =
13592 to_intel_atomic_state(old_crtc_state->state);
13593 struct intel_crtc_state *new_crtc_state =
13594 intel_atomic_get_new_crtc_state(old_intel_state, intel_crtc);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013595
Ville Syrjäläd3a8fb32017-08-23 18:22:21 +030013596 intel_pipe_update_end(new_crtc_state);
Maarten Lankhorst33a49862017-11-13 15:40:43 +010013597
13598 if (new_crtc_state->update_pipe &&
13599 !needs_modeset(&new_crtc_state->base) &&
Maarten Lankhorstd52ad9c2018-03-28 12:05:26 +020013600 old_crtc_state->mode.private_flags & I915_MODE_FLAG_INHERITED)
13601 intel_crtc_arm_fifo_underrun(intel_crtc, new_crtc_state);
Daniel Vetter5a21b662016-05-24 17:13:53 +020013602}
13603
Matt Ropercf4c7c12014-12-04 10:27:42 -080013604/**
Matt Roper4a3b8762014-12-23 10:41:51 -080013605 * intel_plane_destroy - destroy a plane
13606 * @plane: plane to destroy
Matt Ropercf4c7c12014-12-04 10:27:42 -080013607 *
Matt Roper4a3b8762014-12-23 10:41:51 -080013608 * Common destruction function for all types of planes (primary, cursor,
13609 * sprite).
Matt Ropercf4c7c12014-12-04 10:27:42 -080013610 */
Matt Roper4a3b8762014-12-23 10:41:51 -080013611void intel_plane_destroy(struct drm_plane *plane)
Matt Roper465c1202014-05-29 08:06:54 -070013612{
Matt Roper465c1202014-05-29 08:06:54 -070013613 drm_plane_cleanup(plane);
Ville Syrjälä69ae5612016-05-27 20:59:22 +030013614 kfree(to_intel_plane(plane));
Matt Roper465c1202014-05-29 08:06:54 -070013615}
13616
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013617static bool i8xx_plane_format_mod_supported(struct drm_plane *_plane,
13618 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013619{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013620 switch (modifier) {
13621 case DRM_FORMAT_MOD_LINEAR:
13622 case I915_FORMAT_MOD_X_TILED:
13623 break;
13624 default:
13625 return false;
13626 }
13627
Ben Widawsky714244e2017-08-01 09:58:16 -070013628 switch (format) {
13629 case DRM_FORMAT_C8:
13630 case DRM_FORMAT_RGB565:
13631 case DRM_FORMAT_XRGB1555:
13632 case DRM_FORMAT_XRGB8888:
13633 return modifier == DRM_FORMAT_MOD_LINEAR ||
13634 modifier == I915_FORMAT_MOD_X_TILED;
13635 default:
13636 return false;
13637 }
13638}
13639
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013640static bool i965_plane_format_mod_supported(struct drm_plane *_plane,
13641 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013642{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013643 switch (modifier) {
13644 case DRM_FORMAT_MOD_LINEAR:
13645 case I915_FORMAT_MOD_X_TILED:
13646 break;
13647 default:
13648 return false;
13649 }
13650
Ben Widawsky714244e2017-08-01 09:58:16 -070013651 switch (format) {
13652 case DRM_FORMAT_C8:
13653 case DRM_FORMAT_RGB565:
13654 case DRM_FORMAT_XRGB8888:
13655 case DRM_FORMAT_XBGR8888:
13656 case DRM_FORMAT_XRGB2101010:
13657 case DRM_FORMAT_XBGR2101010:
13658 return modifier == DRM_FORMAT_MOD_LINEAR ||
13659 modifier == I915_FORMAT_MOD_X_TILED;
13660 default:
13661 return false;
13662 }
13663}
13664
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013665static bool intel_cursor_format_mod_supported(struct drm_plane *_plane,
13666 u32 format, u64 modifier)
Ben Widawsky714244e2017-08-01 09:58:16 -070013667{
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013668 return modifier == DRM_FORMAT_MOD_LINEAR &&
13669 format == DRM_FORMAT_ARGB8888;
Ben Widawsky714244e2017-08-01 09:58:16 -070013670}
13671
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013672static const struct drm_plane_funcs i965_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013673 .update_plane = drm_atomic_helper_update_plane,
13674 .disable_plane = drm_atomic_helper_disable_plane,
13675 .destroy = intel_plane_destroy,
13676 .atomic_get_property = intel_plane_atomic_get_property,
13677 .atomic_set_property = intel_plane_atomic_set_property,
13678 .atomic_duplicate_state = intel_plane_duplicate_state,
13679 .atomic_destroy_state = intel_plane_destroy_state,
13680 .format_mod_supported = i965_plane_format_mod_supported,
13681};
13682
Ville Syrjälä679bfe82018-10-05 15:58:07 +030013683static const struct drm_plane_funcs i8xx_plane_funcs = {
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013684 .update_plane = drm_atomic_helper_update_plane,
13685 .disable_plane = drm_atomic_helper_disable_plane,
13686 .destroy = intel_plane_destroy,
13687 .atomic_get_property = intel_plane_atomic_get_property,
13688 .atomic_set_property = intel_plane_atomic_set_property,
13689 .atomic_duplicate_state = intel_plane_duplicate_state,
13690 .atomic_destroy_state = intel_plane_destroy_state,
13691 .format_mod_supported = i8xx_plane_format_mod_supported,
Matt Roper465c1202014-05-29 08:06:54 -070013692};
13693
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013694static int
13695intel_legacy_cursor_update(struct drm_plane *plane,
13696 struct drm_crtc *crtc,
13697 struct drm_framebuffer *fb,
13698 int crtc_x, int crtc_y,
13699 unsigned int crtc_w, unsigned int crtc_h,
13700 uint32_t src_x, uint32_t src_y,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013701 uint32_t src_w, uint32_t src_h,
13702 struct drm_modeset_acquire_ctx *ctx)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013703{
13704 struct drm_i915_private *dev_priv = to_i915(crtc->dev);
13705 int ret;
13706 struct drm_plane_state *old_plane_state, *new_plane_state;
13707 struct intel_plane *intel_plane = to_intel_plane(plane);
13708 struct drm_framebuffer *old_fb;
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013709 struct intel_crtc_state *crtc_state =
13710 to_intel_crtc_state(crtc->state);
13711 struct intel_crtc_state *new_crtc_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013712
13713 /*
13714 * When crtc is inactive or there is a modeset pending,
13715 * wait for it to complete in the slowpath
13716 */
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013717 if (!crtc_state->base.active || needs_modeset(&crtc_state->base) ||
13718 crtc_state->update_pipe)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013719 goto slow;
13720
13721 old_plane_state = plane->state;
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013722 /*
13723 * Don't do an async update if there is an outstanding commit modifying
13724 * the plane. This prevents our async update's changes from getting
13725 * overridden by a previous synchronous update's state.
13726 */
13727 if (old_plane_state->commit &&
13728 !try_wait_for_completion(&old_plane_state->commit->hw_done))
13729 goto slow;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013730
13731 /*
13732 * If any parameters change that may affect watermarks,
13733 * take the slowpath. Only changing fb or position should be
13734 * in the fastpath.
13735 */
13736 if (old_plane_state->crtc != crtc ||
13737 old_plane_state->src_w != src_w ||
13738 old_plane_state->src_h != src_h ||
13739 old_plane_state->crtc_w != crtc_w ||
13740 old_plane_state->crtc_h != crtc_h ||
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013741 !old_plane_state->fb != !fb)
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013742 goto slow;
13743
13744 new_plane_state = intel_plane_duplicate_state(plane);
13745 if (!new_plane_state)
13746 return -ENOMEM;
13747
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013748 new_crtc_state = to_intel_crtc_state(intel_crtc_duplicate_state(crtc));
13749 if (!new_crtc_state) {
13750 ret = -ENOMEM;
13751 goto out_free;
13752 }
13753
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013754 drm_atomic_set_fb_for_plane(new_plane_state, fb);
13755
13756 new_plane_state->src_x = src_x;
13757 new_plane_state->src_y = src_y;
13758 new_plane_state->src_w = src_w;
13759 new_plane_state->src_h = src_h;
13760 new_plane_state->crtc_x = crtc_x;
13761 new_plane_state->crtc_y = crtc_y;
13762 new_plane_state->crtc_w = crtc_w;
13763 new_plane_state->crtc_h = crtc_h;
13764
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013765 ret = intel_plane_atomic_check_with_state(crtc_state, new_crtc_state,
13766 to_intel_plane_state(old_plane_state),
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013767 to_intel_plane_state(new_plane_state));
13768 if (ret)
13769 goto out_free;
13770
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013771 ret = mutex_lock_interruptible(&dev_priv->drm.struct_mutex);
13772 if (ret)
13773 goto out_free;
13774
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013775 ret = intel_plane_pin_fb(to_intel_plane_state(new_plane_state));
13776 if (ret)
13777 goto out_unlock;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013778
Dhinakaran Pandiyana694e222018-03-06 19:34:19 -080013779 intel_fb_obj_flush(intel_fb_obj(fb), ORIGIN_FLIP);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013780
Dhinakaran Pandiyan07bcd992018-03-06 19:34:18 -080013781 old_fb = old_plane_state->fb;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013782 i915_gem_track_fb(intel_fb_obj(old_fb), intel_fb_obj(fb),
13783 intel_plane->frontbuffer_bit);
13784
13785 /* Swap plane state */
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013786 plane->state = new_plane_state;
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013787
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013788 /*
13789 * We cannot swap crtc_state as it may be in use by an atomic commit or
13790 * page flip that's running simultaneously. If we swap crtc_state and
13791 * destroy the old state, we will cause a use-after-free there.
13792 *
13793 * Only update active_planes, which is needed for our internal
13794 * bookkeeping. Either value will do the right thing when updating
13795 * planes atomically. If the cursor was part of the atomic update then
13796 * we would have taken the slowpath.
13797 */
13798 crtc_state->active_planes = new_crtc_state->active_planes;
13799
Ville Syrjälä72259532017-03-02 19:15:05 +020013800 if (plane->state->visible) {
13801 trace_intel_update_plane(plane, to_intel_crtc(crtc));
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013802 intel_plane->update_plane(intel_plane, crtc_state,
Ville Syrjäläa5509ab2017-02-17 17:01:59 +020013803 to_intel_plane_state(plane->state));
Ville Syrjälä72259532017-03-02 19:15:05 +020013804 } else {
13805 trace_intel_disable_plane(plane, to_intel_crtc(crtc));
Ville Syrjälä0dd14be2018-11-14 23:07:20 +020013806 intel_plane->disable_plane(intel_plane, crtc_state);
Ville Syrjälä72259532017-03-02 19:15:05 +020013807 }
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013808
Ville Syrjäläef1a1912018-02-21 18:02:34 +020013809 intel_plane_unpin_fb(to_intel_plane_state(old_plane_state));
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013810
13811out_unlock:
13812 mutex_unlock(&dev_priv->drm.struct_mutex);
13813out_free:
Maarten Lankhorstc249c5f2018-09-20 12:27:05 +020013814 if (new_crtc_state)
13815 intel_crtc_destroy_state(crtc, &new_crtc_state->base);
Maarten Lankhorst669c9212017-09-04 12:48:38 +020013816 if (ret)
13817 intel_plane_destroy_state(plane, new_plane_state);
13818 else
13819 intel_plane_destroy_state(plane, old_plane_state);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013820 return ret;
13821
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013822slow:
13823 return drm_atomic_helper_update_plane(plane, crtc, fb,
13824 crtc_x, crtc_y, crtc_w, crtc_h,
Daniel Vetter34a2ab52017-03-22 22:50:41 +010013825 src_x, src_y, src_w, src_h, ctx);
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013826}
13827
13828static const struct drm_plane_funcs intel_cursor_plane_funcs = {
13829 .update_plane = intel_legacy_cursor_update,
13830 .disable_plane = drm_atomic_helper_disable_plane,
13831 .destroy = intel_plane_destroy,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013832 .atomic_get_property = intel_plane_atomic_get_property,
13833 .atomic_set_property = intel_plane_atomic_set_property,
13834 .atomic_duplicate_state = intel_plane_duplicate_state,
13835 .atomic_destroy_state = intel_plane_destroy_state,
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013836 .format_mod_supported = intel_cursor_format_mod_supported,
Maarten Lankhorstf79f2692016-12-12 11:34:55 +010013837};
13838
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013839static bool i9xx_plane_has_fbc(struct drm_i915_private *dev_priv,
13840 enum i9xx_plane_id i9xx_plane)
13841{
13842 if (!HAS_FBC(dev_priv))
13843 return false;
13844
13845 if (IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv))
13846 return i9xx_plane == PLANE_A; /* tied to pipe A */
13847 else if (IS_IVYBRIDGE(dev_priv))
13848 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B ||
13849 i9xx_plane == PLANE_C;
13850 else if (INTEL_GEN(dev_priv) >= 4)
13851 return i9xx_plane == PLANE_A || i9xx_plane == PLANE_B;
13852 else
13853 return i9xx_plane == PLANE_A;
13854}
13855
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013856static struct intel_plane *
Ville Syrjälä580503c2016-10-31 22:37:00 +020013857intel_primary_plane_create(struct drm_i915_private *dev_priv, enum pipe pipe)
Matt Roper465c1202014-05-29 08:06:54 -070013858{
Ville Syrjälä881440a2018-10-05 15:58:17 +030013859 struct intel_plane *plane;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013860 const struct drm_plane_funcs *plane_funcs;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013861 unsigned int supported_rotations;
Ville Syrjälädeb19682018-10-05 15:58:08 +030013862 unsigned int possible_crtcs;
Ville Syrjälä881440a2018-10-05 15:58:17 +030013863 const u64 *modifiers;
13864 const u32 *formats;
13865 int num_formats;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013866 int ret;
Matt Roper465c1202014-05-29 08:06:54 -070013867
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013868 if (INTEL_GEN(dev_priv) >= 9)
13869 return skl_universal_plane_create(dev_priv, pipe,
13870 PLANE_PRIMARY);
13871
Ville Syrjälä881440a2018-10-05 15:58:17 +030013872 plane = intel_plane_alloc();
13873 if (IS_ERR(plane))
13874 return plane;
Matt Roperea2c67b2014-12-23 10:41:52 -080013875
Ville Syrjälä881440a2018-10-05 15:58:17 +030013876 plane->pipe = pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013877 /*
13878 * On gen2/3 only plane A can do FBC, but the panel fitter and LVDS
13879 * port is hooked to pipe B. Hence we want plane A feeding pipe B.
13880 */
13881 if (HAS_FBC(dev_priv) && INTEL_GEN(dev_priv) < 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013882 plane->i9xx_plane = (enum i9xx_plane_id) !pipe;
Ville Syrjäläe3c566d2016-11-08 16:47:11 +020013883 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013884 plane->i9xx_plane = (enum i9xx_plane_id) pipe;
13885 plane->id = PLANE_PRIMARY;
13886 plane->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, plane->id);
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013887
Ville Syrjälä881440a2018-10-05 15:58:17 +030013888 plane->has_fbc = i9xx_plane_has_fbc(dev_priv, plane->i9xx_plane);
13889 if (plane->has_fbc) {
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013890 struct intel_fbc *fbc = &dev_priv->fbc;
13891
Ville Syrjälä881440a2018-10-05 15:58:17 +030013892 fbc->possible_framebuffer_bits |= plane->frontbuffer_bit;
Ville Syrjäläcf1805e2018-02-21 19:31:01 +020013893 }
13894
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013895 if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013896 formats = i965_primary_formats;
Damien Lespiau568db4f2015-05-12 16:13:18 +010013897 num_formats = ARRAY_SIZE(i965_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013898 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013899
Ville Syrjälä881440a2018-10-05 15:58:17 +030013900 plane->max_stride = i9xx_plane_max_stride;
13901 plane->update_plane = i9xx_update_plane;
13902 plane->disable_plane = i9xx_disable_plane;
13903 plane->get_hw_state = i9xx_plane_get_hw_state;
13904 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013905
13906 plane_funcs = &i965_plane_funcs;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013907 } else {
Ville Syrjälä881440a2018-10-05 15:58:17 +030013908 formats = i8xx_primary_formats;
Damien Lespiau6c0fd452015-05-19 12:29:16 +010013909 num_formats = ARRAY_SIZE(i8xx_primary_formats);
Ben Widawsky714244e2017-08-01 09:58:16 -070013910 modifiers = i9xx_format_modifiers;
Maarten Lankhorsta8d201a2016-01-07 11:54:11 +010013911
Ville Syrjälä881440a2018-10-05 15:58:17 +030013912 plane->max_stride = i9xx_plane_max_stride;
13913 plane->update_plane = i9xx_update_plane;
13914 plane->disable_plane = i9xx_disable_plane;
13915 plane->get_hw_state = i9xx_plane_get_hw_state;
13916 plane->check_plane = i9xx_plane_check;
Ville Syrjäläa38189c2018-05-18 19:21:59 +030013917
13918 plane_funcs = &i8xx_plane_funcs;
Matt Roper465c1202014-05-29 08:06:54 -070013919 }
13920
Ville Syrjälädeb19682018-10-05 15:58:08 +030013921 possible_crtcs = BIT(pipe);
13922
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013923 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjälä881440a2018-10-05 15:58:17 +030013924 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013925 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013926 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013927 DRM_PLANE_TYPE_PRIMARY,
13928 "primary %c", pipe_name(pipe));
13929 else
Ville Syrjälä881440a2018-10-05 15:58:17 +030013930 ret = drm_universal_plane_init(&dev_priv->drm, &plane->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030013931 possible_crtcs, plane_funcs,
Ville Syrjälä881440a2018-10-05 15:58:17 +030013932 formats, num_formats, modifiers,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030013933 DRM_PLANE_TYPE_PRIMARY,
Ville Syrjäläed150302017-11-17 21:19:10 +020013934 "plane %c",
Ville Syrjälä881440a2018-10-05 15:58:17 +030013935 plane_name(plane->i9xx_plane));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013936 if (ret)
13937 goto fail;
Sonika Jindal48404c12014-08-22 14:06:04 +053013938
Ville Syrjäläb7c80602018-10-05 15:58:15 +030013939 if (IS_CHERRYVIEW(dev_priv) && pipe == PIPE_B) {
Ville Syrjälä4ea7be22016-11-14 18:54:00 +020013940 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013941 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180 |
13942 DRM_MODE_REFLECT_X;
Dave Airlie5481e272016-10-25 16:36:13 +100013943 } else if (INTEL_GEN(dev_priv) >= 4) {
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013944 supported_rotations =
Robert Fossc2c446a2017-05-19 16:50:17 -040013945 DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013946 } else {
Robert Fossc2c446a2017-05-19 16:50:17 -040013947 supported_rotations = DRM_MODE_ROTATE_0;
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013948 }
13949
Dave Airlie5481e272016-10-25 16:36:13 +100013950 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä881440a2018-10-05 15:58:17 +030013951 drm_plane_create_rotation_property(&plane->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040013952 DRM_MODE_ROTATE_0,
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030013953 supported_rotations);
Sonika Jindal48404c12014-08-22 14:06:04 +053013954
Ville Syrjälä881440a2018-10-05 15:58:17 +030013955 drm_plane_helper_add(&plane->base, &intel_plane_helper_funcs);
Matt Roperea2c67b2014-12-23 10:41:52 -080013956
Ville Syrjälä881440a2018-10-05 15:58:17 +030013957 return plane;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013958
13959fail:
Ville Syrjälä881440a2018-10-05 15:58:17 +030013960 intel_plane_free(plane);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013961
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013962 return ERR_PTR(ret);
Matt Roper465c1202014-05-29 08:06:54 -070013963}
13964
Ville Syrjäläb079bd172016-10-25 18:58:02 +030013965static struct intel_plane *
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013966intel_cursor_plane_create(struct drm_i915_private *dev_priv,
13967 enum pipe pipe)
Matt Roper3d7d6512014-06-10 08:28:13 -070013968{
Ville Syrjälädeb19682018-10-05 15:58:08 +030013969 unsigned int possible_crtcs;
Ville Syrjäläc539b572018-10-05 15:58:14 +030013970 struct intel_plane *cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000013971 int ret;
Matt Roper3d7d6512014-06-10 08:28:13 -070013972
Ville Syrjäläc539b572018-10-05 15:58:14 +030013973 cursor = intel_plane_alloc();
13974 if (IS_ERR(cursor))
13975 return cursor;
Matt Roperea2c67b2014-12-23 10:41:52 -080013976
Matt Roper3d7d6512014-06-10 08:28:13 -070013977 cursor->pipe = pipe;
Ville Syrjäläed150302017-11-17 21:19:10 +020013978 cursor->i9xx_plane = (enum i9xx_plane_id) pipe;
Ville Syrjäläb14e5842016-11-22 18:01:56 +020013979 cursor->id = PLANE_CURSOR;
Ville Syrjäläc19e1122018-01-23 20:33:43 +020013980 cursor->frontbuffer_bit = INTEL_FRONTBUFFER(pipe, cursor->id);
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013981
13982 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013983 cursor->max_stride = i845_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013984 cursor->update_plane = i845_update_cursor;
13985 cursor->disable_plane = i845_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013986 cursor->get_hw_state = i845_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013987 cursor->check_plane = i845_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013988 } else {
Ville Syrjäläddd57132018-09-07 18:24:02 +030013989 cursor->max_stride = i9xx_cursor_max_stride;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013990 cursor->update_plane = i9xx_update_cursor;
13991 cursor->disable_plane = i9xx_disable_cursor;
Ville Syrjälä51f5a0962017-11-17 21:19:08 +020013992 cursor->get_hw_state = i9xx_cursor_get_hw_state;
Ville Syrjälä659056f2017-03-27 21:55:39 +030013993 cursor->check_plane = i9xx_check_cursor;
Ville Syrjäläb2d03b02017-03-27 21:55:37 +030013994 }
Matt Roper3d7d6512014-06-10 08:28:13 -070013995
Ville Syrjäläcd5dcbf2017-03-27 21:55:35 +030013996 cursor->cursor.base = ~0;
13997 cursor->cursor.cntl = ~0;
Ville Syrjälä024faac2017-03-27 21:55:42 +030013998
13999 if (IS_I845G(dev_priv) || IS_I865G(dev_priv) || HAS_CUR_FBC(dev_priv))
14000 cursor->cursor.size = ~0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014001
Ville Syrjälädeb19682018-10-05 15:58:08 +030014002 possible_crtcs = BIT(pipe);
14003
Ville Syrjälä580503c2016-10-31 22:37:00 +020014004 ret = drm_universal_plane_init(&dev_priv->drm, &cursor->base,
Ville Syrjälädeb19682018-10-05 15:58:08 +030014005 possible_crtcs, &intel_cursor_plane_funcs,
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014006 intel_cursor_formats,
14007 ARRAY_SIZE(intel_cursor_formats),
Ben Widawsky714244e2017-08-01 09:58:16 -070014008 cursor_format_modifiers,
14009 DRM_PLANE_TYPE_CURSOR,
Ville Syrjälä38573dc2016-05-27 20:59:23 +030014010 "cursor %c", pipe_name(pipe));
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014011 if (ret)
14012 goto fail;
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014013
Dave Airlie5481e272016-10-25 16:36:13 +100014014 if (INTEL_GEN(dev_priv) >= 4)
Ville Syrjälä93ca7e02016-09-26 19:30:56 +030014015 drm_plane_create_rotation_property(&cursor->base,
Robert Fossc2c446a2017-05-19 16:50:17 -040014016 DRM_MODE_ROTATE_0,
14017 DRM_MODE_ROTATE_0 |
14018 DRM_MODE_ROTATE_180);
Ville Syrjälä4398ad42014-10-23 07:41:34 -070014019
Matt Roperea2c67b2014-12-23 10:41:52 -080014020 drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
14021
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014022 return cursor;
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014023
14024fail:
Ville Syrjäläc539b572018-10-05 15:58:14 +030014025 intel_plane_free(cursor);
Ville Syrjäläfca0ce22016-03-21 14:43:22 +000014026
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014027 return ERR_PTR(ret);
Matt Roper3d7d6512014-06-10 08:28:13 -070014028}
14029
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014030static void intel_crtc_init_scalers(struct intel_crtc *crtc,
14031 struct intel_crtc_state *crtc_state)
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014032{
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014033 struct intel_crtc_scaler_state *scaler_state =
14034 &crtc_state->scaler_state;
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014035 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014036 int i;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014037
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014038 crtc->num_scalers = dev_priv->info.num_scalers[crtc->pipe];
14039 if (!crtc->num_scalers)
14040 return;
14041
Ville Syrjälä65edccc2016-10-31 22:37:01 +020014042 for (i = 0; i < crtc->num_scalers; i++) {
14043 struct intel_scaler *scaler = &scaler_state->scalers[i];
14044
14045 scaler->in_use = 0;
Maarten Lankhorst0aaf29b2018-09-21 16:44:37 +020014046 scaler->mode = 0;
Chandra Konduru549e2bf2015-04-07 15:28:38 -070014047 }
14048
14049 scaler_state->scaler_id = -1;
14050}
14051
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014052static int intel_crtc_init(struct drm_i915_private *dev_priv, enum pipe pipe)
Jesse Barnes79e53942008-11-07 14:24:08 -080014053{
14054 struct intel_crtc *intel_crtc;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014055 struct intel_crtc_state *crtc_state = NULL;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014056 struct intel_plane *primary = NULL;
14057 struct intel_plane *cursor = NULL;
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014058 int sprite, ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014059
Daniel Vetter955382f2013-09-19 14:05:45 +020014060 intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014061 if (!intel_crtc)
14062 return -ENOMEM;
Jesse Barnes79e53942008-11-07 14:24:08 -080014063
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014064 crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014065 if (!crtc_state) {
14066 ret = -ENOMEM;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014067 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014068 }
Ander Conselvan de Oliveira550acef2015-04-21 17:13:24 +030014069 intel_crtc->config = crtc_state;
14070 intel_crtc->base.state = &crtc_state->base;
Matt Roper07878242015-02-25 11:43:26 -080014071 crtc_state->base.crtc = &intel_crtc->base;
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014072
Ville Syrjälä580503c2016-10-31 22:37:00 +020014073 primary = intel_primary_plane_create(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014074 if (IS_ERR(primary)) {
14075 ret = PTR_ERR(primary);
Matt Roper3d7d6512014-06-10 08:28:13 -070014076 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014077 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014078 intel_crtc->plane_ids_mask |= BIT(primary->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014079
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014080 for_each_sprite(dev_priv, pipe, sprite) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014081 struct intel_plane *plane;
14082
Ville Syrjälä580503c2016-10-31 22:37:00 +020014083 plane = intel_sprite_plane_create(dev_priv, pipe, sprite);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014084 if (IS_ERR(plane)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014085 ret = PTR_ERR(plane);
14086 goto fail;
14087 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014088 intel_crtc->plane_ids_mask |= BIT(plane->id);
Ville Syrjäläa81d6fa2016-10-25 18:58:01 +030014089 }
14090
Ville Syrjälä580503c2016-10-31 22:37:00 +020014091 cursor = intel_cursor_plane_create(dev_priv, pipe);
Ville Syrjäläd2b2cbc2016-11-07 22:20:56 +020014092 if (IS_ERR(cursor)) {
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014093 ret = PTR_ERR(cursor);
Matt Roper3d7d6512014-06-10 08:28:13 -070014094 goto fail;
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014095 }
Ville Syrjäläd97d7b42016-11-22 18:01:57 +020014096 intel_crtc->plane_ids_mask |= BIT(cursor->id);
Matt Roper3d7d6512014-06-10 08:28:13 -070014097
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020014098 ret = drm_crtc_init_with_planes(&dev_priv->drm, &intel_crtc->base,
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014099 &primary->base, &cursor->base,
14100 &intel_crtc_funcs,
Ville Syrjälä4d5d72b72016-05-27 20:59:21 +030014101 "pipe %c", pipe_name(pipe));
Matt Roper3d7d6512014-06-10 08:28:13 -070014102 if (ret)
14103 goto fail;
Jesse Barnes79e53942008-11-07 14:24:08 -080014104
Jesse Barnes80824002009-09-10 15:28:06 -070014105 intel_crtc->pipe = pipe;
Jesse Barnes80824002009-09-10 15:28:06 -070014106
Nabendu Maiti1c74eea2016-11-29 11:23:14 +053014107 /* initialize shared scalers */
14108 intel_crtc_init_scalers(intel_crtc, crtc_state);
14109
Ville Syrjälä1947fd12018-03-05 19:41:22 +020014110 BUG_ON(pipe >= ARRAY_SIZE(dev_priv->pipe_to_crtc_mapping) ||
14111 dev_priv->pipe_to_crtc_mapping[pipe] != NULL);
14112 dev_priv->pipe_to_crtc_mapping[pipe] = intel_crtc;
14113
14114 if (INTEL_GEN(dev_priv) < 9) {
14115 enum i9xx_plane_id i9xx_plane = primary->i9xx_plane;
14116
14117 BUG_ON(i9xx_plane >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
14118 dev_priv->plane_to_crtc_mapping[i9xx_plane] != NULL);
14119 dev_priv->plane_to_crtc_mapping[i9xx_plane] = intel_crtc;
14120 }
Jesse Barnes22fd0fa2009-12-02 13:42:53 -080014121
Jesse Barnes79e53942008-11-07 14:24:08 -080014122 drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
Daniel Vetter87b6b102014-05-15 15:33:46 +020014123
Matt Roper302da0c2018-12-10 13:54:15 -080014124 intel_color_init(intel_crtc);
Lionel Landwerlin8563b1e2016-03-16 10:57:14 +000014125
Daniel Vetter87b6b102014-05-15 15:33:46 +020014126 WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014127
14128 return 0;
Matt Roper3d7d6512014-06-10 08:28:13 -070014129
14130fail:
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014131 /*
14132 * drm_mode_config_cleanup() will free up any
14133 * crtcs/planes already initialized.
14134 */
Ander Conselvan de Oliveiraf5de6e02015-01-15 14:55:26 +020014135 kfree(crtc_state);
Matt Roper3d7d6512014-06-10 08:28:13 -070014136 kfree(intel_crtc);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030014137
14138 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014139}
14140
Ville Syrjälä6a20fe72018-02-07 18:48:41 +020014141int intel_get_pipe_from_crtc_id_ioctl(struct drm_device *dev, void *data,
14142 struct drm_file *file)
Carl Worth08d7b3d2009-04-29 14:43:54 -070014143{
Carl Worth08d7b3d2009-04-29 14:43:54 -070014144 struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
Rob Clark7707e652014-07-17 23:30:04 -040014145 struct drm_crtc *drmmode_crtc;
Daniel Vetterc05422d2009-08-11 16:05:30 +020014146 struct intel_crtc *crtc;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014147
Keith Packard418da172017-03-14 23:25:07 -070014148 drmmode_crtc = drm_crtc_find(dev, file, pipe_from_crtc_id->crtc_id);
Chris Wilson71240ed2016-06-24 14:00:24 +010014149 if (!drmmode_crtc)
Ville Syrjälä3f2c2052013-10-17 13:35:03 +030014150 return -ENOENT;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014151
Rob Clark7707e652014-07-17 23:30:04 -040014152 crtc = to_intel_crtc(drmmode_crtc);
Daniel Vetterc05422d2009-08-11 16:05:30 +020014153 pipe_from_crtc_id->pipe = crtc->pipe;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014154
Daniel Vetterc05422d2009-08-11 16:05:30 +020014155 return 0;
Carl Worth08d7b3d2009-04-29 14:43:54 -070014156}
14157
Daniel Vetter66a92782012-07-12 20:08:18 +020014158static int intel_encoder_clones(struct intel_encoder *encoder)
Jesse Barnes79e53942008-11-07 14:24:08 -080014159{
Daniel Vetter66a92782012-07-12 20:08:18 +020014160 struct drm_device *dev = encoder->base.dev;
14161 struct intel_encoder *source_encoder;
Jesse Barnes79e53942008-11-07 14:24:08 -080014162 int index_mask = 0;
Jesse Barnes79e53942008-11-07 14:24:08 -080014163 int entry = 0;
14164
Damien Lespiaub2784e12014-08-05 11:29:37 +010014165 for_each_intel_encoder(dev, source_encoder) {
Ville Syrjäläbc079e82014-03-03 16:15:28 +020014166 if (encoders_cloneable(encoder, source_encoder))
Daniel Vetter66a92782012-07-12 20:08:18 +020014167 index_mask |= (1 << entry);
14168
Jesse Barnes79e53942008-11-07 14:24:08 -080014169 entry++;
14170 }
Chris Wilson4ef69c72010-09-09 15:14:28 +010014171
Jesse Barnes79e53942008-11-07 14:24:08 -080014172 return index_mask;
14173}
14174
Ville Syrjälä646d5772016-10-31 22:37:14 +020014175static bool has_edp_a(struct drm_i915_private *dev_priv)
Chris Wilson4d302442010-12-14 19:21:29 +000014176{
Ville Syrjälä646d5772016-10-31 22:37:14 +020014177 if (!IS_MOBILE(dev_priv))
Chris Wilson4d302442010-12-14 19:21:29 +000014178 return false;
14179
14180 if ((I915_READ(DP_A) & DP_DETECTED) == 0)
14181 return false;
14182
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014183 if (IS_GEN(dev_priv, 5) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE))
Chris Wilson4d302442010-12-14 19:21:29 +000014184 return false;
14185
14186 return true;
14187}
14188
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014189static bool intel_crt_present(struct drm_i915_private *dev_priv)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014190{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014191 if (INTEL_GEN(dev_priv) >= 9)
Damien Lespiau884497e2013-12-03 13:56:23 +000014192 return false;
14193
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +010014194 if (IS_HSW_ULT(dev_priv) || IS_BDW_ULT(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014195 return false;
14196
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014197 if (IS_CHERRYVIEW(dev_priv))
Jesse Barnes84b4e042014-06-25 08:24:29 -070014198 return false;
14199
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014200 if (HAS_PCH_LPT_H(dev_priv) &&
14201 I915_READ(SFUSE_STRAP) & SFUSE_STRAP_CRT_DISABLED)
Ville Syrjälä65e472e2015-12-01 23:28:55 +020014202 return false;
14203
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014204 /* DDI E can't be used if DDI A requires 4 lanes */
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014205 if (HAS_DDI(dev_priv) && I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)
Ville Syrjälä70ac54d2015-12-01 23:29:56 +020014206 return false;
14207
Ville Syrjäläe4abb732015-12-01 23:31:33 +020014208 if (!dev_priv->vbt.int_crt_support)
Jesse Barnes84b4e042014-06-25 08:24:29 -070014209 return false;
14210
14211 return true;
14212}
14213
Imre Deak8090ba82016-08-10 14:07:33 +030014214void intel_pps_unlock_regs_wa(struct drm_i915_private *dev_priv)
14215{
14216 int pps_num;
14217 int pps_idx;
14218
14219 if (HAS_DDI(dev_priv))
14220 return;
14221 /*
14222 * This w/a is needed at least on CPT/PPT, but to be sure apply it
14223 * everywhere where registers can be write protected.
14224 */
14225 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14226 pps_num = 2;
14227 else
14228 pps_num = 1;
14229
14230 for (pps_idx = 0; pps_idx < pps_num; pps_idx++) {
14231 u32 val = I915_READ(PP_CONTROL(pps_idx));
14232
14233 val = (val & ~PANEL_UNLOCK_MASK) | PANEL_UNLOCK_REGS;
14234 I915_WRITE(PP_CONTROL(pps_idx), val);
14235 }
14236}
14237
Imre Deak44cb7342016-08-10 14:07:29 +030014238static void intel_pps_init(struct drm_i915_private *dev_priv)
14239{
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +020014240 if (HAS_PCH_SPLIT(dev_priv) || IS_GEN9_LP(dev_priv))
Imre Deak44cb7342016-08-10 14:07:29 +030014241 dev_priv->pps_mmio_base = PCH_PPS_BASE;
14242 else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
14243 dev_priv->pps_mmio_base = VLV_PPS_BASE;
14244 else
14245 dev_priv->pps_mmio_base = PPS_BASE;
Imre Deak8090ba82016-08-10 14:07:33 +030014246
14247 intel_pps_unlock_regs_wa(dev_priv);
Imre Deak44cb7342016-08-10 14:07:29 +030014248}
14249
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014250static void intel_setup_outputs(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -080014251{
Chris Wilson4ef69c72010-09-09 15:14:28 +010014252 struct intel_encoder *encoder;
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014253 bool dpd_is_edp = false;
Jesse Barnes79e53942008-11-07 14:24:08 -080014254
Imre Deak44cb7342016-08-10 14:07:29 +030014255 intel_pps_init(dev_priv);
14256
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080014257 if (!HAS_DISPLAY(dev_priv))
Chris Wilsonfc0c5a92018-08-15 21:12:07 +010014258 return;
14259
Imre Deak97a824e12016-06-21 11:51:47 +030014260 /*
14261 * intel_edp_init_connector() depends on this completing first, to
14262 * prevent the registeration of both eDP and LVDS and the incorrect
14263 * sharing of the PPS.
14264 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014265 intel_lvds_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014266
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000014267 if (intel_crt_present(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014268 intel_crt_init(dev_priv);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014269
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014270 if (IS_ICELAKE(dev_priv)) {
14271 intel_ddi_init(dev_priv, PORT_A);
14272 intel_ddi_init(dev_priv, PORT_B);
14273 intel_ddi_init(dev_priv, PORT_C);
14274 intel_ddi_init(dev_priv, PORT_D);
14275 intel_ddi_init(dev_priv, PORT_E);
14276 intel_ddi_init(dev_priv, PORT_F);
Madhav Chauhanbf4d57f2018-10-30 13:56:23 +020014277 icl_dsi_init(dev_priv);
Paulo Zanoni00c92d92018-05-21 17:25:47 -070014278 } else if (IS_GEN9_LP(dev_priv)) {
Vandana Kannanc776eb22014-08-19 12:05:01 +053014279 /*
14280 * FIXME: Broxton doesn't support port detection via the
14281 * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to
14282 * detect the ports.
14283 */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014284 intel_ddi_init(dev_priv, PORT_A);
14285 intel_ddi_init(dev_priv, PORT_B);
14286 intel_ddi_init(dev_priv, PORT_C);
Shashank Sharmac6c794a2016-03-22 12:01:50 +020014287
Jani Nikulae5186342018-07-05 16:25:08 +030014288 vlv_dsi_init(dev_priv);
Tvrtko Ursulin4f8036a2016-10-13 11:02:52 +010014289 } else if (HAS_DDI(dev_priv)) {
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014290 int found;
14291
Jesse Barnesde31fac2015-03-06 15:53:32 -080014292 /*
14293 * Haswell uses DDI functions to detect digital outputs.
14294 * On SKL pre-D0 the strap isn't connected, so we assume
14295 * it's there.
14296 */
Ville Syrjälä77179402015-09-18 20:03:35 +030014297 found = I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_INIT_DISPLAY_DETECTED;
Jesse Barnesde31fac2015-03-06 15:53:32 -080014298 /* WaIgnoreDDIAStrap: skl */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014299 if (found || IS_GEN9_BC(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014300 intel_ddi_init(dev_priv, PORT_A);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014301
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014302 /* DDI B, C, D, and F detection is indicated by the SFUSE_STRAP
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014303 * register */
14304 found = I915_READ(SFUSE_STRAP);
14305
14306 if (found & SFUSE_STRAP_DDIB_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014307 intel_ddi_init(dev_priv, PORT_B);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014308 if (found & SFUSE_STRAP_DDIC_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014309 intel_ddi_init(dev_priv, PORT_C);
Eugeni Dodonov0e72a5b2012-05-09 15:37:27 -030014310 if (found & SFUSE_STRAP_DDID_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014311 intel_ddi_init(dev_priv, PORT_D);
Rodrigo Vivi9787e832018-01-29 15:22:22 -080014312 if (found & SFUSE_STRAP_DDIF_DETECTED)
14313 intel_ddi_init(dev_priv, PORT_F);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014314 /*
14315 * On SKL we don't have a way to detect DDI-E so we rely on VBT.
14316 */
Rodrigo Vivib976dc52017-01-23 10:32:37 -080014317 if (IS_GEN9_BC(dev_priv) &&
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014318 (dev_priv->vbt.ddi_port_info[PORT_E].supports_dp ||
14319 dev_priv->vbt.ddi_port_info[PORT_E].supports_dvi ||
14320 dev_priv->vbt.ddi_port_info[PORT_E].supports_hdmi))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014321 intel_ddi_init(dev_priv, PORT_E);
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -070014322
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010014323 } else if (HAS_PCH_SPLIT(dev_priv)) {
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014324 int found;
Jani Nikula7b91bf72017-08-18 12:30:19 +030014325 dpd_is_edp = intel_dp_is_port_edp(dev_priv, PORT_D);
Daniel Vetter270b3042012-10-27 15:52:05 +020014326
Ville Syrjälä646d5772016-10-31 22:37:14 +020014327 if (has_edp_a(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014328 intel_dp_init(dev_priv, DP_A, PORT_A);
Adam Jacksoncb0953d2010-07-16 14:46:29 -040014329
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014330 if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) {
Zhao Yakui461ed3c2010-03-30 15:11:33 +080014331 /* PCH SDVOB multiplex with HDMIB */
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014332 found = intel_sdvo_init(dev_priv, PCH_SDVOB, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014333 if (!found)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014334 intel_hdmi_init(dev_priv, PCH_HDMIB, PORT_B);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014335 if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014336 intel_dp_init(dev_priv, PCH_DP_B, PORT_B);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014337 }
14338
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014339 if (I915_READ(PCH_HDMIC) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014340 intel_hdmi_init(dev_priv, PCH_HDMIC, PORT_C);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014341
Paulo Zanonidc0fa712013-02-19 16:21:46 -030014342 if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014343 intel_hdmi_init(dev_priv, PCH_HDMID, PORT_D);
Zhenyu Wang30ad48b2009-06-05 15:38:43 +080014344
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014345 if (I915_READ(PCH_DP_C) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014346 intel_dp_init(dev_priv, PCH_DP_C, PORT_C);
Zhenyu Wang5eb08b62009-07-24 01:00:31 +080014347
Daniel Vetter270b3042012-10-27 15:52:05 +020014348 if (I915_READ(PCH_DP_D) & DP_DETECTED)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014349 intel_dp_init(dev_priv, PCH_DP_D, PORT_D);
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014350 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014351 bool has_edp, has_port;
Chris Wilson457c52d2016-06-01 08:27:50 +010014352
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014353 /*
14354 * The DP_DETECTED bit is the latched state of the DDC
14355 * SDA pin at boot. However since eDP doesn't require DDC
14356 * (no way to plug in a DP->HDMI dongle) the DDC pins for
14357 * eDP ports may have been muxed to an alternate function.
14358 * Thus we can't rely on the DP_DETECTED bit alone to detect
14359 * eDP ports. Consult the VBT as well as DP_DETECTED to
14360 * detect eDP ports.
Ville Syrjälä22f350422016-06-03 12:17:43 +030014361 *
14362 * Sadly the straps seem to be missing sometimes even for HDMI
14363 * ports (eg. on Voyo V3 - CHT x7-Z8700), so check both strap
14364 * and VBT for the presence of the port. Additionally we can't
14365 * trust the port type the VBT declares as we've seen at least
14366 * HDMI ports that the VBT claim are DP or eDP.
Ville Syrjäläe17ac6d2014-10-09 19:37:15 +030014367 */
Jani Nikula7b91bf72017-08-18 12:30:19 +030014368 has_edp = intel_dp_is_port_edp(dev_priv, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014369 has_port = intel_bios_is_port_present(dev_priv, PORT_B);
14370 if (I915_READ(VLV_DP_B) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014371 has_edp &= intel_dp_init(dev_priv, VLV_DP_B, PORT_B);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014372 if ((I915_READ(VLV_HDMIB) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014373 intel_hdmi_init(dev_priv, VLV_HDMIB, PORT_B);
Artem Bityutskiy585a94b2013-10-16 18:10:41 +030014374
Jani Nikula7b91bf72017-08-18 12:30:19 +030014375 has_edp = intel_dp_is_port_edp(dev_priv, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014376 has_port = intel_bios_is_port_present(dev_priv, PORT_C);
14377 if (I915_READ(VLV_DP_C) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014378 has_edp &= intel_dp_init(dev_priv, VLV_DP_C, PORT_C);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014379 if ((I915_READ(VLV_HDMIC) & SDVO_DETECTED || has_port) && !has_edp)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014380 intel_hdmi_init(dev_priv, VLV_HDMIC, PORT_C);
Gajanan Bhat19c03922012-09-27 19:13:07 +053014381
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014382 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä22f350422016-06-03 12:17:43 +030014383 /*
14384 * eDP not supported on port D,
14385 * so no need to worry about it
14386 */
14387 has_port = intel_bios_is_port_present(dev_priv, PORT_D);
14388 if (I915_READ(CHV_DP_D) & DP_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014389 intel_dp_init(dev_priv, CHV_DP_D, PORT_D);
Ville Syrjälä22f350422016-06-03 12:17:43 +030014390 if (I915_READ(CHV_HDMID) & SDVO_DETECTED || has_port)
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014391 intel_hdmi_init(dev_priv, CHV_HDMID, PORT_D);
Ville Syrjälä9418c1f2014-04-09 13:28:56 +030014392 }
14393
Jani Nikulae5186342018-07-05 16:25:08 +030014394 vlv_dsi_init(dev_priv);
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014395 } else if (!IS_GEN(dev_priv, 2) && !IS_PINEVIEW(dev_priv)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014396 bool found = false;
Eric Anholt7d573822009-01-02 13:33:00 -080014397
Paulo Zanonie2debe92013-02-18 19:00:27 -030014398 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014399 DRM_DEBUG_KMS("probing SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014400 found = intel_sdvo_init(dev_priv, GEN3_SDVOB, PORT_B);
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014401 if (!found && IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014402 DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014403 intel_hdmi_init(dev_priv, GEN4_HDMIB, PORT_B);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014404 }
Ma Ling27185ae2009-08-24 13:50:23 +080014405
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014406 if (!found && IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014407 intel_dp_init(dev_priv, DP_B, PORT_B);
Eric Anholt725e30a2009-01-22 13:01:02 -080014408 }
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014409
14410 /* Before G4X SDVOC doesn't have its own detect register */
Kristian Høgsberg13520b02009-03-13 15:42:14 -040014411
Paulo Zanonie2debe92013-02-18 19:00:27 -030014412 if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014413 DRM_DEBUG_KMS("probing SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014414 found = intel_sdvo_init(dev_priv, GEN3_SDVOC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014415 }
Ma Ling27185ae2009-08-24 13:50:23 +080014416
Paulo Zanonie2debe92013-02-18 19:00:27 -030014417 if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) {
Ma Ling27185ae2009-08-24 13:50:23 +080014418
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014419 if (IS_G4X(dev_priv)) {
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014420 DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014421 intel_hdmi_init(dev_priv, GEN4_HDMIC, PORT_C);
Jesse Barnesb01f2c32009-12-11 11:07:17 -080014422 }
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014423 if (IS_G4X(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014424 intel_dp_init(dev_priv, DP_C, PORT_C);
Eric Anholt725e30a2009-01-22 13:01:02 -080014425 }
Ma Ling27185ae2009-08-24 13:50:23 +080014426
Tvrtko Ursulin9beb5fe2016-10-13 11:03:06 +010014427 if (IS_G4X(dev_priv) && (I915_READ(DP_D) & DP_DETECTED))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014428 intel_dp_init(dev_priv, DP_D, PORT_D);
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014429 } else if (IS_GEN(dev_priv, 2))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014430 intel_dvo_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014431
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +000014432 if (SUPPORTS_TV(dev_priv))
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014433 intel_tv_init(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080014434
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014435 intel_psr_init(dev_priv);
Rodrigo Vivi7c8f8a72014-06-13 05:10:03 -070014436
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014437 for_each_intel_encoder(&dev_priv->drm, encoder) {
Chris Wilson4ef69c72010-09-09 15:14:28 +010014438 encoder->base.possible_crtcs = encoder->crtc_mask;
14439 encoder->base.possible_clones =
Daniel Vetter66a92782012-07-12 20:08:18 +020014440 intel_encoder_clones(encoder);
Jesse Barnes79e53942008-11-07 14:24:08 -080014441 }
Chris Wilson47356eb2011-01-11 17:06:04 +000014442
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014443 intel_init_pch_refclk(dev_priv);
Daniel Vetter270b3042012-10-27 15:52:05 +020014444
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020014445 drm_helper_move_panel_connectors_to_head(&dev_priv->drm);
Jesse Barnes79e53942008-11-07 14:24:08 -080014446}
14447
14448static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
14449{
14450 struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014451 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014452
Daniel Vetteref2d6332014-02-10 18:00:38 +010014453 drm_framebuffer_cleanup(fb);
Chris Wilson70001cd2017-02-16 09:46:21 +000014454
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014455 i915_gem_object_lock(obj);
14456 WARN_ON(!obj->framebuffer_references--);
14457 i915_gem_object_unlock(obj);
Chris Wilsondd689282017-03-01 15:41:28 +000014458
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014459 i915_gem_object_put(obj);
Chris Wilson70001cd2017-02-16 09:46:21 +000014460
Jesse Barnes79e53942008-11-07 14:24:08 -080014461 kfree(intel_fb);
14462}
14463
14464static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
Chris Wilson05394f32010-11-08 19:18:58 +000014465 struct drm_file *file,
Jesse Barnes79e53942008-11-07 14:24:08 -080014466 unsigned int *handle)
14467{
Daniel Stonea5ff7a42018-05-18 15:30:07 +010014468 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Jesse Barnes79e53942008-11-07 14:24:08 -080014469
Chris Wilsoncc917ab2015-10-13 14:22:26 +010014470 if (obj->userptr.mm) {
14471 DRM_DEBUG("attempting to use a userptr for a framebuffer, denied\n");
14472 return -EINVAL;
14473 }
14474
Chris Wilson05394f32010-11-08 19:18:58 +000014475 return drm_gem_handle_create(file, &obj->base, handle);
Jesse Barnes79e53942008-11-07 14:24:08 -080014476}
14477
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014478static int intel_user_framebuffer_dirty(struct drm_framebuffer *fb,
14479 struct drm_file *file,
14480 unsigned flags, unsigned color,
14481 struct drm_clip_rect *clips,
14482 unsigned num_clips)
14483{
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014484 struct drm_i915_gem_object *obj = intel_fb_obj(fb);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014485
Chris Wilson5a97bcc2017-02-22 11:40:46 +000014486 i915_gem_object_flush_if_display(obj);
Chris Wilsond59b21e2017-02-22 11:40:49 +000014487 intel_fb_obj_flush(obj, ORIGIN_DIRTYFB);
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014488
14489 return 0;
14490}
14491
Jesse Barnes79e53942008-11-07 14:24:08 -080014492static const struct drm_framebuffer_funcs intel_fb_funcs = {
14493 .destroy = intel_user_framebuffer_destroy,
14494 .create_handle = intel_user_framebuffer_create_handle,
Rodrigo Vivi86c98582015-07-08 16:22:45 -070014495 .dirty = intel_user_framebuffer_dirty,
Jesse Barnes79e53942008-11-07 14:24:08 -080014496};
14497
Damien Lespiaub3218032015-02-27 11:15:18 +000014498static
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014499u32 intel_fb_pitch_limit(struct drm_i915_private *dev_priv,
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014500 u32 pixel_format, u64 fb_modifier)
Damien Lespiaub3218032015-02-27 11:15:18 +000014501{
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014502 struct intel_crtc *crtc;
14503 struct intel_plane *plane;
Damien Lespiaub3218032015-02-27 11:15:18 +000014504
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014505 /*
14506 * We assume the primary plane for pipe A has
14507 * the highest stride limits of them all.
14508 */
14509 crtc = intel_get_crtc_for_pipe(dev_priv, PIPE_A);
14510 plane = to_intel_plane(crtc->base.primary);
Ville Syrjäläac484962016-01-20 21:05:26 +020014511
Ville Syrjälä645d91f2018-09-07 18:24:03 +030014512 return plane->max_stride(plane, pixel_format, fb_modifier,
14513 DRM_MODE_ROTATE_0);
Damien Lespiaub3218032015-02-27 11:15:18 +000014514}
14515
Chris Wilson24dbf512017-02-15 10:59:18 +000014516static int intel_framebuffer_init(struct intel_framebuffer *intel_fb,
14517 struct drm_i915_gem_object *obj,
14518 struct drm_mode_fb_cmd2 *mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014519{
Chris Wilson24dbf512017-02-15 10:59:18 +000014520 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014521 struct drm_framebuffer *fb = &intel_fb->base;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014522 u32 pitch_limit;
Chris Wilsondd689282017-03-01 15:41:28 +000014523 unsigned int tiling, stride;
Chris Wilson24dbf512017-02-15 10:59:18 +000014524 int ret = -EINVAL;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014525 int i;
Jesse Barnes79e53942008-11-07 14:24:08 -080014526
Chris Wilsondd689282017-03-01 15:41:28 +000014527 i915_gem_object_lock(obj);
14528 obj->framebuffer_references++;
14529 tiling = i915_gem_object_get_tiling(obj);
14530 stride = i915_gem_object_get_stride(obj);
14531 i915_gem_object_unlock(obj);
Daniel Vetterdd4916c2013-10-09 21:23:51 +020014532
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014533 if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014534 /*
14535 * If there's a fence, enforce that
14536 * the fb modifier and tiling mode match.
14537 */
14538 if (tiling != I915_TILING_NONE &&
14539 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014540 DRM_DEBUG_KMS("tiling_mode doesn't match fb modifier\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014541 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014542 }
14543 } else {
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014544 if (tiling == I915_TILING_X) {
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014545 mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014546 } else if (tiling == I915_TILING_Y) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014547 DRM_DEBUG_KMS("No Y tiling for legacy addfb\n");
Chris Wilson24dbf512017-02-15 10:59:18 +000014548 goto err;
Daniel Vetter2a80ead2015-02-10 17:16:06 +000014549 }
14550 }
14551
Ville Syrjälä17e8fd12018-10-29 20:34:53 +020014552 if (!drm_any_plane_has_format(&dev_priv->drm,
14553 mode_cmd->pixel_format,
14554 mode_cmd->modifier[0])) {
14555 struct drm_format_name_buf format_name;
14556
14557 DRM_DEBUG_KMS("unsupported pixel format %s / modifier 0x%llx\n",
14558 drm_get_format_name(mode_cmd->pixel_format,
14559 &format_name),
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014560 mode_cmd->modifier[0]);
Chris Wilson24dbf512017-02-15 10:59:18 +000014561 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014562 }
Chris Wilson57cd6502010-08-08 12:34:44 +010014563
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014564 /*
14565 * gen2/3 display engine uses the fence if present,
14566 * so the tiling mode must match the fb modifier exactly.
14567 */
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014568 if (INTEL_GEN(dev_priv) < 4 &&
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014569 tiling != intel_fb_modifier_to_tiling(mode_cmd->modifier[0])) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014570 DRM_DEBUG_KMS("tiling_mode must match fb modifier exactly on gen2/3\n");
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014571 goto err;
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014572 }
14573
Dhinakaran Pandiyan4c8d3512018-10-26 12:53:42 -070014574 pitch_limit = intel_fb_pitch_limit(dev_priv, mode_cmd->pixel_format,
14575 mode_cmd->modifier[0]);
Chris Wilsona35cdaa2013-06-25 17:26:45 +010014576 if (mode_cmd->pitches[0] > pitch_limit) {
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014577 DRM_DEBUG_KMS("%s pitch (%u) must be at most %d\n",
Ben Widawsky2f075562017-03-24 14:29:48 -070014578 mode_cmd->modifier[0] != DRM_FORMAT_MOD_LINEAR ?
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014579 "tiled" : "linear",
14580 mode_cmd->pitches[0], pitch_limit);
Chris Wilson24dbf512017-02-15 10:59:18 +000014581 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014582 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014583
Ville Syrjäläc2ff7372016-02-11 19:16:37 +020014584 /*
14585 * If there's a fence, enforce that
14586 * the fb pitch and fence stride match.
14587 */
Ville Syrjälä144cc1432017-03-07 21:42:10 +020014588 if (tiling != I915_TILING_NONE && mode_cmd->pitches[0] != stride) {
14589 DRM_DEBUG_KMS("pitch (%d) must match tiling stride (%d)\n",
14590 mode_cmd->pitches[0], stride);
Chris Wilson24dbf512017-02-15 10:59:18 +000014591 goto err;
Chris Wilsonc16ed4b2012-12-18 22:13:14 +000014592 }
Ville Syrjälä5d7bd702012-10-31 17:50:18 +020014593
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014594 /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
14595 if (mode_cmd->offsets[0] != 0)
Chris Wilson24dbf512017-02-15 10:59:18 +000014596 goto err;
Ville Syrjälä90f9a332012-10-31 17:50:19 +020014597
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014598 drm_helper_mode_fill_fb_struct(&dev_priv->drm, fb, mode_cmd);
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014599
Chandra Kondurue44134f2018-05-12 03:03:15 +053014600 if (fb->format->format == DRM_FORMAT_NV12 &&
14601 (fb->width < SKL_MIN_YUV_420_SRC_W ||
14602 fb->height < SKL_MIN_YUV_420_SRC_H ||
14603 (fb->width % 4) != 0 || (fb->height % 4) != 0)) {
14604 DRM_DEBUG_KMS("src dimensions not correct for NV12\n");
Ville Syrjälä3b909462018-10-29 16:00:31 +020014605 goto err;
Chandra Kondurue44134f2018-05-12 03:03:15 +053014606 }
14607
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014608 for (i = 0; i < fb->format->num_planes; i++) {
14609 u32 stride_alignment;
14610
14611 if (mode_cmd->handles[i] != mode_cmd->handles[0]) {
14612 DRM_DEBUG_KMS("bad plane %d handle\n", i);
Christophe JAILLET37875d62017-09-10 10:56:42 +020014613 goto err;
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014614 }
14615
14616 stride_alignment = intel_fb_stride_alignment(fb, i);
14617
14618 /*
14619 * Display WA #0531: skl,bxt,kbl,glk
14620 *
14621 * Render decompression and plane width > 3840
14622 * combined with horizontal panning requires the
14623 * plane stride to be a multiple of 4. We'll just
14624 * require the entire fb to accommodate that to avoid
14625 * potential runtime errors at plane configuration time.
14626 */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014627 if (IS_GEN(dev_priv, 9) && i == 0 && fb->width > 3840 &&
Dhinakaran Pandiyan63eaf9a2018-08-22 12:38:27 -070014628 is_ccs_modifier(fb->modifier))
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014629 stride_alignment *= 4;
14630
14631 if (fb->pitches[i] & (stride_alignment - 1)) {
14632 DRM_DEBUG_KMS("plane %d pitch (%d) must be at least %u byte aligned\n",
14633 i, fb->pitches[i], stride_alignment);
14634 goto err;
14635 }
Ville Syrjäläd88c4af2017-03-07 21:42:06 +020014636
Daniel Stonea268bcd2018-05-18 15:30:08 +010014637 fb->obj[i] = &obj->base;
14638 }
Daniel Vetterc7d73f62012-12-13 23:38:38 +010014639
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014640 ret = intel_fill_fb_info(dev_priv, fb);
Ville Syrjälä6687c902015-09-15 13:16:41 +030014641 if (ret)
Chris Wilson9aceb5c12017-03-01 15:41:27 +000014642 goto err;
Ville Syrjälä2d7a2152016-02-15 22:54:47 +020014643
Ville Syrjälä2e2adb02017-08-01 09:58:13 -070014644 ret = drm_framebuffer_init(&dev_priv->drm, fb, &intel_fb_funcs);
Jesse Barnes79e53942008-11-07 14:24:08 -080014645 if (ret) {
14646 DRM_ERROR("framebuffer init failed %d\n", ret);
Chris Wilson24dbf512017-02-15 10:59:18 +000014647 goto err;
Jesse Barnes79e53942008-11-07 14:24:08 -080014648 }
14649
Jesse Barnes79e53942008-11-07 14:24:08 -080014650 return 0;
Chris Wilson24dbf512017-02-15 10:59:18 +000014651
14652err:
Chris Wilsondd689282017-03-01 15:41:28 +000014653 i915_gem_object_lock(obj);
14654 obj->framebuffer_references--;
14655 i915_gem_object_unlock(obj);
Chris Wilson24dbf512017-02-15 10:59:18 +000014656 return ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080014657}
14658
Jesse Barnes79e53942008-11-07 14:24:08 -080014659static struct drm_framebuffer *
14660intel_user_framebuffer_create(struct drm_device *dev,
14661 struct drm_file *filp,
Ville Syrjälä1eb834512015-11-11 19:11:29 +020014662 const struct drm_mode_fb_cmd2 *user_mode_cmd)
Jesse Barnes79e53942008-11-07 14:24:08 -080014663{
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014664 struct drm_framebuffer *fb;
Chris Wilson05394f32010-11-08 19:18:58 +000014665 struct drm_i915_gem_object *obj;
Ville Syrjälä76dc3762015-11-11 19:11:28 +020014666 struct drm_mode_fb_cmd2 mode_cmd = *user_mode_cmd;
Jesse Barnes79e53942008-11-07 14:24:08 -080014667
Chris Wilson03ac0642016-07-20 13:31:51 +010014668 obj = i915_gem_object_lookup(filp, mode_cmd.handles[0]);
14669 if (!obj)
Chris Wilsoncce13ff2010-08-08 13:36:38 +010014670 return ERR_PTR(-ENOENT);
Jesse Barnes79e53942008-11-07 14:24:08 -080014671
Chris Wilson24dbf512017-02-15 10:59:18 +000014672 fb = intel_framebuffer_create(obj, &mode_cmd);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014673 if (IS_ERR(fb))
Chris Wilsonf0cd5182016-10-28 13:58:43 +010014674 i915_gem_object_put(obj);
Lukas Wunnerdcb13942015-07-04 11:50:58 +020014675
14676 return fb;
Jesse Barnes79e53942008-11-07 14:24:08 -080014677}
14678
Chris Wilson778e23a2016-12-05 14:29:39 +000014679static void intel_atomic_state_free(struct drm_atomic_state *state)
14680{
14681 struct intel_atomic_state *intel_state = to_intel_atomic_state(state);
14682
14683 drm_atomic_state_default_release(state);
14684
14685 i915_sw_fence_fini(&intel_state->commit_ready);
14686
14687 kfree(state);
14688}
14689
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014690static enum drm_mode_status
14691intel_mode_valid(struct drm_device *dev,
14692 const struct drm_display_mode *mode)
14693{
Ville Syrjäläad77c532018-06-15 20:44:05 +030014694 struct drm_i915_private *dev_priv = to_i915(dev);
14695 int hdisplay_max, htotal_max;
14696 int vdisplay_max, vtotal_max;
14697
Ville Syrjäläe4dd27a2018-05-24 15:54:03 +030014698 /*
14699 * Can't reject DBLSCAN here because Xorg ddxen can add piles
14700 * of DBLSCAN modes to the output's mode list when they detect
14701 * the scaling mode property on the connector. And they don't
14702 * ask the kernel to validate those modes in any way until
14703 * modeset time at which point the client gets a protocol error.
14704 * So in order to not upset those clients we silently ignore the
14705 * DBLSCAN flag on such connectors. For other connectors we will
14706 * reject modes with the DBLSCAN flag in encoder->compute_config().
14707 * And we always reject DBLSCAN modes in connector->mode_valid()
14708 * as we never want such modes on the connector's mode list.
14709 */
14710
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014711 if (mode->vscan > 1)
14712 return MODE_NO_VSCAN;
14713
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014714 if (mode->flags & DRM_MODE_FLAG_HSKEW)
14715 return MODE_H_ILLEGAL;
14716
14717 if (mode->flags & (DRM_MODE_FLAG_CSYNC |
14718 DRM_MODE_FLAG_NCSYNC |
14719 DRM_MODE_FLAG_PCSYNC))
14720 return MODE_HSYNC;
14721
14722 if (mode->flags & (DRM_MODE_FLAG_BCAST |
14723 DRM_MODE_FLAG_PIXMUX |
14724 DRM_MODE_FLAG_CLKDIV2))
14725 return MODE_BAD;
14726
Ville Syrjäläad77c532018-06-15 20:44:05 +030014727 if (INTEL_GEN(dev_priv) >= 9 ||
14728 IS_BROADWELL(dev_priv) || IS_HASWELL(dev_priv)) {
14729 hdisplay_max = 8192; /* FDI max 4096 handled elsewhere */
14730 vdisplay_max = 4096;
14731 htotal_max = 8192;
14732 vtotal_max = 8192;
14733 } else if (INTEL_GEN(dev_priv) >= 3) {
14734 hdisplay_max = 4096;
14735 vdisplay_max = 4096;
14736 htotal_max = 8192;
14737 vtotal_max = 8192;
14738 } else {
14739 hdisplay_max = 2048;
14740 vdisplay_max = 2048;
14741 htotal_max = 4096;
14742 vtotal_max = 4096;
14743 }
14744
14745 if (mode->hdisplay > hdisplay_max ||
14746 mode->hsync_start > htotal_max ||
14747 mode->hsync_end > htotal_max ||
14748 mode->htotal > htotal_max)
14749 return MODE_H_ILLEGAL;
14750
14751 if (mode->vdisplay > vdisplay_max ||
14752 mode->vsync_start > vtotal_max ||
14753 mode->vsync_end > vtotal_max ||
14754 mode->vtotal > vtotal_max)
14755 return MODE_V_ILLEGAL;
14756
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014757 return MODE_OK;
14758}
14759
Jesse Barnes79e53942008-11-07 14:24:08 -080014760static const struct drm_mode_config_funcs intel_mode_funcs = {
Jesse Barnes79e53942008-11-07 14:24:08 -080014761 .fb_create = intel_user_framebuffer_create,
Ville Syrjäläbbfb6ce2017-08-01 09:58:12 -070014762 .get_format_info = intel_get_format_info,
Daniel Vetter0632fef2013-10-08 17:44:49 +020014763 .output_poll_changed = intel_fbdev_output_poll_changed,
Ville Syrjäläe995ca0b2017-11-14 20:32:58 +020014764 .mode_valid = intel_mode_valid,
Matt Roper5ee67f12015-01-21 16:35:44 -080014765 .atomic_check = intel_atomic_check,
14766 .atomic_commit = intel_atomic_commit,
Maarten Lankhorstde419ab2015-06-04 10:21:28 +020014767 .atomic_state_alloc = intel_atomic_state_alloc,
14768 .atomic_state_clear = intel_atomic_state_clear,
Chris Wilson778e23a2016-12-05 14:29:39 +000014769 .atomic_state_free = intel_atomic_state_free,
Jesse Barnes79e53942008-11-07 14:24:08 -080014770};
14771
Imre Deak88212942016-03-16 13:38:53 +020014772/**
14773 * intel_init_display_hooks - initialize the display modesetting hooks
14774 * @dev_priv: device private
14775 */
14776void intel_init_display_hooks(struct drm_i915_private *dev_priv)
Jesse Barnese70236a2009-09-21 10:42:27 -070014777{
Ville Syrjälä7ff89ca2017-02-07 20:33:05 +020014778 intel_init_cdclk_hooks(dev_priv);
14779
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +000014780 if (INTEL_GEN(dev_priv) >= 9) {
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014781 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014782 dev_priv->display.get_initial_plane_config =
14783 skylake_get_initial_plane_config;
Damien Lespiaubc8d7df2015-01-20 12:51:51 +000014784 dev_priv->display.crtc_compute_clock =
14785 haswell_crtc_compute_clock;
14786 dev_priv->display.crtc_enable = haswell_crtc_enable;
14787 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014788 } else if (HAS_DDI(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014789 dev_priv->display.get_pipe_config = haswell_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014790 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014791 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira797d0252014-10-29 11:32:34 +020014792 dev_priv->display.crtc_compute_clock =
14793 haswell_crtc_compute_clock;
Paulo Zanoni4f771f12012-10-23 18:29:51 -020014794 dev_priv->display.crtc_enable = haswell_crtc_enable;
14795 dev_priv->display.crtc_disable = haswell_crtc_disable;
Imre Deak88212942016-03-16 13:38:53 +020014796 } else if (HAS_PCH_SPLIT(dev_priv)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014797 dev_priv->display.get_pipe_config = ironlake_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014798 dev_priv->display.get_initial_plane_config =
Ville Syrjälä81894b22017-11-17 21:19:13 +020014799 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira3fb37702014-10-29 11:32:35 +020014800 dev_priv->display.crtc_compute_clock =
14801 ironlake_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014802 dev_priv->display.crtc_enable = ironlake_crtc_enable;
14803 dev_priv->display.crtc_disable = ironlake_crtc_disable;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014804 } else if (IS_CHERRYVIEW(dev_priv)) {
Jesse Barnes89b667f2013-04-18 14:51:36 -070014805 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014806 dev_priv->display.get_initial_plane_config =
14807 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveira65b3d6a2016-03-21 18:00:13 +020014808 dev_priv->display.crtc_compute_clock = chv_crtc_compute_clock;
14809 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14810 dev_priv->display.crtc_disable = i9xx_crtc_disable;
14811 } else if (IS_VALLEYVIEW(dev_priv)) {
14812 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14813 dev_priv->display.get_initial_plane_config =
14814 i9xx_get_initial_plane_config;
14815 dev_priv->display.crtc_compute_clock = vlv_crtc_compute_clock;
Jesse Barnes89b667f2013-04-18 14:51:36 -070014816 dev_priv->display.crtc_enable = valleyview_crtc_enable;
14817 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira19ec6692016-03-21 18:00:15 +020014818 } else if (IS_G4X(dev_priv)) {
14819 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14820 dev_priv->display.get_initial_plane_config =
14821 i9xx_get_initial_plane_config;
14822 dev_priv->display.crtc_compute_clock = g4x_crtc_compute_clock;
14823 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14824 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira70e8aa22016-03-21 18:00:16 +020014825 } else if (IS_PINEVIEW(dev_priv)) {
14826 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14827 dev_priv->display.get_initial_plane_config =
14828 i9xx_get_initial_plane_config;
14829 dev_priv->display.crtc_compute_clock = pnv_crtc_compute_clock;
14830 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14831 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014832 } else if (!IS_GEN(dev_priv, 2)) {
Daniel Vetter0e8ffe12013-03-28 10:42:00 +010014833 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
Damien Lespiau5724dbd2015-01-20 12:51:52 +000014834 dev_priv->display.get_initial_plane_config =
14835 i9xx_get_initial_plane_config;
Ander Conselvan de Oliveirad6dfee72014-10-29 11:32:36 +020014836 dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock;
Daniel Vetter76e5a892012-06-29 22:39:33 +020014837 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14838 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Ander Conselvan de Oliveira81c97f52016-03-22 15:35:23 +020014839 } else {
14840 dev_priv->display.get_pipe_config = i9xx_get_pipe_config;
14841 dev_priv->display.get_initial_plane_config =
14842 i9xx_get_initial_plane_config;
14843 dev_priv->display.crtc_compute_clock = i8xx_crtc_compute_clock;
14844 dev_priv->display.crtc_enable = i9xx_crtc_enable;
14845 dev_priv->display.crtc_disable = i9xx_crtc_disable;
Eric Anholtf564048e2011-03-30 13:01:02 -070014846 }
Jesse Barnese70236a2009-09-21 10:42:27 -070014847
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014848 if (IS_GEN(dev_priv, 5)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014849 dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014850 } else if (IS_GEN(dev_priv, 6)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014851 dev_priv->display.fdi_link_train = gen6_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014852 } else if (IS_IVYBRIDGE(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014853 /* FIXME: detect B0+ stepping and use auto training */
14854 dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
Imre Deak88212942016-03-16 13:38:53 +020014855 } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
Sonika Jindal3bb11b52014-08-11 09:06:39 +053014856 dev_priv->display.fdi_link_train = hsw_fdi_link_train;
Ville Syrjälä445e7802016-05-11 22:44:42 +030014857 }
14858
Rodrigo Vivibd30ca22017-09-26 14:13:46 -070014859 if (INTEL_GEN(dev_priv) >= 9)
Lyude27082492016-08-24 07:48:10 +020014860 dev_priv->display.update_crtcs = skl_update_crtcs;
14861 else
14862 dev_priv->display.update_crtcs = intel_update_crtcs;
Jesse Barnese70236a2009-09-21 10:42:27 -070014863}
14864
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014865/* Disable the VGA plane that we never use */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000014866static void i915_disable_vga(struct drm_i915_private *dev_priv)
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014867{
David Weinehall52a05c32016-08-22 13:32:44 +030014868 struct pci_dev *pdev = dev_priv->drm.pdev;
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014869 u8 sr1;
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010014870 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014871
Ville Syrjälä2b37c612014-01-22 21:32:38 +020014872 /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */
David Weinehall52a05c32016-08-22 13:32:44 +030014873 vga_get_uninterruptible(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes3fdcf432012-04-06 11:46:27 -070014874 outb(SR01, VGA_SR_INDEX);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014875 sr1 = inb(VGA_SR_DATA);
14876 outb(sr1 | 1<<5, VGA_SR_DATA);
David Weinehall52a05c32016-08-22 13:32:44 +030014877 vga_put(pdev, VGA_RSRC_LEGACY_IO);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014878 udelay(300);
14879
Ville Syrjälä01f5a622014-12-16 18:38:37 +020014880 I915_WRITE(vga_reg, VGA_DISP_DISABLE);
Jesse Barnes9cce37f2010-08-13 15:11:26 -070014881 POSTING_READ(vga_reg);
14882}
14883
Daniel Vetterf8175862012-04-10 15:50:11 +020014884void intel_modeset_init_hw(struct drm_device *dev)
14885{
Chris Wilsonfac5e232016-07-04 11:34:36 +010014886 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1a617b72015-12-03 14:31:06 +010014887
Ville Syrjälä4c75b942016-10-31 22:37:12 +020014888 intel_update_cdclk(dev_priv);
Ville Syrjäläcfddadc2017-10-24 12:52:16 +030014889 intel_dump_cdclk_state(&dev_priv->cdclk.hw, "Current CDCLK");
Ville Syrjäläbb0f4aa2017-01-20 20:21:59 +020014890 dev_priv->cdclk.logical = dev_priv->cdclk.actual = dev_priv->cdclk.hw;
Daniel Vetterf8175862012-04-10 15:50:11 +020014891}
14892
Matt Roperd93c0372015-12-03 11:37:41 -080014893/*
14894 * Calculate what we think the watermarks should be for the state we've read
14895 * out of the hardware and then immediately program those watermarks so that
14896 * we ensure the hardware settings match our internal state.
14897 *
14898 * We can calculate what we think WM's should be by creating a duplicate of the
14899 * current state (which was constructed during hardware readout) and running it
14900 * through the atomic check code to calculate new watermark values in the
14901 * state object.
14902 */
14903static void sanitize_watermarks(struct drm_device *dev)
14904{
14905 struct drm_i915_private *dev_priv = to_i915(dev);
14906 struct drm_atomic_state *state;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014907 struct intel_atomic_state *intel_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014908 struct drm_crtc *crtc;
14909 struct drm_crtc_state *cstate;
14910 struct drm_modeset_acquire_ctx ctx;
14911 int ret;
14912 int i;
14913
14914 /* Only supported on platforms that use atomic watermark design */
Matt Ropered4a6a72016-02-23 17:20:13 -080014915 if (!dev_priv->display.optimize_watermarks)
Matt Roperd93c0372015-12-03 11:37:41 -080014916 return;
14917
14918 /*
14919 * We need to hold connection_mutex before calling duplicate_state so
14920 * that the connector loop is protected.
14921 */
14922 drm_modeset_acquire_init(&ctx, 0);
14923retry:
Matt Roper0cd12622016-01-12 07:13:37 -080014924 ret = drm_modeset_lock_all_ctx(dev, &ctx);
Matt Roperd93c0372015-12-03 11:37:41 -080014925 if (ret == -EDEADLK) {
14926 drm_modeset_backoff(&ctx);
14927 goto retry;
14928 } else if (WARN_ON(ret)) {
Matt Roper0cd12622016-01-12 07:13:37 -080014929 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014930 }
14931
14932 state = drm_atomic_helper_duplicate_state(dev, &ctx);
14933 if (WARN_ON(IS_ERR(state)))
Matt Roper0cd12622016-01-12 07:13:37 -080014934 goto fail;
Matt Roperd93c0372015-12-03 11:37:41 -080014935
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014936 intel_state = to_intel_atomic_state(state);
14937
Matt Ropered4a6a72016-02-23 17:20:13 -080014938 /*
14939 * Hardware readout is the only time we don't want to calculate
14940 * intermediate watermarks (since we don't trust the current
14941 * watermarks).
14942 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020014943 if (!HAS_GMCH_DISPLAY(dev_priv))
14944 intel_state->skip_intermediate_wm = true;
Matt Ropered4a6a72016-02-23 17:20:13 -080014945
Matt Roperd93c0372015-12-03 11:37:41 -080014946 ret = intel_atomic_check(dev, state);
14947 if (ret) {
14948 /*
14949 * If we fail here, it means that the hardware appears to be
14950 * programmed in a way that shouldn't be possible, given our
14951 * understanding of watermark requirements. This might mean a
14952 * mistake in the hardware readout code or a mistake in the
14953 * watermark calculations for a given platform. Raise a WARN
14954 * so that this is noticeable.
14955 *
14956 * If this actually happens, we'll have to just leave the
14957 * BIOS-programmed watermarks untouched and hope for the best.
14958 */
14959 WARN(true, "Could not determine valid watermarks for inherited state\n");
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014960 goto put_state;
Matt Roperd93c0372015-12-03 11:37:41 -080014961 }
14962
14963 /* Write calculated watermark values back */
Maarten Lankhorstaa5e9b42017-03-09 15:52:04 +010014964 for_each_new_crtc_in_state(state, crtc, cstate, i) {
Matt Roperd93c0372015-12-03 11:37:41 -080014965 struct intel_crtc_state *cs = to_intel_crtc_state(cstate);
14966
Matt Ropered4a6a72016-02-23 17:20:13 -080014967 cs->wm.need_postvbl_update = true;
Maarten Lankhorstccf010f2016-11-08 13:55:32 +010014968 dev_priv->display.optimize_watermarks(intel_state, cs);
Maarten Lankhorst556fe362017-11-10 12:34:53 +010014969
14970 to_intel_crtc_state(crtc->state)->wm = cs->wm;
Matt Roperd93c0372015-12-03 11:37:41 -080014971 }
14972
Arnd Bergmannb9a1b712016-10-18 17:16:23 +020014973put_state:
Chris Wilson08536952016-10-14 13:18:18 +010014974 drm_atomic_state_put(state);
Matt Roper0cd12622016-01-12 07:13:37 -080014975fail:
Matt Roperd93c0372015-12-03 11:37:41 -080014976 drm_modeset_drop_locks(&ctx);
14977 drm_modeset_acquire_fini(&ctx);
14978}
14979
Chris Wilson58ecd9d2017-11-05 13:49:05 +000014980static void intel_update_fdi_pll_freq(struct drm_i915_private *dev_priv)
14981{
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014982 if (IS_GEN(dev_priv, 5)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000014983 u32 fdi_pll_clk =
14984 I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK;
14985
14986 dev_priv->fdi_pll_freq = (fdi_pll_clk + 2) * 10000;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080014987 } else if (IS_GEN(dev_priv, 6) || IS_IVYBRIDGE(dev_priv)) {
Chris Wilson58ecd9d2017-11-05 13:49:05 +000014988 dev_priv->fdi_pll_freq = 270000;
14989 } else {
14990 return;
14991 }
14992
14993 DRM_DEBUG_DRIVER("FDI PLL freq=%d\n", dev_priv->fdi_pll_freq);
14994}
14995
Azhar Shaikh516a49c2018-07-06 11:37:30 -070014996static int intel_initial_commit(struct drm_device *dev)
14997{
14998 struct drm_atomic_state *state = NULL;
14999 struct drm_modeset_acquire_ctx ctx;
15000 struct drm_crtc *crtc;
15001 struct drm_crtc_state *crtc_state;
15002 int ret = 0;
15003
15004 state = drm_atomic_state_alloc(dev);
15005 if (!state)
15006 return -ENOMEM;
15007
15008 drm_modeset_acquire_init(&ctx, 0);
15009
15010retry:
15011 state->acquire_ctx = &ctx;
15012
15013 drm_for_each_crtc(crtc, dev) {
15014 crtc_state = drm_atomic_get_crtc_state(state, crtc);
15015 if (IS_ERR(crtc_state)) {
15016 ret = PTR_ERR(crtc_state);
15017 goto out;
15018 }
15019
15020 if (crtc_state->active) {
15021 ret = drm_atomic_add_affected_planes(state, crtc);
15022 if (ret)
15023 goto out;
Ville Syrjäläfa6af5142018-11-20 15:54:49 +020015024
15025 /*
15026 * FIXME hack to force a LUT update to avoid the
15027 * plane update forcing the pipe gamma on without
15028 * having a proper LUT loaded. Remove once we
15029 * have readout for pipe gamma enable.
15030 */
15031 crtc_state->color_mgmt_changed = true;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015032 }
15033 }
15034
15035 ret = drm_atomic_commit(state);
15036
15037out:
15038 if (ret == -EDEADLK) {
15039 drm_atomic_state_clear(state);
15040 drm_modeset_backoff(&ctx);
15041 goto retry;
15042 }
15043
15044 drm_atomic_state_put(state);
15045
15046 drm_modeset_drop_locks(&ctx);
15047 drm_modeset_acquire_fini(&ctx);
15048
15049 return ret;
15050}
15051
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015052int intel_modeset_init(struct drm_device *dev)
Jesse Barnes79e53942008-11-07 14:24:08 -080015053{
Joonas Lahtinen72e96d62016-03-30 16:57:10 +030015054 struct drm_i915_private *dev_priv = to_i915(dev);
15055 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Damien Lespiau8cc87b72014-03-03 17:31:44 +000015056 enum pipe pipe;
Jesse Barnes46f297f2014-03-07 08:57:48 -080015057 struct intel_crtc *crtc;
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015058 int ret;
Jesse Barnes79e53942008-11-07 14:24:08 -080015059
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015060 dev_priv->modeset_wq = alloc_ordered_workqueue("i915_modeset", 0);
15061
Jesse Barnes79e53942008-11-07 14:24:08 -080015062 drm_mode_config_init(dev);
15063
15064 dev->mode_config.min_width = 0;
15065 dev->mode_config.min_height = 0;
15066
Dave Airlie019d96c2011-09-29 16:20:42 +010015067 dev->mode_config.preferred_depth = 24;
15068 dev->mode_config.prefer_shadow = 1;
15069
Tvrtko Ursulin25bab382015-02-10 17:16:16 +000015070 dev->mode_config.allow_fb_modifiers = true;
15071
Laurent Pincharte6ecefa2012-05-17 13:27:23 +020015072 dev->mode_config.funcs = &intel_mode_funcs;
Jesse Barnes79e53942008-11-07 14:24:08 -080015073
Andrea Arcangeli400c19d2017-04-07 01:23:45 +020015074 init_llist_head(&dev_priv->atomic_helper.free_list);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015075 INIT_WORK(&dev_priv->atomic_helper.free_work,
Chris Wilsonba318c62017-02-02 20:47:41 +000015076 intel_atomic_helper_free_state_worker);
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015077
Jani Nikula27a981b2018-10-17 12:35:39 +030015078 intel_init_quirks(dev_priv);
Jesse Barnesb690e962010-07-19 13:53:12 -070015079
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015080 intel_fbc_init(dev_priv);
15081
Ville Syrjälä62d75df2016-10-31 22:37:25 +020015082 intel_init_pm(dev_priv);
Eugeni Dodonov1fa61102012-04-18 15:29:26 -030015083
Lukas Wunner69f92f62015-07-15 13:57:35 +020015084 /*
15085 * There may be no VBT; and if the BIOS enabled SSC we can
15086 * just keep using it to avoid unnecessary flicker. Whereas if the
15087 * BIOS isn't using it, don't assume it will work even if the VBT
15088 * indicates as much.
15089 */
Tvrtko Ursulin6e266952016-10-13 11:02:53 +010015090 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv)) {
Lukas Wunner69f92f62015-07-15 13:57:35 +020015091 bool bios_lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) &
15092 DREF_SSC1_ENABLE);
15093
15094 if (dev_priv->vbt.lvds_use_ssc != bios_lvds_use_ssc) {
15095 DRM_DEBUG_KMS("SSC %sabled by BIOS, overriding VBT which says %sabled\n",
15096 bios_lvds_use_ssc ? "en" : "dis",
15097 dev_priv->vbt.lvds_use_ssc ? "en" : "dis");
15098 dev_priv->vbt.lvds_use_ssc = bios_lvds_use_ssc;
15099 }
15100 }
15101
Ville Syrjäläad77c532018-06-15 20:44:05 +030015102 /* maximum framebuffer dimensions */
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015103 if (IS_GEN(dev_priv, 2)) {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015104 dev->mode_config.max_width = 2048;
15105 dev->mode_config.max_height = 2048;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015106 } else if (IS_GEN(dev_priv, 3)) {
Keith Packard5e4d6fa2009-07-12 23:53:17 -070015107 dev->mode_config.max_width = 4096;
15108 dev->mode_config.max_height = 4096;
Jesse Barnes79e53942008-11-07 14:24:08 -080015109 } else {
Chris Wilsona6c45cf2010-09-17 00:32:17 +010015110 dev->mode_config.max_width = 8192;
15111 dev->mode_config.max_height = 8192;
Jesse Barnes79e53942008-11-07 14:24:08 -080015112 }
Damien Lespiau068be562014-03-28 14:17:49 +000015113
Jani Nikula2a307c22016-11-30 17:43:04 +020015114 if (IS_I845G(dev_priv) || IS_I865G(dev_priv)) {
15115 dev->mode_config.cursor_width = IS_I845G(dev_priv) ? 64 : 512;
Ville Syrjälädc41c152014-08-13 11:57:05 +030015116 dev->mode_config.cursor_height = 1023;
Lucas De Marchicf819ef2018-12-12 10:10:43 -080015117 } else if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015118 dev->mode_config.cursor_width = 64;
15119 dev->mode_config.cursor_height = 64;
Damien Lespiau068be562014-03-28 14:17:49 +000015120 } else {
Ville Syrjälä98fac1d2018-06-15 20:44:04 +030015121 dev->mode_config.cursor_width = 256;
15122 dev->mode_config.cursor_height = 256;
Damien Lespiau068be562014-03-28 14:17:49 +000015123 }
15124
Matthew Auld73ebd502017-12-11 15:18:20 +000015125 dev->mode_config.fb_base = ggtt->gmadr.start;
Jesse Barnes79e53942008-11-07 14:24:08 -080015126
Zhao Yakui28c97732009-10-09 11:39:41 +080015127 DRM_DEBUG_KMS("%d display pipe%s available.\n",
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000015128 INTEL_INFO(dev_priv)->num_pipes,
15129 INTEL_INFO(dev_priv)->num_pipes > 1 ? "s" : "");
Jesse Barnes79e53942008-11-07 14:24:08 -080015130
Damien Lespiau055e3932014-08-18 13:49:10 +010015131 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä5ab0d852016-10-31 22:37:11 +020015132 ret = intel_crtc_init(dev_priv, pipe);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015133 if (ret) {
15134 drm_mode_config_cleanup(dev);
15135 return ret;
15136 }
Jesse Barnes79e53942008-11-07 14:24:08 -080015137 }
15138
Daniel Vettere72f9fb2013-06-05 13:34:06 +020015139 intel_shared_dpll_init(dev);
Chris Wilson58ecd9d2017-11-05 13:49:05 +000015140 intel_update_fdi_pll_freq(dev_priv);
Jesse Barnesee7b9f92012-04-20 17:11:53 +010015141
Ville Syrjälä5be6e332017-02-20 16:04:43 +020015142 intel_update_czclk(dev_priv);
15143 intel_modeset_init_hw(dev);
15144
Ville Syrjäläb2045352016-05-13 23:41:27 +030015145 if (dev_priv->max_cdclk_freq == 0)
Ville Syrjälä4c75b942016-10-31 22:37:12 +020015146 intel_update_max_cdclk(dev_priv);
Ville Syrjäläb2045352016-05-13 23:41:27 +030015147
Jesse Barnes9cce37f2010-08-13 15:11:26 -070015148 /* Just disable it once at startup */
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015149 i915_disable_vga(dev_priv);
Ander Conselvan de Oliveirac39055b2016-11-23 16:21:44 +020015150 intel_setup_outputs(dev_priv);
Chris Wilson11be49e2012-11-15 11:32:20 +000015151
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015152 drm_modeset_lock_all(dev);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015153 intel_modeset_setup_hw_state(dev, dev->mode_config.acquire_ctx);
Daniel Vetter6e9f7982014-05-29 23:54:47 +020015154 drm_modeset_unlock_all(dev);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015155
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015156 for_each_intel_crtc(dev, crtc) {
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015157 struct intel_initial_plane_config plane_config = {};
15158
Jesse Barnes46f297f2014-03-07 08:57:48 -080015159 if (!crtc->active)
15160 continue;
15161
Jesse Barnes46f297f2014-03-07 08:57:48 -080015162 /*
Jesse Barnes46f297f2014-03-07 08:57:48 -080015163 * Note that reserving the BIOS fb up front prevents us
15164 * from stuffing other stolen allocations like the ring
15165 * on top. This prevents some ugliness at boot time, and
15166 * can even allow for smooth boot transitions if the BIOS
15167 * fb is large enough for the active pipe configuration.
15168 */
Maarten Lankhorsteeebeac2015-07-14 12:33:29 +020015169 dev_priv->display.get_initial_plane_config(crtc,
15170 &plane_config);
15171
15172 /*
15173 * If the fb is shared between multiple heads, we'll
15174 * just get the first one.
15175 */
15176 intel_find_initial_plane_obj(crtc, &plane_config);
Jesse Barnes46f297f2014-03-07 08:57:48 -080015177 }
Matt Roperd93c0372015-12-03 11:37:41 -080015178
15179 /*
15180 * Make sure hardware watermarks really match the state we read out.
15181 * Note that we need to do this after reconstructing the BIOS fb's
15182 * since the watermark calculation done here will use pstate->fb.
15183 */
Ville Syrjälä602ae832017-03-02 19:15:02 +020015184 if (!HAS_GMCH_DISPLAY(dev_priv))
15185 sanitize_watermarks(dev);
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015186
Azhar Shaikh516a49c2018-07-06 11:37:30 -070015187 /*
15188 * Force all active planes to recompute their states. So that on
15189 * mode_setcrtc after probe, all the intel_plane_state variables
15190 * are already calculated and there is no assert_plane warnings
15191 * during bootup.
15192 */
15193 ret = intel_initial_commit(dev);
15194 if (ret)
15195 DRM_DEBUG_KMS("Initial commit in probe failed.\n");
15196
Ville Syrjäläb079bd172016-10-25 18:58:02 +030015197 return 0;
Chris Wilson2c7111d2011-03-29 10:40:27 +010015198}
Jesse Barnesd5bb0812011-01-05 12:01:26 -080015199
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015200void i830_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15201{
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015202 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015203 /* 640x480@60Hz, ~25175 kHz */
15204 struct dpll clock = {
15205 .m1 = 18,
15206 .m2 = 7,
15207 .p1 = 13,
15208 .p2 = 4,
15209 .n = 2,
15210 };
15211 u32 dpll, fp;
15212 int i;
15213
15214 WARN_ON(i9xx_calc_dpll_params(48000, &clock) != 25154);
15215
15216 DRM_DEBUG_KMS("enabling pipe %c due to force quirk (vco=%d dot=%d)\n",
15217 pipe_name(pipe), clock.vco, clock.dot);
15218
15219 fp = i9xx_dpll_compute_fp(&clock);
15220 dpll = (I915_READ(DPLL(pipe)) & DPLL_DVO_2X_MODE) |
15221 DPLL_VGA_MODE_DIS |
15222 ((clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT) |
15223 PLL_P2_DIVIDE_BY_4 |
15224 PLL_REF_INPUT_DREFCLK |
15225 DPLL_VCO_ENABLE;
15226
15227 I915_WRITE(FP0(pipe), fp);
15228 I915_WRITE(FP1(pipe), fp);
15229
15230 I915_WRITE(HTOTAL(pipe), (640 - 1) | ((800 - 1) << 16));
15231 I915_WRITE(HBLANK(pipe), (640 - 1) | ((800 - 1) << 16));
15232 I915_WRITE(HSYNC(pipe), (656 - 1) | ((752 - 1) << 16));
15233 I915_WRITE(VTOTAL(pipe), (480 - 1) | ((525 - 1) << 16));
15234 I915_WRITE(VBLANK(pipe), (480 - 1) | ((525 - 1) << 16));
15235 I915_WRITE(VSYNC(pipe), (490 - 1) | ((492 - 1) << 16));
15236 I915_WRITE(PIPESRC(pipe), ((640 - 1) << 16) | (480 - 1));
15237
15238 /*
15239 * Apparently we need to have VGA mode enabled prior to changing
15240 * the P1/P2 dividers. Otherwise the DPLL will keep using the old
15241 * dividers, even though the register value does change.
15242 */
15243 I915_WRITE(DPLL(pipe), dpll & ~DPLL_VGA_MODE_DIS);
15244 I915_WRITE(DPLL(pipe), dpll);
15245
15246 /* Wait for the clocks to stabilize. */
15247 POSTING_READ(DPLL(pipe));
15248 udelay(150);
15249
15250 /* The pixel multiplier can only be updated once the
15251 * DPLL is enabled and the clocks are stable.
15252 *
15253 * So write it again.
15254 */
15255 I915_WRITE(DPLL(pipe), dpll);
15256
15257 /* We do this three times for luck */
15258 for (i = 0; i < 3 ; i++) {
15259 I915_WRITE(DPLL(pipe), dpll);
15260 POSTING_READ(DPLL(pipe));
15261 udelay(150); /* wait for warmup */
15262 }
15263
15264 I915_WRITE(PIPECONF(pipe), PIPECONF_ENABLE | PIPECONF_PROGRESSIVE);
15265 POSTING_READ(PIPECONF(pipe));
Ville Syrjäläd5fb43c2017-11-29 17:37:31 +020015266
15267 intel_wait_for_pipe_scanline_moving(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015268}
15269
15270void i830_disable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe)
15271{
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015272 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15273
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015274 DRM_DEBUG_KMS("disabling pipe %c due to force quirk\n",
15275 pipe_name(pipe));
15276
Ville Syrjälä5816d9c2017-11-29 14:54:11 +020015277 WARN_ON(I915_READ(DSPCNTR(PLANE_A)) & DISPLAY_PLANE_ENABLE);
15278 WARN_ON(I915_READ(DSPCNTR(PLANE_B)) & DISPLAY_PLANE_ENABLE);
15279 WARN_ON(I915_READ(DSPCNTR(PLANE_C)) & DISPLAY_PLANE_ENABLE);
Ville Syrjäläb99b9ec2018-01-31 16:37:09 +020015280 WARN_ON(I915_READ(CURCNTR(PIPE_A)) & MCURSOR_MODE);
15281 WARN_ON(I915_READ(CURCNTR(PIPE_B)) & MCURSOR_MODE);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015282
15283 I915_WRITE(PIPECONF(pipe), 0);
15284 POSTING_READ(PIPECONF(pipe));
15285
Ville Syrjälä8fedd642017-11-29 17:37:30 +020015286 intel_wait_for_pipe_scanline_stopped(crtc);
Ville Syrjälä2ee0da12017-06-01 17:36:16 +030015287
15288 I915_WRITE(DPLL(pipe), DPLL_VGA_MODE_DIS);
15289 POSTING_READ(DPLL(pipe));
15290}
15291
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015292static void
15293intel_sanitize_plane_mapping(struct drm_i915_private *dev_priv)
15294{
15295 struct intel_crtc *crtc;
Daniel Vetterfa555832012-10-10 23:14:00 +020015296
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015297 if (INTEL_GEN(dev_priv) >= 4)
15298 return;
Daniel Vetterfa555832012-10-10 23:14:00 +020015299
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015300 for_each_intel_crtc(&dev_priv->drm, crtc) {
15301 struct intel_plane *plane =
15302 to_intel_plane(crtc->base.primary);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015303 struct intel_crtc *plane_crtc;
15304 enum pipe pipe;
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015305
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015306 if (!plane->get_hw_state(plane, &pipe))
15307 continue;
15308
15309 if (pipe == crtc->pipe)
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015310 continue;
15311
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015312 DRM_DEBUG_KMS("[PLANE:%d:%s] attached to the wrong pipe, disabling plane\n",
15313 plane->base.base.id, plane->base.name);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015314
15315 plane_crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15316 intel_plane_disable_noatomic(plane_crtc, plane);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015317 }
Daniel Vetterfa555832012-10-10 23:14:00 +020015318}
15319
Ville Syrjälä02e93c32015-08-26 19:39:19 +030015320static bool intel_crtc_has_encoders(struct intel_crtc *crtc)
15321{
15322 struct drm_device *dev = crtc->base.dev;
15323 struct intel_encoder *encoder;
15324
15325 for_each_encoder_on_crtc(dev, &crtc->base, encoder)
15326 return true;
15327
15328 return false;
15329}
15330
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015331static struct intel_connector *intel_encoder_find_connector(struct intel_encoder *encoder)
15332{
15333 struct drm_device *dev = encoder->base.dev;
15334 struct intel_connector *connector;
15335
15336 for_each_connector_on_encoder(dev, &encoder->base, connector)
15337 return connector;
15338
15339 return NULL;
15340}
15341
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015342static bool has_pch_trancoder(struct drm_i915_private *dev_priv,
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015343 enum pipe pch_transcoder)
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015344{
15345 return HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015346 (HAS_PCH_LPT_H(dev_priv) && pch_transcoder == PIPE_A);
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015347}
15348
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015349static void intel_sanitize_crtc(struct intel_crtc *crtc,
15350 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter24929352012-07-02 20:28:59 +020015351{
15352 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +010015353 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015354 struct intel_crtc_state *crtc_state = to_intel_crtc_state(crtc->base.state);
15355 enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
Daniel Vetter24929352012-07-02 20:28:59 +020015356
Daniel Vetter24929352012-07-02 20:28:59 +020015357 /* Clear any frame start delays used for debugging left by the BIOS */
Ville Syrjälä738a8142017-11-15 22:04:42 +020015358 if (crtc->active && !transcoder_is_dsi(cpu_transcoder)) {
Jani Nikula4d1de972016-03-18 17:05:42 +020015359 i915_reg_t reg = PIPECONF(cpu_transcoder);
15360
15361 I915_WRITE(reg,
15362 I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
15363 }
Daniel Vetter24929352012-07-02 20:28:59 +020015364
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015365 if (crtc_state->base.active) {
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015366 struct intel_plane *plane;
15367
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015368 /* Disable everything but the primary plane */
15369 for_each_intel_plane_on_crtc(dev, crtc, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015370 const struct intel_plane_state *plane_state =
15371 to_intel_plane_state(plane->base.state);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015372
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015373 if (plane_state->base.visible &&
15374 plane->base.type != DRM_PLANE_TYPE_PRIMARY)
15375 intel_plane_disable_noatomic(crtc, plane);
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015376 }
Daniel Vetter96256042015-02-13 21:03:42 +010015377 }
Ville Syrjäläd3eaf882014-05-20 17:20:05 +030015378
Daniel Vetter24929352012-07-02 20:28:59 +020015379 /* Adjust the state of the output pipe according to whether we
15380 * have active connectors/encoders. */
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015381 if (crtc_state->base.active && !intel_crtc_has_encoders(crtc))
Ville Syrjäläda1d0e22017-06-01 17:36:14 +030015382 intel_crtc_disable_noatomic(&crtc->base, ctx);
Daniel Vetter24929352012-07-02 20:28:59 +020015383
Maarten Lankhorst1b52ad42018-10-11 12:04:53 +020015384 if (crtc_state->base.active || HAS_GMCH_DISPLAY(dev_priv)) {
Daniel Vetter4cc31482014-03-24 00:01:41 +010015385 /*
15386 * We start out with underrun reporting disabled to avoid races.
15387 * For correct bookkeeping mark this on active crtcs.
15388 *
Daniel Vetterc5ab3bc2014-05-14 15:40:34 +020015389 * Also on gmch platforms we dont have any hardware bits to
15390 * disable the underrun reporting. Which means we need to start
15391 * out with underrun reporting disabled also on inactive pipes,
15392 * since otherwise we'll complain about the garbage we read when
15393 * e.g. coming up after runtime pm.
15394 *
Daniel Vetter4cc31482014-03-24 00:01:41 +010015395 * No protection against concurrent access is required - at
15396 * worst a fifo underrun happens which also sets this to false.
15397 */
15398 crtc->cpu_fifo_underrun_disabled = true;
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015399 /*
15400 * We track the PCH trancoder underrun reporting state
15401 * within the crtc. With crtc for pipe A housing the underrun
15402 * reporting state for PCH transcoder A, crtc for pipe B housing
15403 * it for PCH transcoder B, etc. LPT-H has only PCH transcoder A,
15404 * and marking underrun reporting as disabled for the non-existing
15405 * PCH transcoders B and C would prevent enabling the south
15406 * error interrupt (see cpt_can_enable_serr_int()).
15407 */
Ville Syrjäläecf837d92017-10-10 15:55:56 +030015408 if (has_pch_trancoder(dev_priv, crtc->pipe))
Ville Syrjäläa168f5b2016-08-05 20:00:17 +030015409 crtc->pch_fifo_underrun_disabled = true;
Daniel Vetter4cc31482014-03-24 00:01:41 +010015410 }
Daniel Vetter24929352012-07-02 20:28:59 +020015411}
15412
15413static void intel_sanitize_encoder(struct intel_encoder *encoder)
15414{
Imre Deak70332ac2018-11-01 16:04:27 +020015415 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015416 struct intel_connector *connector;
Daniel Vetter24929352012-07-02 20:28:59 +020015417
15418 /* We need to check both for a crtc link (meaning that the
15419 * encoder is active and trying to read from a pipe) and the
15420 * pipe itself being active. */
15421 bool has_active_crtc = encoder->base.crtc &&
15422 to_intel_crtc(encoder->base.crtc)->active;
15423
Maarten Lankhorst496b0fc2016-08-23 16:18:07 +020015424 connector = intel_encoder_find_connector(encoder);
15425 if (connector && !has_active_crtc) {
Daniel Vetter24929352012-07-02 20:28:59 +020015426 DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
15427 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015428 encoder->base.name);
Daniel Vetter24929352012-07-02 20:28:59 +020015429
15430 /* Connector is active, but has no active pipe. This is
15431 * fallout from our resume register restoring. Disable
15432 * the encoder manually again. */
15433 if (encoder->base.crtc) {
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015434 struct drm_crtc_state *crtc_state = encoder->base.crtc->state;
15435
Daniel Vetter24929352012-07-02 20:28:59 +020015436 DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
15437 encoder->base.base.id,
Jani Nikula8e329a032014-06-03 14:56:21 +030015438 encoder->base.name);
Jani Nikulac84c6fe2018-10-16 15:41:34 +030015439 if (encoder->disable)
15440 encoder->disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Ville Syrjäläa62d1492014-06-28 02:04:01 +030015441 if (encoder->post_disable)
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015442 encoder->post_disable(encoder, to_intel_crtc_state(crtc_state), connector->base.state);
Daniel Vetter24929352012-07-02 20:28:59 +020015443 }
Egbert Eich7f1950f2014-04-25 10:56:22 +020015444 encoder->base.crtc = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015445
15446 /* Inconsistent output/port/pipe state happens presumably due to
15447 * a bug in one of the get_hw_state functions. Or someplace else
15448 * in our code, like the register restore mess on resume. Clamp
15449 * things to off as a safer default. */
Maarten Lankhorstfd6bbda2016-08-09 17:04:04 +020015450
15451 connector->base.dpms = DRM_MODE_DPMS_OFF;
15452 connector->base.encoder = NULL;
Daniel Vetter24929352012-07-02 20:28:59 +020015453 }
Maarten Lankhorstd6cae4a2018-05-16 10:50:38 +020015454
15455 /* notify opregion of the sanitized encoder state */
15456 intel_opregion_notify_encoder(encoder, connector && has_active_crtc);
Imre Deak70332ac2018-11-01 16:04:27 +020015457
15458 if (INTEL_GEN(dev_priv) >= 11)
15459 icl_sanitize_encoder_pll_mapping(encoder);
Daniel Vetter24929352012-07-02 20:28:59 +020015460}
15461
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015462void i915_redisable_vga_power_on(struct drm_i915_private *dev_priv)
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015463{
Tvrtko Ursulin920a14b2016-10-14 10:13:44 +010015464 i915_reg_t vga_reg = i915_vgacntrl_reg(dev_priv);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015465
Imre Deak04098752014-02-18 00:02:16 +020015466 if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) {
15467 DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015468 i915_disable_vga(dev_priv);
Imre Deak04098752014-02-18 00:02:16 +020015469 }
15470}
15471
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015472void i915_redisable_vga(struct drm_i915_private *dev_priv)
Imre Deak04098752014-02-18 00:02:16 +020015473{
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015474 /* This function can be called both from intel_modeset_setup_hw_state or
15475 * at a very early point in our resume sequence, where the power well
15476 * structures are not yet restored. Since this function is at a very
15477 * paranoid "someone might have enabled VGA while we were not looking"
15478 * level, just check if the power well is enabled instead of trying to
15479 * follow the "don't touch the power well if we don't need it" policy
15480 * the rest of the driver uses. */
Imre Deak6392f842016-02-12 18:55:13 +020015481 if (!intel_display_power_get_if_enabled(dev_priv, POWER_DOMAIN_VGA))
Paulo Zanoni8dc8a272013-08-02 16:22:24 -030015482 return;
15483
Tvrtko Ursulin29b74b72016-11-16 08:55:39 +000015484 i915_redisable_vga_power_on(dev_priv);
Imre Deak6392f842016-02-12 18:55:13 +020015485
15486 intel_display_power_put(dev_priv, POWER_DOMAIN_VGA);
Krzysztof Mazur0fde9012012-12-19 11:03:41 +010015487}
15488
Ville Syrjäläf9cd7b82015-09-10 18:59:08 +030015489/* FIXME read out full plane state for all planes */
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015490static void readout_plane_state(struct drm_i915_private *dev_priv)
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015491{
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015492 struct intel_plane *plane;
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015493 struct intel_crtc *crtc;
Maarten Lankhorstd032ffa2015-06-15 12:33:51 +020015494
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015495 for_each_intel_plane(&dev_priv->drm, plane) {
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015496 struct intel_plane_state *plane_state =
15497 to_intel_plane_state(plane->base.state);
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015498 struct intel_crtc_state *crtc_state;
15499 enum pipe pipe = PIPE_A;
Ville Syrjäläeade6c82018-01-30 22:38:03 +020015500 bool visible;
15501
15502 visible = plane->get_hw_state(plane, &pipe);
Maarten Lankhorstb26d3ea2015-09-23 16:11:41 +020015503
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015504 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
15505 crtc_state = to_intel_crtc_state(crtc->base.state);
15506
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015507 intel_set_plane_visible(crtc_state, plane_state, visible);
Ville Syrjälä7a4a2a42018-10-03 17:50:52 +030015508
15509 DRM_DEBUG_KMS("[PLANE:%d:%s] hw state readout: %s, pipe %c\n",
15510 plane->base.base.id, plane->base.name,
15511 enableddisabled(visible), pipe_name(pipe));
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015512 }
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015513
15514 for_each_intel_crtc(&dev_priv->drm, crtc) {
15515 struct intel_crtc_state *crtc_state =
15516 to_intel_crtc_state(crtc->base.state);
15517
15518 fixup_active_planes(crtc_state);
15519 }
Ville Syrjälä98ec7732014-04-30 17:43:01 +030015520}
15521
Daniel Vetter30e984d2013-06-05 13:34:17 +020015522static void intel_modeset_readout_hw_state(struct drm_device *dev)
Daniel Vetter24929352012-07-02 20:28:59 +020015523{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015524 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015525 enum pipe pipe;
Daniel Vetter24929352012-07-02 20:28:59 +020015526 struct intel_crtc *crtc;
15527 struct intel_encoder *encoder;
15528 struct intel_connector *connector;
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015529 struct drm_connector_list_iter conn_iter;
Daniel Vetter53589012013-06-05 13:34:16 +020015530 int i;
Daniel Vetter24929352012-07-02 20:28:59 +020015531
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015532 dev_priv->active_crtcs = 0;
15533
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015534 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015535 struct intel_crtc_state *crtc_state =
15536 to_intel_crtc_state(crtc->base.state);
Daniel Vetter3b117c82013-04-17 20:15:07 +020015537
Daniel Vetterec2dc6a2016-05-09 16:34:09 +020015538 __drm_atomic_helper_crtc_destroy_state(&crtc_state->base);
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015539 memset(crtc_state, 0, sizeof(*crtc_state));
15540 crtc_state->base.crtc = &crtc->base;
Daniel Vetter24929352012-07-02 20:28:59 +020015541
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015542 crtc_state->base.active = crtc_state->base.enable =
15543 dev_priv->display.get_pipe_config(crtc, crtc_state);
15544
15545 crtc->base.enabled = crtc_state->base.enable;
15546 crtc->active = crtc_state->base.active;
15547
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015548 if (crtc_state->base.active)
Maarten Lankhorst565602d2015-12-10 12:33:57 +010015549 dev_priv->active_crtcs |= 1 << crtc->pipe;
15550
Ville Syrjälä78108b72016-05-27 20:59:19 +030015551 DRM_DEBUG_KMS("[CRTC:%d:%s] hw state readout: %s\n",
15552 crtc->base.base.id, crtc->base.name,
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015553 enableddisabled(crtc_state->base.active));
Daniel Vetter24929352012-07-02 20:28:59 +020015554 }
15555
Ville Syrjälä62358aa2018-10-03 17:50:17 +030015556 readout_plane_state(dev_priv);
15557
Daniel Vetter53589012013-06-05 13:34:16 +020015558 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15559 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15560
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015561 pll->on = pll->info->funcs->get_hw_state(dev_priv, pll,
15562 &pll->state.hw_state);
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015563 pll->state.crtc_mask = 0;
Damien Lespiaud3fcc802014-05-13 23:32:22 +010015564 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015565 struct intel_crtc_state *crtc_state =
15566 to_intel_crtc_state(crtc->base.state);
15567
15568 if (crtc_state->base.active &&
15569 crtc_state->shared_dpll == pll)
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015570 pll->state.crtc_mask |= 1 << crtc->pipe;
Daniel Vetter53589012013-06-05 13:34:16 +020015571 }
Ander Conselvan de Oliveira2c42e532016-12-29 17:22:09 +020015572 pll->active_mask = pll->state.crtc_mask;
Daniel Vetter53589012013-06-05 13:34:16 +020015573
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +020015574 DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n",
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015575 pll->info->name, pll->state.crtc_mask, pll->on);
Daniel Vetter53589012013-06-05 13:34:16 +020015576 }
15577
Damien Lespiaub2784e12014-08-05 11:29:37 +010015578 for_each_intel_encoder(dev, encoder) {
Daniel Vetter24929352012-07-02 20:28:59 +020015579 pipe = 0;
15580
15581 if (encoder->get_hw_state(encoder, &pipe)) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015582 struct intel_crtc_state *crtc_state;
15583
Ville Syrjälä98187832016-10-31 22:37:10 +020015584 crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015585 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015586
Jesse Barnes045ac3b2013-05-14 17:08:26 -070015587 encoder->base.crtc = &crtc->base;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015588 encoder->get_config(encoder, crtc_state);
Daniel Vetter24929352012-07-02 20:28:59 +020015589 } else {
15590 encoder->base.crtc = NULL;
15591 }
15592
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015593 DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015594 encoder->base.base.id, encoder->base.name,
15595 enableddisabled(encoder->base.crtc),
Damien Lespiau6f2bcce2013-10-16 12:29:54 +010015596 pipe_name(pipe));
Daniel Vetter24929352012-07-02 20:28:59 +020015597 }
15598
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015599 drm_connector_list_iter_begin(dev, &conn_iter);
15600 for_each_intel_connector_iter(connector, &conn_iter) {
Daniel Vetter24929352012-07-02 20:28:59 +020015601 if (connector->get_hw_state(connector)) {
15602 connector->base.dpms = DRM_MODE_DPMS_ON;
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015603
15604 encoder = connector->encoder;
15605 connector->base.encoder = &encoder->base;
15606
15607 if (encoder->base.crtc &&
15608 encoder->base.crtc->state->active) {
15609 /*
15610 * This has to be done during hardware readout
15611 * because anything calling .crtc_disable may
15612 * rely on the connector_mask being accurate.
15613 */
15614 encoder->base.crtc->state->connector_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015615 drm_connector_mask(&connector->base);
Maarten Lankhorste87a52b2016-01-28 15:04:58 +010015616 encoder->base.crtc->state->encoder_mask |=
Ville Syrjälä40560e22018-06-26 22:47:11 +030015617 drm_encoder_mask(&encoder->base);
Maarten Lankhorst2aa974c2016-01-06 14:53:25 +010015618 }
15619
Daniel Vetter24929352012-07-02 20:28:59 +020015620 } else {
15621 connector->base.dpms = DRM_MODE_DPMS_OFF;
15622 connector->base.encoder = NULL;
15623 }
15624 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
Tvrtko Ursulin08c4d7f2016-11-17 12:30:14 +000015625 connector->base.base.id, connector->base.name,
15626 enableddisabled(connector->base.encoder));
Daniel Vetter24929352012-07-02 20:28:59 +020015627 }
Daniel Vetterf9e905c2017-03-01 10:52:25 +010015628 drm_connector_list_iter_end(&conn_iter);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015629
15630 for_each_intel_crtc(dev, crtc) {
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015631 struct intel_crtc_state *crtc_state =
15632 to_intel_crtc_state(crtc->base.state);
Ville Syrjäläd305e062017-08-30 21:57:03 +030015633 int min_cdclk = 0;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015634
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015635 memset(&crtc->base.mode, 0, sizeof(crtc->base.mode));
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015636 if (crtc_state->base.active) {
15637 intel_mode_from_pipe_config(&crtc->base.mode, crtc_state);
Ville Syrjäläbd4cd032018-04-26 19:30:15 +030015638 crtc->base.mode.hdisplay = crtc_state->pipe_src_w;
15639 crtc->base.mode.vdisplay = crtc_state->pipe_src_h;
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015640 intel_mode_from_pipe_config(&crtc_state->base.adjusted_mode, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015641 WARN_ON(drm_atomic_set_mode_for_crtc(crtc->base.state, &crtc->base.mode));
15642
15643 /*
15644 * The initial mode needs to be set in order to keep
15645 * the atomic core happy. It wants a valid mode if the
15646 * crtc's enabled, so we do the above call.
15647 *
Daniel Vetter7800fb62016-12-19 09:24:23 +010015648 * But we don't set all the derived state fully, hence
15649 * set a flag to indicate that a full recalculation is
15650 * needed on the next commit.
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015651 */
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015652 crtc_state->base.mode.private_flags = I915_MODE_FLAG_INHERITED;
Ville Syrjälä9eca68322015-09-10 18:59:10 +030015653
Ville Syrjäläa7d1b3f2017-01-26 21:50:31 +020015654 intel_crtc_compute_pixel_rate(crtc_state);
15655
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015656 if (dev_priv->display.modeset_calc_cdclk) {
Ville Syrjäläd305e062017-08-30 21:57:03 +030015657 min_cdclk = intel_crtc_compute_min_cdclk(crtc_state);
Ville Syrjälä9c61de42017-07-10 22:33:47 +030015658 if (WARN_ON(min_cdclk < 0))
15659 min_cdclk = 0;
15660 }
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015661
Daniel Vetter5caa0fe2017-05-09 16:03:29 +020015662 drm_calc_timestamping_constants(&crtc->base,
15663 &crtc_state->base.adjusted_mode);
Maarten Lankhorstf2bdd112018-10-11 12:04:52 +020015664 update_scanline_offset(crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015665 }
Ville Syrjäläe3b247d2016-02-17 21:41:09 +020015666
Ville Syrjäläd305e062017-08-30 21:57:03 +030015667 dev_priv->min_cdclk[crtc->pipe] = min_cdclk;
Ville Syrjälä53e9bf52017-10-24 12:52:14 +030015668 dev_priv->min_voltage_level[crtc->pipe] =
15669 crtc_state->min_voltage_level;
Ville Syrjäläaca1ebf2016-12-20 17:39:02 +020015670
Ville Syrjäläa8cd6da2016-12-22 16:04:41 +020015671 intel_pipe_config_sanity_check(dev_priv, crtc_state);
Ville Syrjälä7f4c6282015-09-10 18:59:07 +030015672 }
Daniel Vetter30e984d2013-06-05 13:34:17 +020015673}
15674
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015675static void
15676get_encoder_power_domains(struct drm_i915_private *dev_priv)
15677{
15678 struct intel_encoder *encoder;
15679
15680 for_each_intel_encoder(&dev_priv->drm, encoder) {
15681 u64 get_domains;
15682 enum intel_display_power_domain domain;
Imre Deak52528052018-06-21 21:44:49 +030015683 struct intel_crtc_state *crtc_state;
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015684
15685 if (!encoder->get_power_domains)
15686 continue;
15687
Imre Deak52528052018-06-21 21:44:49 +030015688 /*
Imre Deakb79ebe72018-07-05 15:26:54 +030015689 * MST-primary and inactive encoders don't have a crtc state
15690 * and neither of these require any power domain references.
Imre Deak52528052018-06-21 21:44:49 +030015691 */
Imre Deakb79ebe72018-07-05 15:26:54 +030015692 if (!encoder->base.crtc)
15693 continue;
Imre Deak52528052018-06-21 21:44:49 +030015694
Imre Deakb79ebe72018-07-05 15:26:54 +030015695 crtc_state = to_intel_crtc_state(encoder->base.crtc->state);
Imre Deak52528052018-06-21 21:44:49 +030015696 get_domains = encoder->get_power_domains(encoder, crtc_state);
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015697 for_each_power_domain(domain, get_domains)
15698 intel_display_power_get(dev_priv, domain);
15699 }
15700}
15701
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015702static void intel_early_display_was(struct drm_i915_private *dev_priv)
15703{
15704 /* Display WA #1185 WaDisableDARBFClkGating:cnl,glk */
15705 if (IS_CANNONLAKE(dev_priv) || IS_GEMINILAKE(dev_priv))
15706 I915_WRITE(GEN9_CLKGATE_DIS_0, I915_READ(GEN9_CLKGATE_DIS_0) |
15707 DARBF_GATING_DIS);
15708
15709 if (IS_HASWELL(dev_priv)) {
15710 /*
15711 * WaRsPkgCStateDisplayPMReq:hsw
15712 * System hang if this isn't done before disabling all planes!
15713 */
15714 I915_WRITE(CHICKEN_PAR1_1,
15715 I915_READ(CHICKEN_PAR1_1) | FORCE_ARB_IDLE_PLANES);
15716 }
15717}
15718
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015719static void ibx_sanitize_pch_hdmi_port(struct drm_i915_private *dev_priv,
15720 enum port port, i915_reg_t hdmi_reg)
15721{
15722 u32 val = I915_READ(hdmi_reg);
15723
15724 if (val & SDVO_ENABLE ||
15725 (val & SDVO_PIPE_SEL_MASK) == SDVO_PIPE_SEL(PIPE_A))
15726 return;
15727
15728 DRM_DEBUG_KMS("Sanitizing transcoder select for HDMI %c\n",
15729 port_name(port));
15730
15731 val &= ~SDVO_PIPE_SEL_MASK;
15732 val |= SDVO_PIPE_SEL(PIPE_A);
15733
15734 I915_WRITE(hdmi_reg, val);
15735}
15736
15737static void ibx_sanitize_pch_dp_port(struct drm_i915_private *dev_priv,
15738 enum port port, i915_reg_t dp_reg)
15739{
15740 u32 val = I915_READ(dp_reg);
15741
15742 if (val & DP_PORT_EN ||
15743 (val & DP_PIPE_SEL_MASK) == DP_PIPE_SEL(PIPE_A))
15744 return;
15745
15746 DRM_DEBUG_KMS("Sanitizing transcoder select for DP %c\n",
15747 port_name(port));
15748
15749 val &= ~DP_PIPE_SEL_MASK;
15750 val |= DP_PIPE_SEL(PIPE_A);
15751
15752 I915_WRITE(dp_reg, val);
15753}
15754
15755static void ibx_sanitize_pch_ports(struct drm_i915_private *dev_priv)
15756{
15757 /*
15758 * The BIOS may select transcoder B on some of the PCH
15759 * ports even it doesn't enable the port. This would trip
15760 * assert_pch_dp_disabled() and assert_pch_hdmi_disabled().
15761 * Sanitize the transcoder select bits to prevent that. We
15762 * assume that the BIOS never actually enabled the port,
15763 * because if it did we'd actually have to toggle the port
15764 * on and back off to make the transcoder A select stick
15765 * (see. intel_dp_link_down(), intel_disable_hdmi(),
15766 * intel_disable_sdvo()).
15767 */
15768 ibx_sanitize_pch_dp_port(dev_priv, PORT_B, PCH_DP_B);
15769 ibx_sanitize_pch_dp_port(dev_priv, PORT_C, PCH_DP_C);
15770 ibx_sanitize_pch_dp_port(dev_priv, PORT_D, PCH_DP_D);
15771
15772 /* PCH SDVOB multiplex with HDMIB */
15773 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_B, PCH_HDMIB);
15774 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_C, PCH_HDMIC);
15775 ibx_sanitize_pch_hdmi_port(dev_priv, PORT_D, PCH_HDMID);
15776}
15777
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015778/* Scan out the current hw modeset state,
15779 * and sanitizes it to the current state
15780 */
15781static void
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015782intel_modeset_setup_hw_state(struct drm_device *dev,
15783 struct drm_modeset_acquire_ctx *ctx)
Daniel Vetter30e984d2013-06-05 13:34:17 +020015784{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015785 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015786 struct intel_crtc *crtc;
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015787 struct intel_crtc_state *crtc_state;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015788 struct intel_encoder *encoder;
Daniel Vetter35c95372013-07-17 06:55:04 +020015789 int i;
Daniel Vetter30e984d2013-06-05 13:34:17 +020015790
Imre Deak2cd9a682018-08-16 15:37:57 +030015791 intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
15792
Rodrigo Vividf49ec82017-11-10 16:03:19 -080015793 intel_early_display_was(dev_priv);
Daniel Vetter30e984d2013-06-05 13:34:17 +020015794 intel_modeset_readout_hw_state(dev);
Daniel Vetter24929352012-07-02 20:28:59 +020015795
15796 /* HW state is read out, now we need to sanitize this mess. */
Ander Conselvan de Oliveira62b69562017-02-24 16:19:59 +020015797 get_encoder_power_domains(dev_priv);
15798
Ville Syrjälä3aefb672018-11-08 16:36:35 +020015799 if (HAS_PCH_IBX(dev_priv))
15800 ibx_sanitize_pch_ports(dev_priv);
15801
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015802 /*
15803 * intel_sanitize_plane_mapping() may need to do vblank
15804 * waits, so we need vblank interrupts restored beforehand.
15805 */
15806 for_each_intel_crtc(&dev_priv->drm, crtc) {
15807 drm_crtc_vblank_reset(&crtc->base);
Ville Syrjäläb1e01592017-11-17 21:19:09 +020015808
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015809 if (crtc->base.state->active)
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015810 drm_crtc_vblank_on(&crtc->base);
Daniel Vetter24929352012-07-02 20:28:59 +020015811 }
15812
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015813 intel_sanitize_plane_mapping(dev_priv);
Ville Syrjäläe2af48c2016-10-31 22:37:05 +020015814
Ville Syrjälä68bc30d2018-10-03 17:49:51 +030015815 for_each_intel_encoder(dev, encoder)
15816 intel_sanitize_encoder(encoder);
15817
15818 for_each_intel_crtc(&dev_priv->drm, crtc) {
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015819 crtc_state = to_intel_crtc_state(crtc->base.state);
Ville Syrjäläaecd36b2017-06-01 17:36:13 +030015820 intel_sanitize_crtc(crtc, ctx);
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015821 intel_dump_pipe_config(crtc, crtc_state,
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +020015822 "[setup_hw_state]");
Daniel Vetter24929352012-07-02 20:28:59 +020015823 }
Daniel Vetter9a935852012-07-05 22:34:27 +020015824
Ander Conselvan de Oliveirad29b2f92015-03-20 16:18:05 +020015825 intel_modeset_update_connector_atomic_state(dev);
15826
Daniel Vetter35c95372013-07-17 06:55:04 +020015827 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
15828 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
15829
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +010015830 if (!pll->on || pll->active_mask)
Daniel Vetter35c95372013-07-17 06:55:04 +020015831 continue;
15832
Lucas De Marchi72f775f2018-03-20 15:06:34 -070015833 DRM_DEBUG_KMS("%s enabled but not in use, disabling\n",
15834 pll->info->name);
Daniel Vetter35c95372013-07-17 06:55:04 +020015835
Lucas De Marchiee1398b2018-03-20 15:06:33 -070015836 pll->info->funcs->disable(dev_priv, pll);
Daniel Vetter35c95372013-07-17 06:55:04 +020015837 pll->on = false;
15838 }
15839
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015840 if (IS_G4X(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015841 g4x_wm_get_hw_state(dev_priv);
Ville Syrjälä04548cb2017-04-21 21:14:29 +030015842 g4x_wm_sanitize(dev_priv);
15843 } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015844 vlv_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015845 vlv_wm_sanitize(dev_priv);
Rodrigo Vivia029fa42017-08-09 13:52:48 -070015846 } else if (INTEL_GEN(dev_priv) >= 9) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015847 skl_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015848 } else if (HAS_PCH_SPLIT(dev_priv)) {
Matt Ropercd1d3ee2018-12-10 13:54:14 -080015849 ilk_wm_get_hw_state(dev_priv);
Ville Syrjälä602ae832017-03-02 19:15:02 +020015850 }
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015851
15852 for_each_intel_crtc(dev, crtc) {
Ander Conselvan de Oliveirad8fc70b2017-02-09 11:31:21 +020015853 u64 put_domains;
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015854
Maarten Lankhorst91d78192018-10-11 12:04:54 +020015855 crtc_state = to_intel_crtc_state(crtc->base.state);
15856 put_domains = modeset_get_crtc_power_domains(&crtc->base, crtc_state);
Maarten Lankhorst292b9902015-07-13 16:30:27 +020015857 if (WARN_ON(put_domains))
15858 modeset_put_power_domains(dev_priv, put_domains);
15859 }
Imre Deak2cd9a682018-08-16 15:37:57 +030015860
15861 intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
Paulo Zanoni010cf732016-01-19 11:35:48 -020015862
15863 intel_fbc_init_pipe_state(dev_priv);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015864}
Ville Syrjälä7d0bc1e2013-09-16 17:38:33 +030015865
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015866void intel_display_resume(struct drm_device *dev)
15867{
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015868 struct drm_i915_private *dev_priv = to_i915(dev);
15869 struct drm_atomic_state *state = dev_priv->modeset_restore_state;
15870 struct drm_modeset_acquire_ctx ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015871 int ret;
Daniel Vetterf30da182013-04-11 20:22:50 +020015872
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015873 dev_priv->modeset_restore_state = NULL;
Maarten Lankhorst73974892016-08-05 23:28:27 +030015874 if (state)
15875 state->acquire_ctx = &ctx;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015876
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015877 drm_modeset_acquire_init(&ctx, 0);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015878
Maarten Lankhorst73974892016-08-05 23:28:27 +030015879 while (1) {
15880 ret = drm_modeset_lock_all_ctx(dev, &ctx);
15881 if (ret != -EDEADLK)
15882 break;
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015883
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015884 drm_modeset_backoff(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015885 }
15886
Maarten Lankhorst73974892016-08-05 23:28:27 +030015887 if (!ret)
Maarten Lankhorst581e49f2017-01-16 10:37:38 +010015888 ret = __intel_display_resume(dev, state, &ctx);
Maarten Lankhorst73974892016-08-05 23:28:27 +030015889
Kumar, Mahesh2503a0f2017-08-17 19:15:28 +053015890 intel_enable_ipc(dev_priv);
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015891 drm_modeset_drop_locks(&ctx);
15892 drm_modeset_acquire_fini(&ctx);
Maarten Lankhorst043e9bd2015-07-13 16:30:25 +020015893
Chris Wilson08536952016-10-14 13:18:18 +010015894 if (ret)
Maarten Lankhorste2c8b872016-02-16 10:06:14 +010015895 DRM_ERROR("Restoring old state failed with %i\n", ret);
Chris Wilson3c5e37f2017-01-15 12:58:25 +000015896 if (state)
15897 drm_atomic_state_put(state);
Chris Wilson2c7111d2011-03-29 10:40:27 +010015898}
15899
Manasi Navare886c6b82017-10-26 14:52:00 -070015900static void intel_hpd_poll_fini(struct drm_device *dev)
15901{
15902 struct intel_connector *connector;
15903 struct drm_connector_list_iter conn_iter;
15904
Chris Wilson448aa912017-11-28 11:01:47 +000015905 /* Kill all the work that may have been queued by hpd. */
Manasi Navare886c6b82017-10-26 14:52:00 -070015906 drm_connector_list_iter_begin(dev, &conn_iter);
15907 for_each_intel_connector_iter(connector, &conn_iter) {
15908 if (connector->modeset_retry_work.func)
15909 cancel_work_sync(&connector->modeset_retry_work);
Ramalingam Cd3dacc72018-10-29 15:15:46 +053015910 if (connector->hdcp.shim) {
15911 cancel_delayed_work_sync(&connector->hdcp.check_work);
15912 cancel_work_sync(&connector->hdcp.prop_work);
Sean Paulee5e5e72018-01-08 14:55:39 -050015913 }
Manasi Navare886c6b82017-10-26 14:52:00 -070015914 }
15915 drm_connector_list_iter_end(&conn_iter);
15916}
15917
Jesse Barnes79e53942008-11-07 14:24:08 -080015918void intel_modeset_cleanup(struct drm_device *dev)
15919{
Chris Wilsonfac5e232016-07-04 11:34:36 +010015920 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes652c3932009-08-17 13:31:43 -070015921
Chris Wilson8bcf9f72018-07-10 10:44:20 +010015922 flush_workqueue(dev_priv->modeset_wq);
15923
Chris Wilsoneb955ee2017-01-23 21:29:39 +000015924 flush_work(&dev_priv->atomic_helper.free_work);
15925 WARN_ON(!llist_empty(&dev_priv->atomic_helper.free_list));
15926
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015927 /*
15928 * Interrupts and polling as the first thing to avoid creating havoc.
Imre Deak2eb52522014-11-19 15:30:05 +020015929 * Too much stuff here (turning of connectors, ...) would
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015930 * experience fancy races otherwise.
15931 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +020015932 intel_irq_uninstall(dev_priv);
Jesse Barneseb21b922014-06-20 11:57:33 -070015933
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015934 /*
15935 * Due to the hpd irq storm handling the hotplug work can re-arm the
15936 * poll handlers. Hence disable polling after hpd handling is shut down.
15937 */
Manasi Navare886c6b82017-10-26 14:52:00 -070015938 intel_hpd_poll_fini(dev);
Daniel Vetterfd0c0642013-04-24 11:13:35 +020015939
Daniel Vetter4f256d82017-07-15 00:46:55 +020015940 /* poll work can call into fbdev, hence clean that up afterwards */
15941 intel_fbdev_fini(dev_priv);
15942
Jesse Barnes723bfd72010-10-07 16:01:13 -070015943 intel_unregister_dsm_handler();
15944
Paulo Zanonic937ab3e52016-01-19 11:35:46 -020015945 intel_fbc_global_disable(dev_priv);
Kristian Høgsberg69341a52009-11-11 12:19:17 -050015946
Chris Wilson1630fe72011-07-08 12:22:42 +010015947 /* flush any delayed tasks or pending work */
15948 flush_scheduled_work();
15949
Jesse Barnes79e53942008-11-07 14:24:08 -080015950 drm_mode_config_cleanup(dev);
Daniel Vetter4d7bb012012-12-18 15:24:37 +010015951
José Roberto de Souza58db08a72018-11-07 16:16:47 -080015952 intel_overlay_cleanup(dev_priv);
Imre Deakae484342014-03-31 15:10:44 +030015953
Tvrtko Ursulin40196442016-12-01 14:16:42 +000015954 intel_teardown_gmbus(dev_priv);
Ville Syrjälä757fffc2017-11-13 15:36:22 +020015955
15956 destroy_workqueue(dev_priv->modeset_wq);
José Roberto de Souzaacde44b2018-11-07 16:16:45 -080015957
15958 intel_fbc_cleanup_cfb(dev_priv);
Jesse Barnes79e53942008-11-07 14:24:08 -080015959}
15960
Dave Airlie28d52042009-09-21 14:33:58 +100015961/*
15962 * set vga decode state - true == enable VGA decode
15963 */
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015964int intel_modeset_vga_set_state(struct drm_i915_private *dev_priv, bool state)
Dave Airlie28d52042009-09-21 14:33:58 +100015965{
Tvrtko Ursulin6315b5d2016-11-16 12:32:42 +000015966 unsigned reg = INTEL_GEN(dev_priv) >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL;
Dave Airlie28d52042009-09-21 14:33:58 +100015967 u16 gmch_ctrl;
15968
Chris Wilson75fa0412014-02-07 18:37:02 -020015969 if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) {
15970 DRM_ERROR("failed to read control word\n");
15971 return -EIO;
15972 }
15973
Chris Wilsonc0cc8a52014-02-07 18:37:03 -020015974 if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state)
15975 return 0;
15976
Dave Airlie28d52042009-09-21 14:33:58 +100015977 if (state)
15978 gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
15979 else
15980 gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
Chris Wilson75fa0412014-02-07 18:37:02 -020015981
15982 if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) {
15983 DRM_ERROR("failed to write control word\n");
15984 return -EIO;
15985 }
15986
Dave Airlie28d52042009-09-21 14:33:58 +100015987 return 0;
15988}
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015989
Chris Wilson98a2f412016-10-12 10:05:18 +010015990#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
15991
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015992struct intel_display_error_state {
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030015993
15994 u32 power_well_driver;
15995
Chris Wilson63b66e52013-08-08 15:12:06 +020015996 int num_transcoders;
15997
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000015998 struct intel_cursor_error_state {
15999 u32 control;
16000 u32 position;
16001 u32 base;
16002 u32 size;
Damien Lespiau52331302012-08-15 19:23:25 +010016003 } cursor[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016004
16005 struct intel_pipe_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016006 bool power_domain_on;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016007 u32 source;
Imre Deakf301b1e12014-04-18 15:55:04 +030016008 u32 stat;
Damien Lespiau52331302012-08-15 19:23:25 +010016009 } pipe[I915_MAX_PIPES];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016010
16011 struct intel_plane_error_state {
16012 u32 control;
16013 u32 stride;
16014 u32 size;
16015 u32 pos;
16016 u32 addr;
16017 u32 surface;
16018 u32 tile_offset;
Damien Lespiau52331302012-08-15 19:23:25 +010016019 } plane[I915_MAX_PIPES];
Chris Wilson63b66e52013-08-08 15:12:06 +020016020
16021 struct intel_transcoder_error_state {
Imre Deakddf9c532013-11-27 22:02:02 +020016022 bool power_domain_on;
Chris Wilson63b66e52013-08-08 15:12:06 +020016023 enum transcoder cpu_transcoder;
16024
16025 u32 conf;
16026
16027 u32 htotal;
16028 u32 hblank;
16029 u32 hsync;
16030 u32 vtotal;
16031 u32 vblank;
16032 u32 vsync;
16033 } transcoder[4];
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016034};
16035
16036struct intel_display_error_state *
Chris Wilsonc0336662016-05-06 15:40:21 +010016037intel_display_capture_error_state(struct drm_i915_private *dev_priv)
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016038{
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016039 struct intel_display_error_state *error;
Chris Wilson63b66e52013-08-08 15:12:06 +020016040 int transcoders[] = {
16041 TRANSCODER_A,
16042 TRANSCODER_B,
16043 TRANSCODER_C,
16044 TRANSCODER_EDP,
16045 };
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016046 int i;
16047
José Roberto de Souzae1bf0942018-11-30 15:20:47 -080016048 if (!HAS_DISPLAY(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016049 return NULL;
16050
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016051 error = kzalloc(sizeof(*error), GFP_ATOMIC);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016052 if (error == NULL)
16053 return NULL;
16054
Chris Wilsonc0336662016-05-06 15:40:21 +010016055 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Imre Deak75e39682018-08-06 12:58:39 +030016056 error->power_well_driver = I915_READ(HSW_PWR_WELL_CTL2);
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016057
Damien Lespiau055e3932014-08-18 13:49:10 +010016058 for_each_pipe(dev_priv, i) {
Imre Deakddf9c532013-11-27 22:02:02 +020016059 error->pipe[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016060 __intel_display_power_is_enabled(dev_priv,
16061 POWER_DOMAIN_PIPE(i));
Imre Deakddf9c532013-11-27 22:02:02 +020016062 if (!error->pipe[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016063 continue;
16064
Ville Syrjälä5efb3e22014-04-09 13:28:53 +030016065 error->cursor[i].control = I915_READ(CURCNTR(i));
16066 error->cursor[i].position = I915_READ(CURPOS(i));
16067 error->cursor[i].base = I915_READ(CURBASE(i));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016068
16069 error->plane[i].control = I915_READ(DSPCNTR(i));
16070 error->plane[i].stride = I915_READ(DSPSTRIDE(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016071 if (INTEL_GEN(dev_priv) <= 3) {
Paulo Zanoni51889b32013-03-06 20:03:13 -030016072 error->plane[i].size = I915_READ(DSPSIZE(i));
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016073 error->plane[i].pos = I915_READ(DSPPOS(i));
16074 }
Chris Wilsonc0336662016-05-06 15:40:21 +010016075 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Paulo Zanonica291362013-03-06 20:03:14 -030016076 error->plane[i].addr = I915_READ(DSPADDR(i));
Chris Wilsonc0336662016-05-06 15:40:21 +010016077 if (INTEL_GEN(dev_priv) >= 4) {
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016078 error->plane[i].surface = I915_READ(DSPSURF(i));
16079 error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
16080 }
16081
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016082 error->pipe[i].source = I915_READ(PIPESRC(i));
Imre Deakf301b1e12014-04-18 15:55:04 +030016083
Chris Wilsonc0336662016-05-06 15:40:21 +010016084 if (HAS_GMCH_DISPLAY(dev_priv))
Imre Deakf301b1e12014-04-18 15:55:04 +030016085 error->pipe[i].stat = I915_READ(PIPESTAT(i));
Chris Wilson63b66e52013-08-08 15:12:06 +020016086 }
16087
Jani Nikula4d1de972016-03-18 17:05:42 +020016088 /* Note: this does not include DSI transcoders. */
Chris Wilsonc0336662016-05-06 15:40:21 +010016089 error->num_transcoders = INTEL_INFO(dev_priv)->num_pipes;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +030016090 if (HAS_DDI(dev_priv))
Chris Wilson63b66e52013-08-08 15:12:06 +020016091 error->num_transcoders++; /* Account for eDP. */
16092
16093 for (i = 0; i < error->num_transcoders; i++) {
16094 enum transcoder cpu_transcoder = transcoders[i];
16095
Imre Deakddf9c532013-11-27 22:02:02 +020016096 error->transcoder[i].power_domain_on =
Daniel Vetterf458ebb2014-09-30 10:56:39 +020016097 __intel_display_power_is_enabled(dev_priv,
Paulo Zanoni38cc1da2013-12-20 15:09:41 -020016098 POWER_DOMAIN_TRANSCODER(cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016099 if (!error->transcoder[i].power_domain_on)
Paulo Zanoni9d1cb912013-11-01 13:32:08 -020016100 continue;
16101
Chris Wilson63b66e52013-08-08 15:12:06 +020016102 error->transcoder[i].cpu_transcoder = cpu_transcoder;
16103
16104 error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder));
16105 error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
16106 error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder));
16107 error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder));
16108 error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
16109 error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder));
16110 error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder));
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016111 }
16112
16113 return error;
16114}
16115
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016116#define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
16117
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016118void
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016119intel_display_print_error_state(struct drm_i915_error_state_buf *m,
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016120 struct intel_display_error_state *error)
16121{
Chris Wilson5a4c6f12017-02-14 16:46:11 +000016122 struct drm_i915_private *dev_priv = m->i915;
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016123 int i;
16124
Chris Wilson63b66e52013-08-08 15:12:06 +020016125 if (!error)
16126 return;
16127
Tvrtko Ursulinb7f05d42016-11-09 11:30:45 +000016128 err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev_priv)->num_pipes);
Tvrtko Ursulin86527442016-10-13 11:03:00 +010016129 if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016130 err_printf(m, "PWR_WELL_CTL2: %08x\n",
Paulo Zanoniff57f1b2013-05-03 12:15:37 -030016131 error->power_well_driver);
Damien Lespiau055e3932014-08-18 13:49:10 +010016132 for_each_pipe(dev_priv, i) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016133 err_printf(m, "Pipe [%d]:\n", i);
Imre Deakddf9c532013-11-27 22:02:02 +020016134 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016135 onoff(error->pipe[i].power_domain_on));
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016136 err_printf(m, " SRC: %08x\n", error->pipe[i].source);
Imre Deakf301b1e12014-04-18 15:55:04 +030016137 err_printf(m, " STAT: %08x\n", error->pipe[i].stat);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016138
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016139 err_printf(m, "Plane [%d]:\n", i);
16140 err_printf(m, " CNTR: %08x\n", error->plane[i].control);
16141 err_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016142 if (INTEL_GEN(dev_priv) <= 3) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016143 err_printf(m, " SIZE: %08x\n", error->plane[i].size);
16144 err_printf(m, " POS: %08x\n", error->plane[i].pos);
Paulo Zanoni80ca3782013-03-22 14:20:57 -030016145 }
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +010016146 if (INTEL_GEN(dev_priv) <= 7 && !IS_HASWELL(dev_priv))
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016147 err_printf(m, " ADDR: %08x\n", error->plane[i].addr);
Tvrtko Ursulin5f56d5f2016-11-16 08:55:37 +000016148 if (INTEL_GEN(dev_priv) >= 4) {
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016149 err_printf(m, " SURF: %08x\n", error->plane[i].surface);
16150 err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016151 }
16152
Mika Kuoppalaedc3d882013-05-23 13:55:35 +030016153 err_printf(m, "Cursor [%d]:\n", i);
16154 err_printf(m, " CNTR: %08x\n", error->cursor[i].control);
16155 err_printf(m, " POS: %08x\n", error->cursor[i].position);
16156 err_printf(m, " BASE: %08x\n", error->cursor[i].base);
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016157 }
Chris Wilson63b66e52013-08-08 15:12:06 +020016158
16159 for (i = 0; i < error->num_transcoders; i++) {
Jani Nikulada205632016-03-15 21:51:10 +020016160 err_printf(m, "CPU transcoder: %s\n",
Chris Wilson63b66e52013-08-08 15:12:06 +020016161 transcoder_name(error->transcoder[i].cpu_transcoder));
Imre Deakddf9c532013-11-27 22:02:02 +020016162 err_printf(m, " Power: %s\n",
Jani Nikula87ad3212016-01-14 12:53:34 +020016163 onoff(error->transcoder[i].power_domain_on));
Chris Wilson63b66e52013-08-08 15:12:06 +020016164 err_printf(m, " CONF: %08x\n", error->transcoder[i].conf);
16165 err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal);
16166 err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank);
16167 err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync);
16168 err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal);
16169 err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank);
16170 err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync);
16171 }
Chris Wilsonc4a1d9e2010-11-21 13:12:35 +000016172}
Chris Wilson98a2f412016-10-12 10:05:18 +010016173
16174#endif